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, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 51 | int options, 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, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 53 | int options, 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, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 57 | int options, 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, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 63 | int options, 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 | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 65 | int options, 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, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 67 | int options, 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, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 69 | int options, 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, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 71 | int options, struct unres_schema *unres); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 72 | static struct lys_when *read_yin_when(struct lys_module *module, struct lyxml_elem *yin, struct unres_schema *unres); |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 73 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 74 | /* |
| 75 | * yin - the provided XML subtree is unlinked |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 76 | * ext - pointer to the storage in the parent structure to be able to update its location after realloc |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 77 | */ |
| 78 | int |
| 79 | lyp_yin_fill_ext(void *parent, LYEXT_PAR parent_type, LYEXT_SUBSTMT substmt, uint8_t substmt_index, |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 80 | struct lys_module *module, struct lyxml_elem *yin, struct lys_ext_instance ***ext, |
| 81 | uint8_t ext_index, struct unres_schema *unres) |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 82 | { |
| 83 | struct unres_ext *info; |
| 84 | |
| 85 | info = malloc(sizeof *info); |
| 86 | lyxml_unlink(module->ctx, yin); |
| 87 | info->data.yin = yin; |
| 88 | info->datatype = LYS_IN_YIN; |
| 89 | info->parent = parent; |
Radek Krejci | a7db970 | 2017-01-20 12:55:14 +0100 | [diff] [blame] | 90 | info->mod = module; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 91 | info->parent_type = parent_type; |
| 92 | info->substmt = substmt; |
| 93 | info->substmt_index = substmt_index; |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 94 | info->ext_index = ext_index; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 95 | |
| 96 | if (unres_schema_add_node(module, unres, ext, UNRES_EXT, (struct lys_node *)info) == -1) { |
| 97 | return EXIT_FAILURE; |
| 98 | } |
| 99 | |
| 100 | return EXIT_SUCCESS; |
| 101 | } |
| 102 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 103 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 104 | static const char * |
| 105 | read_yin_subnode(struct ly_ctx *ctx, struct lyxml_elem *node, const char *name) |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 106 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 107 | int len; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 108 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 109 | /* there should be <text> child */ |
| 110 | if (!node->child || !node->child->name || strcmp(node->child->name, name)) { |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 111 | LOGERR(LY_EVALID, "Expected \"%s\" element in \"%s\" element.", name, node->name); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 112 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, name, node->name); |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 113 | return NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 114 | } else if (node->child->content) { |
| 115 | len = strlen(node->child->content); |
| 116 | return lydict_insert(ctx, node->child->content, len); |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 117 | } else { |
| 118 | return lydict_insert(ctx, "", 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 119 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 120 | } |
| 121 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 122 | int |
| 123 | lyp_yin_parse_subnode_ext(struct lys_module *mod, void *elem, LYEXT_PAR elem_type, |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 124 | struct lyxml_elem *yin, LYEXT_SUBSTMT type, uint8_t i, struct unres_schema *unres) |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 125 | { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 126 | void *reallocated; |
| 127 | struct lyxml_elem *next, *child; |
| 128 | int r; |
| 129 | struct lys_ext_instance ***ext; |
| 130 | uint8_t *ext_size; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 131 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 132 | switch (elem_type) { |
| 133 | case LYEXT_PAR_MODULE: |
| 134 | ext_size = &((struct lys_module *)elem)->ext_size; |
| 135 | ext = &((struct lys_module *)elem)->ext; |
| 136 | break; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 137 | case LYEXT_PAR_IMPORT: |
| 138 | ext_size = &((struct lys_import *)elem)->ext_size; |
| 139 | ext = &((struct lys_import *)elem)->ext; |
| 140 | break; |
| 141 | case LYEXT_PAR_INCLUDE: |
| 142 | ext_size = &((struct lys_include *)elem)->ext_size; |
| 143 | ext = &((struct lys_include *)elem)->ext; |
| 144 | break; |
| 145 | case LYEXT_PAR_REVISION: |
| 146 | ext_size = &((struct lys_revision *)elem)->ext_size; |
| 147 | ext = &((struct lys_revision *)elem)->ext; |
| 148 | break; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 149 | case LYEXT_PAR_NODE: |
| 150 | ext_size = &((struct lys_node *)elem)->ext_size; |
| 151 | ext = &((struct lys_node *)elem)->ext; |
| 152 | break; |
| 153 | case LYEXT_PAR_IDENT: |
| 154 | ext_size = &((struct lys_ident *)elem)->ext_size; |
| 155 | ext = &((struct lys_ident *)elem)->ext; |
| 156 | break; |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 157 | case LYEXT_PAR_TYPE: |
| 158 | ext_size = &((struct lys_type *)elem)->ext_size; |
| 159 | ext = &((struct lys_type *)elem)->ext; |
| 160 | break; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 161 | case LYEXT_PAR_TYPE_BIT: |
| 162 | ext_size = &((struct lys_type_bit *)elem)->ext_size; |
| 163 | ext = &((struct lys_type_bit *)elem)->ext; |
| 164 | break; |
| 165 | case LYEXT_PAR_TYPE_ENUM: |
| 166 | ext_size = &((struct lys_type_enum *)elem)->ext_size; |
| 167 | ext = &((struct lys_type_enum *)elem)->ext; |
| 168 | break; |
| 169 | case LYEXT_PAR_TPDF: |
| 170 | ext_size = &((struct lys_tpdf *)elem)->ext_size; |
| 171 | ext = &((struct lys_tpdf *)elem)->ext; |
| 172 | break; |
| 173 | case LYEXT_PAR_EXT: |
| 174 | ext_size = &((struct lys_ext *)elem)->ext_size; |
| 175 | ext = &((struct lys_ext *)elem)->ext; |
| 176 | break; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 177 | case LYEXT_PAR_EXTINST: |
| 178 | ext_size = &((struct lys_ext_instance *)elem)->ext_size; |
| 179 | ext = &((struct lys_ext_instance *)elem)->ext; |
| 180 | break; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 181 | case LYEXT_PAR_FEATURE: |
| 182 | ext_size = &((struct lys_feature *)elem)->ext_size; |
| 183 | ext = &((struct lys_feature *)elem)->ext; |
| 184 | break; |
| 185 | case LYEXT_PAR_REFINE: |
| 186 | ext_size = &((struct lys_refine *)elem)->ext_size; |
| 187 | ext = &((struct lys_refine *)elem)->ext; |
| 188 | break; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 189 | case LYEXT_PAR_RESTR: |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 190 | ext_size = &((struct lys_restr *)elem)->ext_size; |
| 191 | ext = &((struct lys_restr *)elem)->ext; |
| 192 | break; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 193 | case LYEXT_PAR_WHEN: |
| 194 | ext_size = &((struct lys_when *)elem)->ext_size; |
| 195 | ext = &((struct lys_when *)elem)->ext; |
| 196 | break; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 197 | case LYEXT_PAR_DEVIATE: |
| 198 | ext_size = &((struct lys_deviate *)elem)->ext_size; |
| 199 | ext = &((struct lys_deviate *)elem)->ext; |
| 200 | break; |
| 201 | case LYEXT_PAR_DEVIATION: |
| 202 | ext_size = &((struct lys_deviation *)elem)->ext_size; |
| 203 | ext = &((struct lys_deviation *)elem)->ext; |
| 204 | break; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 205 | default: |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 206 | LOGERR(LY_EINT, "parent type %d", elem_type); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 207 | return EXIT_FAILURE; |
| 208 | } |
| 209 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 210 | if (type == LYEXT_SUBSTMT_SELF) { |
| 211 | /* parse for the statement self, not for the substatement */ |
| 212 | child = yin; |
| 213 | next = NULL; |
| 214 | goto parseext; |
| 215 | } |
| 216 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 217 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 218 | if (!strcmp(child->ns->value, LY_NSYIN)) { |
| 219 | /* skip the regular YIN nodes */ |
| 220 | continue; |
| 221 | } |
| 222 | |
| 223 | /* parse it as extension */ |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 224 | parseext: |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 225 | |
| 226 | /* first, allocate a space for the extension instance in the parent elem */ |
| 227 | reallocated = realloc(*ext, (1 + (*ext_size)) * sizeof **ext); |
| 228 | if (!reallocated) { |
| 229 | LOGMEM; |
| 230 | return EXIT_FAILURE; |
| 231 | } |
| 232 | (*ext) = reallocated; |
| 233 | |
| 234 | /* init memory */ |
| 235 | (*ext)[(*ext_size)] = NULL; |
| 236 | |
| 237 | /* parse YIN data */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 238 | r = lyp_yin_fill_ext(elem, elem_type, type, i, mod, child, &(*ext), (*ext_size), unres); |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 239 | (*ext_size)++; |
| 240 | if (r) { |
| 241 | return EXIT_FAILURE; |
| 242 | } |
| 243 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 244 | /* done - do not free the child, it is unlinked in lyp_yin_fill_ext */ |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 245 | } |
| 246 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 247 | return EXIT_SUCCESS; |
| 248 | } |
| 249 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 250 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 251 | static int |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 252 | fill_yin_iffeature(struct lys_node *parent, int parent_is_feature, struct lyxml_elem *yin, struct lys_iffeature *iffeat, |
| 253 | struct unres_schema *unres) |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 254 | { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 255 | int r, c_ext = 0; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 256 | const char *value; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 257 | struct lyxml_elem *node, *next; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 258 | |
| 259 | GETVAL(value, yin, "name"); |
Michal Vasko | 97b32be | 2016-07-25 10:59:53 +0200 | [diff] [blame] | 260 | |
| 261 | if ((lys_node_module(parent)->version != 2) && ((value[0] == '(') || strchr(value, ' '))) { |
| 262 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "if-feature"); |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 263 | error: |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 264 | return EXIT_FAILURE; |
| 265 | } |
| 266 | |
Michal Vasko | 56d082c | 2016-10-25 14:00:42 +0200 | [diff] [blame] | 267 | if (!(value = transform_iffeat_schema2json(parent->module, value))) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 268 | return EXIT_FAILURE; |
| 269 | } |
| 270 | |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 271 | r = resolve_iffeature_compile(iffeat, value, parent, parent_is_feature, unres); |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 272 | lydict_remove(parent->module->ctx, value); |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 273 | if (r) { |
| 274 | return EXIT_FAILURE; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 275 | } |
| 276 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 277 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 278 | if (!node->ns) { |
| 279 | /* garbage */ |
| 280 | lyxml_free(parent->module->ctx, node); |
| 281 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 282 | /* extension */ |
| 283 | c_ext++; |
| 284 | } else { |
| 285 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name, "if-feature"); |
| 286 | return EXIT_FAILURE; |
| 287 | } |
| 288 | } |
| 289 | if (c_ext) { |
| 290 | iffeat->ext = calloc(c_ext, sizeof *iffeat->ext); |
| 291 | if (!iffeat->ext) { |
| 292 | LOGMEM; |
| 293 | return EXIT_FAILURE; |
| 294 | } |
| 295 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 296 | /* extensions */ |
| 297 | r = lyp_yin_fill_ext(iffeat, LYEXT_PAR_IDENT, 0, 0, parent->module, node, |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 298 | &iffeat->ext, iffeat->ext_size, unres); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 299 | iffeat->ext_size++; |
| 300 | if (r) { |
| 301 | return EXIT_FAILURE; |
| 302 | } |
| 303 | } |
| 304 | } |
| 305 | |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 306 | return EXIT_SUCCESS; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | /* logs directly */ |
| 310 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 311 | fill_yin_identity(struct lys_module *module, struct lyxml_elem *yin, struct lys_ident *ident, struct unres_schema *unres) |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 312 | { |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 313 | struct lyxml_elem *node, *next; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 314 | const char *value; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 315 | int rc; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 316 | int c_ftrs = 0, c_base = 0, c_ext = 0; |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 317 | void *reallocated; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 318 | |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 319 | GETVAL(value, yin, "name"); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 320 | ident->name = value; |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 321 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 322 | if (read_yin_common(module, NULL, ident, LYEXT_PAR_IDENT, yin, OPT_IDENT | OPT_MODULE, unres)) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 323 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 324 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 325 | |
Pavol Vican | d6cda45 | 2016-07-13 15:08:29 +0200 | [diff] [blame] | 326 | if (dup_identities_check(ident->name, module)) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 327 | goto error; |
Pavol Vican | d6cda45 | 2016-07-13 15:08:29 +0200 | [diff] [blame] | 328 | } |
| 329 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 330 | LY_TREE_FOR(yin->child, node) { |
| 331 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 332 | /* extension */ |
| 333 | c_ext++; |
| 334 | } else if (!strcmp(node->name, "base")) { |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 335 | if (c_base && (module->version < 2)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 336 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "base", "identity"); |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 337 | goto error; |
| 338 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 339 | if (lyp_yin_parse_subnode_ext(module, ident, LYEXT_PAR_IDENT, node, LYEXT_SUBSTMT_BASE, c_base, unres)) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 340 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 341 | } |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 342 | c_base++; |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 343 | |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 344 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
| 345 | c_ftrs++; |
| 346 | |
| 347 | } else { |
| 348 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name, "identity"); |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 349 | goto error; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 350 | } |
| 351 | } |
| 352 | |
| 353 | if (c_base) { |
| 354 | ident->base_size = 0; |
| 355 | ident->base = calloc(c_base, sizeof *ident->base); |
| 356 | if (!ident->base) { |
| 357 | LOGMEM; |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 358 | goto error; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 359 | } |
| 360 | } |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 361 | if (c_ftrs) { |
| 362 | ident->iffeature = calloc(c_ftrs, sizeof *ident->iffeature); |
| 363 | if (!ident->iffeature) { |
| 364 | LOGMEM; |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 365 | goto error; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 366 | } |
| 367 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 368 | if (c_ext) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 369 | /* some extensions may be already present from the substatements */ |
| 370 | reallocated = realloc(ident->ext, (c_ext + ident->ext_size) * sizeof *ident->ext); |
| 371 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 372 | LOGMEM; |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 373 | goto error; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 374 | } |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 375 | ident->ext = reallocated; |
| 376 | |
| 377 | /* init memory */ |
| 378 | memset(&ident->ext[ident->ext_size], 0, c_ext * sizeof *ident->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 379 | } |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 380 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 381 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 382 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 383 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 384 | rc = lyp_yin_fill_ext(ident, LYEXT_PAR_IDENT, 0, 0, module, node, &ident->ext, ident->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 385 | ident->ext_size++; |
| 386 | if (rc) { |
| 387 | goto error; |
| 388 | } |
| 389 | } else if (!strcmp(node->name, "base")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 390 | GETVAL(value, node, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 391 | value = transform_schema2json(module, value); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 392 | if (!value) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 393 | goto error; |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 394 | } |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 395 | |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 396 | if (unres_schema_add_str(module, unres, ident, UNRES_IDENT, value) == -1) { |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 397 | lydict_remove(module->ctx, value); |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 398 | goto error; |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 399 | } |
| 400 | lydict_remove(module->ctx, value); |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 401 | } else if (!strcmp(node->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 402 | rc = fill_yin_iffeature((struct lys_node *)ident, 0, node, &ident->iffeature[ident->iffeature_size], unres); |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 403 | ident->iffeature_size++; |
| 404 | if (rc) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 405 | goto error; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 406 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 407 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 408 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 409 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 410 | return EXIT_SUCCESS; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 411 | |
| 412 | error: |
| 413 | return EXIT_FAILURE; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 414 | } |
| 415 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 416 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 417 | static int |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 418 | read_restr_substmt(struct lys_module *module, struct lys_restr *restr, struct lyxml_elem *yin, |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 419 | struct unres_schema *unres) |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 420 | { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 421 | struct lyxml_elem *child, *next; |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 422 | const char *value; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 423 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 424 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 425 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 426 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 427 | continue; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 428 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 429 | /* extension */ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 430 | if (lyp_yin_parse_subnode_ext(module, restr, LYEXT_PAR_RESTR, child, LYEXT_SUBSTMT_SELF, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 431 | return EXIT_FAILURE; |
| 432 | } |
| 433 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 434 | if (restr->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 435 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 436 | return EXIT_FAILURE; |
| 437 | } |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 438 | if (lyp_yin_parse_subnode_ext(module, restr, LYEXT_PAR_RESTR, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 439 | return EXIT_FAILURE; |
| 440 | } |
| 441 | restr->dsc = read_yin_subnode(module->ctx, child, "text"); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 442 | if (!restr->dsc) { |
| 443 | return EXIT_FAILURE; |
| 444 | } |
| 445 | } else if (!strcmp(child->name, "reference")) { |
| 446 | if (restr->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 447 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 448 | return EXIT_FAILURE; |
| 449 | } |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 450 | if (lyp_yin_parse_subnode_ext(module, restr, LYEXT_PAR_RESTR, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 451 | return EXIT_FAILURE; |
| 452 | } |
| 453 | restr->ref = read_yin_subnode(module->ctx, child, "text"); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 454 | if (!restr->ref) { |
| 455 | return EXIT_FAILURE; |
| 456 | } |
| 457 | } else if (!strcmp(child->name, "error-app-tag")) { |
| 458 | if (restr->eapptag) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 459 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 460 | return EXIT_FAILURE; |
| 461 | } |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 462 | if (lyp_yin_parse_subnode_ext(module, restr, LYEXT_PAR_RESTR, child, LYEXT_SUBSTMT_ERRTAG, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 463 | return EXIT_FAILURE; |
| 464 | } |
Michal Vasko | 54e426f | 2015-07-07 15:38:02 +0200 | [diff] [blame] | 465 | GETVAL(value, child, "value"); |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 466 | restr->eapptag = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 467 | } else if (!strcmp(child->name, "error-message")) { |
| 468 | if (restr->emsg) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 469 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 470 | return EXIT_FAILURE; |
| 471 | } |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 472 | if (lyp_yin_parse_subnode_ext(module, restr, LYEXT_PAR_RESTR, child, LYEXT_SUBSTMT_ERRMSG, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 473 | return EXIT_FAILURE; |
| 474 | } |
| 475 | restr->emsg = read_yin_subnode(module->ctx, child, "value"); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 476 | if (!restr->emsg) { |
| 477 | return EXIT_FAILURE; |
| 478 | } |
| 479 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 480 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 481 | return EXIT_FAILURE; |
| 482 | } |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 483 | } |
| 484 | |
| 485 | return EXIT_SUCCESS; |
Michal Vasko | c8ef47f | 2015-06-29 14:56:19 +0200 | [diff] [blame] | 486 | |
| 487 | error: |
| 488 | return EXIT_FAILURE; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 489 | } |
| 490 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 491 | /* logs directly, returns EXIT_SUCCESS, EXIT_FAILURE, -1 */ |
| 492 | int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 493 | fill_yin_type(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_type *type, |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 494 | int parenttype, struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 495 | { |
Michal Vasko | 0aee5c1 | 2016-06-17 14:27:26 +0200 | [diff] [blame] | 496 | const char *value, *name; |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 497 | struct lys_node *siter; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 498 | struct lyxml_elem *next, *next2, *node, *child, exts; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 499 | struct lys_restr **restrs, *restr; |
Radek Krejci | 1c5890d | 2016-08-02 13:15:42 +0200 | [diff] [blame] | 500 | struct lys_type_bit bit, *bits_sc = NULL; |
| 501 | struct lys_type_enum *enms_sc = NULL; /* shortcut */ |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 502 | struct lys_type *dertype; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 503 | int i, j, rc, val_set, c_ftrs, c_ext = 0; |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 504 | int ret = -1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 505 | int64_t v, v_; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 506 | int64_t p, p_; |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 507 | size_t len; |
| 508 | char *buf, modifier; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 509 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 510 | /* init */ |
| 511 | memset(&exts, 0, sizeof exts); |
| 512 | |
Radek Krejci | 8de7b0f | 2015-07-02 11:43:42 +0200 | [diff] [blame] | 513 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 514 | value = transform_schema2json(module, value); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 515 | if (!value) { |
| 516 | goto error; |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 517 | } |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 518 | |
| 519 | i = parse_identifier(value); |
| 520 | if (i < 1) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 521 | LOGVAL(LYE_INCHAR, LY_VLOG_NONE, NULL, value[-i], &value[-i]); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 522 | lydict_remove(module->ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 523 | goto error; |
| 524 | } |
| 525 | /* module name */ |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 526 | name = value; |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 527 | if (value[i]) { |
| 528 | type->module_name = lydict_insert(module->ctx, value, i); |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 529 | name += i; |
| 530 | if ((name[0] != ':') || (parse_identifier(name + 1) < 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 531 | LOGVAL(LYE_INCHAR, LY_VLOG_NONE, NULL, name[0], name); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 532 | lydict_remove(module->ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 533 | goto error; |
| 534 | } |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 535 | /* name is in dictionary, but moved */ |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 536 | ++name; |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 537 | } |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 538 | |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 539 | rc = resolve_superior_type(name, type->module_name, module, parent, &type->der); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 540 | if (rc == -1) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 541 | LOGVAL(LYE_INMOD, LY_VLOG_NONE, NULL, type->module_name); |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 542 | lydict_remove(module->ctx, value); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 543 | goto error; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 544 | |
| 545 | /* the type could not be resolved or it was resolved to an unresolved typedef */ |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 546 | } else if (rc == EXIT_FAILURE) { |
Michal Vasko | 01c6fd2 | 2016-05-20 11:43:05 +0200 | [diff] [blame] | 547 | LOGVAL(LYE_NORESOLV, LY_VLOG_NONE, NULL, "type", name); |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 548 | lydict_remove(module->ctx, value); |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 549 | ret = EXIT_FAILURE; |
| 550 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 551 | } |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 552 | lydict_remove(module->ctx, value); |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 553 | |
Radek Krejci | 9b6aad2 | 2016-09-20 15:55:51 +0200 | [diff] [blame] | 554 | if (type->base == LY_TYPE_ERR) { |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 555 | /* resolved type in grouping, decrease the grouping's nacm number to indicate that one less |
Radek Krejci | 9b6aad2 | 2016-09-20 15:55:51 +0200 | [diff] [blame] | 556 | * unresolved item left inside the grouping, LY_TYPE_ERR used as a flag for types inside a grouping. */ |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 557 | for (siter = parent; siter && (siter->nodetype != LYS_GROUPING); siter = lys_parent(siter)); |
| 558 | if (siter) { |
Radek Krejci | 6ff885d | 2017-01-03 14:06:22 +0100 | [diff] [blame] | 559 | #if __BYTE_ORDER == __LITTLE_ENDIAN |
| 560 | if (!((uint8_t*)&((struct lys_node_grp *)siter)->flags)[1]) { |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 561 | LOGINT; |
| 562 | goto error; |
| 563 | } |
Radek Krejci | 6ff885d | 2017-01-03 14:06:22 +0100 | [diff] [blame] | 564 | ((uint8_t*)&((struct lys_node_grp *)siter)->flags)[1]--; |
| 565 | #else |
| 566 | if (!((uint8_t*)&((struct lys_node_grp *)siter)->flags)[0]) { |
| 567 | LOGINT; |
| 568 | goto error; |
| 569 | } |
| 570 | ((uint8_t*)&((struct lys_node_grp *)siter)->flags)[0]--; |
| 571 | #endif |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 572 | } else { |
| 573 | LOGINT; |
| 574 | goto error; |
| 575 | } |
| 576 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 577 | type->base = type->der->type.base; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 578 | |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 579 | /* check status */ |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 580 | if (lyp_check_status(type->parent->flags, type->parent->module, type->parent->name, |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 581 | type->der->flags, type->der->module, type->der->name, parent)) { |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 582 | return -1; |
| 583 | } |
| 584 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 585 | /* parse extension instances */ |
| 586 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 587 | if (!node->ns) { |
| 588 | /* garbage */ |
| 589 | lyxml_free(module->ctx, node); |
| 590 | continue; |
| 591 | } else if (!strcmp(node->ns->value, LY_NSYIN)) { |
| 592 | /* YANG (YIN) statements - process later */ |
| 593 | continue; |
| 594 | } |
| 595 | |
| 596 | lyxml_unlink_elem(module->ctx, node, 2); |
| 597 | lyxml_add_child(module->ctx, &exts, node); |
| 598 | c_ext++; |
| 599 | } |
| 600 | if (c_ext) { |
| 601 | type->ext = calloc(c_ext, sizeof *type->ext); |
| 602 | if (!type->ext) { |
| 603 | LOGMEM; |
| 604 | goto error; |
| 605 | } |
| 606 | LY_TREE_FOR_SAFE(exts.child, next, node) { |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 607 | rc = lyp_yin_fill_ext(type, LYEXT_PAR_TYPE, 0, 0, module, node, &type->ext, type->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 608 | type->ext_size++; |
| 609 | if (rc) { |
| 610 | goto error; |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 615 | switch (type->base) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 616 | case LY_TYPE_BITS: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 617 | /* RFC 6020 9.7.4 - bit */ |
| 618 | |
| 619 | /* get bit specifications, at least one must be present */ |
| 620 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 621 | if (!strcmp(node->name, "bit")) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 622 | type->info.bits.count++; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 623 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 624 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 625 | type->info.bits.count = 0; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 626 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 627 | } |
| 628 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 629 | dertype = &type->der->type; |
| 630 | if (!dertype->der) { |
| 631 | if (!type->info.bits.count) { |
| 632 | /* type is derived directly from buit-in bits type and bit statement is required */ |
| 633 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "bit", "type"); |
| 634 | goto error; |
| 635 | } |
| 636 | } else { |
| 637 | for (; !dertype->info.enums.count; dertype = &dertype->der->type); |
| 638 | if (module->version < 2 && type->info.bits.count) { |
| 639 | /* type is not directly derived from buit-in bits type and bit statement is prohibited, |
| 640 | * since YANG 1.1 the bit statements can be used to restrict the base bits type */ |
| 641 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "bit"); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 642 | type->info.bits.count = 0; |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 643 | goto error; |
| 644 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 645 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 646 | |
| 647 | type->info.bits.bit = calloc(type->info.bits.count, sizeof *type->info.bits.bit); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 648 | if (!type->info.bits.bit) { |
| 649 | LOGMEM; |
| 650 | goto error; |
| 651 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 652 | p = 0; |
| 653 | i = -1; |
| 654 | LY_TREE_FOR(yin->child, next) { |
| 655 | i++; |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 656 | c_ftrs = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 657 | |
| 658 | GETVAL(value, next, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 659 | if (lyp_check_identifier(value, LY_IDENT_SIMPLE, NULL, NULL)) { |
Michal Vasko | 2d26a02 | 2015-12-07 09:27:21 +0100 | [diff] [blame] | 660 | goto error; |
| 661 | } |
| 662 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 663 | type->info.bits.bit[i].name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 664 | if (read_yin_common(module, NULL, &type->info.bits.bit[i], LYEXT_PAR_TYPE_BIT, next, 0, unres)) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 665 | type->info.bits.count = i + 1; |
| 666 | goto error; |
| 667 | } |
| 668 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 669 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 670 | /* check the name uniqueness */ |
| 671 | for (j = 0; j < i; j++) { |
| 672 | if (!strcmp(type->info.bits.bit[j].name, type->info.bits.bit[i].name)) { |
| 673 | LOGVAL(LYE_BITS_DUPNAME, LY_VLOG_NONE, NULL, type->info.bits.bit[i].name); |
| 674 | type->info.bits.count = i + 1; |
| 675 | goto error; |
| 676 | } |
| 677 | } |
| 678 | } else { |
| 679 | /* restricted bits type - the name MUST be used in the base type */ |
| 680 | bits_sc = dertype->info.bits.bit; |
| 681 | for (j = 0; j < dertype->info.bits.count; j++) { |
| 682 | if (ly_strequal(bits_sc[j].name, value, 1)) { |
| 683 | break; |
| 684 | } |
| 685 | } |
| 686 | if (j == dertype->info.bits.count) { |
| 687 | LOGVAL(LYE_BITS_INNAME, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 688 | type->info.bits.count = i + 1; |
| 689 | goto error; |
| 690 | } |
| 691 | } |
| 692 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 693 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 694 | p_ = -1; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 695 | LY_TREE_FOR_SAFE(next->child, next2, node) { |
| 696 | if (!node->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 697 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 698 | continue; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 699 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 700 | /* extension */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 701 | if (lyp_yin_parse_subnode_ext(module, &type->info.bits.bit[i], LYEXT_PAR_TYPE_BIT, node, |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 702 | LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 703 | goto error; |
| 704 | } |
| 705 | } else if (!strcmp(node->name, "position")) { |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 706 | if (p_ != -1) { |
| 707 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, next->name); |
| 708 | type->info.bits.count = i + 1; |
| 709 | goto error; |
| 710 | } |
| 711 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 712 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 713 | p_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 714 | |
| 715 | /* range check */ |
Radek Krejci | b8ca108 | 2015-07-10 11:24:11 +0200 | [diff] [blame] | 716 | if (p_ < 0 || p_ > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 717 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "bit/position"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 718 | type->info.bits.count = i + 1; |
| 719 | goto error; |
| 720 | } |
| 721 | type->info.bits.bit[i].pos = (uint32_t)p_; |
| 722 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 723 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 724 | /* keep the highest enum value for automatic increment */ |
| 725 | if (type->info.bits.bit[i].pos >= p) { |
| 726 | p = type->info.bits.bit[i].pos; |
| 727 | p++; |
| 728 | } else { |
| 729 | /* check that the value is unique */ |
| 730 | for (j = 0; j < i; j++) { |
| 731 | if (type->info.bits.bit[j].pos == type->info.bits.bit[i].pos) { |
| 732 | LOGVAL(LYE_BITS_DUPVAL, LY_VLOG_NONE, NULL, |
| 733 | type->info.bits.bit[i].pos, type->info.bits.bit[i].name, |
| 734 | type->info.bits.bit[j].name); |
| 735 | type->info.bits.count = i + 1; |
| 736 | goto error; |
| 737 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 738 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 739 | } |
| 740 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 741 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 742 | if (lyp_yin_parse_subnode_ext(module, &type->info.bits.bit[i], LYEXT_PAR_TYPE_BIT, node, |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 743 | LYEXT_SUBSTMT_POSITION, 0, unres)) { |
| 744 | goto error; |
| 745 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 746 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
| 747 | c_ftrs++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 748 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 749 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 750 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 751 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 752 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 753 | |
| 754 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 755 | if (p_ == -1) { |
| 756 | /* assign value automatically */ |
| 757 | if (p > UINT32_MAX) { |
| 758 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "4294967295", "bit/position"); |
| 759 | type->info.bits.count = i + 1; |
| 760 | goto error; |
| 761 | } |
| 762 | type->info.bits.bit[i].pos = (uint32_t)p; |
| 763 | type->info.bits.bit[i].flags |= LYS_AUTOASSIGNED; |
| 764 | p++; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 765 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 766 | } else { /* restricted bits type */ |
| 767 | if (p_ == -1) { |
| 768 | /* automatically assign position from base type */ |
| 769 | type->info.bits.bit[i].pos = bits_sc[j].pos; |
| 770 | type->info.bits.bit[i].flags |= LYS_AUTOASSIGNED; |
| 771 | } else { |
| 772 | /* check that the assigned position corresponds to the original |
| 773 | * position of the bit in the base type */ |
| 774 | if (p_ != bits_sc[j].pos) { |
| 775 | /* p_ - assigned position in restricted bits |
| 776 | * bits_sc[j].pos - position assigned to the corresponding bit (detected above) in base type */ |
| 777 | LOGVAL(LYE_BITS_INVAL, LY_VLOG_NONE, NULL, type->info.bits.bit[i].pos, |
Radek Krejci | 541a45d | 2016-08-02 13:12:07 +0200 | [diff] [blame] | 778 | type->info.bits.bit[i].name, bits_sc[j].pos); |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 779 | type->info.bits.count = i + 1; |
| 780 | goto error; |
| 781 | } |
| 782 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 783 | } |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 784 | |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 785 | /* if-features */ |
| 786 | if (c_ftrs) { |
| 787 | bits_sc = &type->info.bits.bit[i]; |
| 788 | bits_sc->iffeature = calloc(c_ftrs, sizeof *bits_sc->iffeature); |
| 789 | if (!bits_sc->iffeature) { |
| 790 | LOGMEM; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 791 | type->info.bits.count = i + 1; |
| 792 | goto error; |
| 793 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 794 | |
| 795 | LY_TREE_FOR(next->child, node) { |
| 796 | if (!strcmp(node->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 797 | rc = fill_yin_iffeature((struct lys_node *)type->parent, 0, node, |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 798 | &bits_sc->iffeature[bits_sc->iffeature_size], unres); |
| 799 | bits_sc->iffeature_size++; |
| 800 | if (rc) { |
| 801 | type->info.bits.count = i + 1; |
| 802 | goto error; |
| 803 | } |
| 804 | } |
| 805 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 806 | } |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 807 | |
| 808 | /* keep them ordered by position */ |
| 809 | j = i; |
| 810 | while (j && type->info.bits.bit[j - 1].pos > type->info.bits.bit[j].pos) { |
| 811 | /* switch them */ |
| 812 | memcpy(&bit, &type->info.bits.bit[j], sizeof bit); |
| 813 | memcpy(&type->info.bits.bit[j], &type->info.bits.bit[j - 1], sizeof bit); |
| 814 | memcpy(&type->info.bits.bit[j - 1], &bit, sizeof bit); |
| 815 | j--; |
| 816 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 817 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 818 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 819 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 820 | case LY_TYPE_DEC64: |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 821 | /* RFC 6020 9.2.4 - range and 9.3.4 - fraction-digits */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 822 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 823 | |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 824 | if (!strcmp(node->name, "range")) { |
| 825 | if (type->info.dec64.range) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 826 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 827 | goto error; |
| 828 | } |
| 829 | |
| 830 | GETVAL(value, node, "value"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 831 | type->info.dec64.range = calloc(1, sizeof *type->info.dec64.range); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 832 | if (!type->info.dec64.range) { |
| 833 | LOGMEM; |
| 834 | goto error; |
| 835 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 836 | type->info.dec64.range->expr = lydict_insert(module->ctx, value, 0); |
| 837 | |
| 838 | /* get possible substatements */ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 839 | if (read_restr_substmt(module, type->info.dec64.range, node, unres)) { |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 840 | goto error; |
| 841 | } |
| 842 | } else if (!strcmp(node->name, "fraction-digits")) { |
| 843 | if (type->info.dec64.dig) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 844 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 845 | goto error; |
| 846 | } |
| 847 | GETVAL(value, node, "value"); |
| 848 | v = strtol(value, NULL, 10); |
| 849 | |
| 850 | /* range check */ |
| 851 | if (v < 1 || v > 18) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 852 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 853 | goto error; |
| 854 | } |
| 855 | type->info.dec64.dig = (uint8_t)v; |
Radek Krejci | 8c3b4b6 | 2016-06-17 14:32:12 +0200 | [diff] [blame] | 856 | type->info.dec64.div = 10; |
| 857 | for (i = 1; i < v; i++) { |
| 858 | type->info.dec64.div *= 10; |
| 859 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 860 | |
| 861 | /* extensions */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 862 | if (lyp_yin_parse_subnode_ext(module, type, LYEXT_PAR_TYPE, node, LYEXT_SUBSTMT_DIGITS, 0, unres)) { |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 863 | goto error; |
| 864 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 865 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 866 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 867 | goto error; |
| 868 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | /* mandatory sub-statement(s) check */ |
| 872 | if (!type->info.dec64.dig && !type->der->type.der) { |
| 873 | /* decimal64 type directly derived from built-in type requires fraction-digits */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 874 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "fraction-digits", "type"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 875 | goto error; |
| 876 | } |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 877 | if (type->info.dec64.dig && type->der->type.der) { |
| 878 | /* type is not directly derived from buit-in type and fraction-digits statement is prohibited */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 879 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "fraction-digits"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 880 | goto error; |
| 881 | } |
Radek Krejci | 4800f65 | 2016-09-08 14:02:52 +0200 | [diff] [blame] | 882 | |
| 883 | /* copy fraction-digits specification from parent type for easier internal use */ |
| 884 | if (type->der->type.der) { |
| 885 | type->info.dec64.dig = type->der->type.info.dec64.dig; |
| 886 | type->info.dec64.div = type->der->type.info.dec64.div; |
| 887 | } |
| 888 | |
Pavol Vican | 3c8ee2b | 2016-09-29 13:18:13 +0200 | [diff] [blame] | 889 | if (type->info.dec64.range && lyp_check_length_range(type->info.dec64.range->expr, type)) { |
| 890 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "range"); |
| 891 | goto error; |
| 892 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 893 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 894 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 895 | case LY_TYPE_ENUM: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 896 | /* RFC 6020 9.6 - enum */ |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 897 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 898 | /* get enum specifications, at least one must be present */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 899 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 900 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 901 | if (!strcmp(node->name, "enum")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 902 | type->info.enums.count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 903 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 904 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 905 | type->info.enums.count = 0; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 906 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 907 | } |
| 908 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 909 | dertype = &type->der->type; |
| 910 | if (!dertype->der) { |
| 911 | if (!type->info.enums.count) { |
| 912 | /* type is derived directly from buit-in enumeartion type and enum statement is required */ |
| 913 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "enum", "type"); |
| 914 | goto error; |
| 915 | } |
| 916 | } else { |
| 917 | for (; !dertype->info.enums.count; dertype = &dertype->der->type); |
| 918 | if (module->version < 2 && type->info.enums.count) { |
| 919 | /* type is not directly derived from built-in enumeration type and enum statement is prohibited |
| 920 | * in YANG 1.0, since YANG 1.1 enum statements can be used to restrict the base enumeration type */ |
| 921 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "enum"); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 922 | type->info.enums.count = 0; |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 923 | goto error; |
| 924 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 925 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 926 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 927 | type->info.enums.enm = calloc(type->info.enums.count, sizeof *type->info.enums.enm); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 928 | if (!type->info.enums.enm) { |
| 929 | LOGMEM; |
| 930 | goto error; |
| 931 | } |
Radek Krejci | fc8d832 | 2016-06-24 11:23:23 +0200 | [diff] [blame] | 932 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 933 | v = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 934 | i = -1; |
| 935 | LY_TREE_FOR(yin->child, next) { |
| 936 | i++; |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 937 | c_ftrs = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 938 | |
| 939 | GETVAL(value, next, "name"); |
Michal Vasko | 0fb58e9 | 2015-12-07 09:27:44 +0100 | [diff] [blame] | 940 | if (!value[0]) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 941 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "enum name"); |
| 942 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Enum name must not be empty."); |
Michal Vasko | 0fb58e9 | 2015-12-07 09:27:44 +0100 | [diff] [blame] | 943 | goto error; |
| 944 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 945 | type->info.enums.enm[i].name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 946 | if (read_yin_common(module, NULL, &type->info.enums.enm[i], LYEXT_PAR_TYPE_ENUM, next, 0, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 947 | type->info.enums.count = i + 1; |
| 948 | goto error; |
| 949 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 950 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 951 | /* the assigned name MUST NOT have any leading or trailing whitespace characters */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 952 | value = type->info.enums.enm[i].name; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 953 | if (isspace(value[0]) || isspace(value[strlen(value) - 1])) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 954 | LOGVAL(LYE_ENUM_WS, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 955 | type->info.enums.count = i + 1; |
| 956 | goto error; |
| 957 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 958 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 959 | if (!dertype->der) { /* directly derived type from enumeration built-in type */ |
| 960 | /* check the name uniqueness */ |
| 961 | for (j = 0; j < i; j++) { |
| 962 | if (ly_strequal(type->info.enums.enm[j].name, value, 1)) { |
| 963 | LOGVAL(LYE_ENUM_DUPNAME, LY_VLOG_NONE, NULL, value); |
| 964 | type->info.enums.count = i + 1; |
| 965 | goto error; |
| 966 | } |
| 967 | } |
| 968 | } else { |
| 969 | /* restricted enumeration type - the name MUST be used in the base type */ |
| 970 | enms_sc = dertype->info.enums.enm; |
| 971 | for (j = 0; j < dertype->info.enums.count; j++) { |
| 972 | if (ly_strequal(enms_sc[j].name, value, 1)) { |
| 973 | break; |
| 974 | } |
| 975 | } |
| 976 | if (j == dertype->info.enums.count) { |
| 977 | LOGVAL(LYE_ENUM_INNAME, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 978 | type->info.enums.count = i + 1; |
| 979 | goto error; |
| 980 | } |
| 981 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 982 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 983 | val_set = 0; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 984 | LY_TREE_FOR_SAFE(next->child, next2, node) { |
| 985 | if (!node->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 986 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 987 | continue; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 988 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 989 | /* extensions */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 990 | if (lyp_yin_parse_subnode_ext(module, &type->info.enums.enm[i], LYEXT_PAR_TYPE_ENUM, node, |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 991 | LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 992 | goto error; |
| 993 | } |
| 994 | } else if (!strcmp(node->name, "value")) { |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 995 | if (val_set) { |
| 996 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, next->name); |
| 997 | type->info.enums.count = i + 1; |
| 998 | goto error; |
| 999 | } |
| 1000 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1001 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 1002 | v_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1003 | |
| 1004 | /* range check */ |
| 1005 | if (v_ < INT32_MIN || v_ > INT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1006 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "enum/value"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1007 | type->info.enums.count = i + 1; |
| 1008 | goto error; |
| 1009 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1010 | type->info.enums.enm[i].value = v_; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1011 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1012 | if (!dertype->der) { /* directly derived type from enumeration built-in type */ |
Pavol Vican | 5de389c | 2016-08-30 08:55:15 +0200 | [diff] [blame] | 1013 | if (!i) { |
| 1014 | /* change value, which is assigned automatically, if first enum has value. */ |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1015 | v = type->info.enums.enm[i].value; |
| 1016 | v++; |
| 1017 | } else { |
Pavol Vican | 5de389c | 2016-08-30 08:55:15 +0200 | [diff] [blame] | 1018 | /* keep the highest enum value for automatic increment */ |
| 1019 | if (type->info.enums.enm[i].value >= v) { |
| 1020 | v = type->info.enums.enm[i].value; |
| 1021 | v++; |
| 1022 | } else { |
| 1023 | /* check that the value is unique */ |
| 1024 | for (j = 0; j < i; j++) { |
| 1025 | if (type->info.enums.enm[j].value == type->info.enums.enm[i].value) { |
| 1026 | LOGVAL(LYE_ENUM_DUPVAL, LY_VLOG_NONE, NULL, |
| 1027 | type->info.enums.enm[i].value, type->info.enums.enm[i].name, |
| 1028 | type->info.enums.enm[j].name); |
| 1029 | type->info.enums.count = i + 1; |
| 1030 | goto error; |
| 1031 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1032 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1033 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1034 | } |
| 1035 | } |
Radek Krejci | fc8d832 | 2016-06-24 11:23:23 +0200 | [diff] [blame] | 1036 | val_set = 1; |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1037 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1038 | if (lyp_yin_parse_subnode_ext(module, &type->info.enums.enm[i], LYEXT_PAR_TYPE_ENUM, node, |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 1039 | LYEXT_SUBSTMT_VALUE, 0, unres)) { |
| 1040 | goto error; |
| 1041 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1042 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
| 1043 | c_ftrs++; |
| 1044 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1045 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1046 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1047 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1048 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1049 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1050 | |
| 1051 | if (!dertype->der) { /* directly derived type from enumeration */ |
| 1052 | if (!val_set) { |
| 1053 | /* assign value automatically */ |
| 1054 | if (v > INT32_MAX) { |
| 1055 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "2147483648", "enum/value"); |
| 1056 | type->info.enums.count = i + 1; |
| 1057 | goto error; |
| 1058 | } |
| 1059 | type->info.enums.enm[i].value = v; |
| 1060 | type->info.enums.enm[i].flags |= LYS_AUTOASSIGNED; |
| 1061 | v++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1062 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1063 | } else { /* restricted enum type */ |
| 1064 | if (!val_set) { |
| 1065 | /* automatically assign value from base type */ |
| 1066 | type->info.enums.enm[i].value = enms_sc[j].value; |
| 1067 | type->info.enums.enm[i].flags |= LYS_AUTOASSIGNED; |
| 1068 | } else { |
| 1069 | /* check that the assigned value corresponds to the original |
| 1070 | * value of the enum in the base type */ |
| 1071 | if (v_ != enms_sc[j].value) { |
| 1072 | /* v_ - assigned value in restricted enum |
| 1073 | * enms_sc[j].value - value assigned to the corresponding enum (detected above) in base type */ |
| 1074 | LOGVAL(LYE_ENUM_INVAL, LY_VLOG_NONE, NULL, |
Radek Krejci | 541a45d | 2016-08-02 13:12:07 +0200 | [diff] [blame] | 1075 | type->info.enums.enm[i].value, type->info.enums.enm[i].name, enms_sc[j].value); |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1076 | type->info.enums.count = i + 1; |
| 1077 | goto error; |
| 1078 | } |
| 1079 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1080 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1081 | |
| 1082 | /* if-features */ |
| 1083 | if (c_ftrs) { |
| 1084 | enms_sc = &type->info.enums.enm[i]; |
| 1085 | enms_sc->iffeature = calloc(c_ftrs, sizeof *enms_sc->iffeature); |
| 1086 | if (!enms_sc->iffeature) { |
| 1087 | LOGMEM; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1088 | type->info.enums.count = i + 1; |
| 1089 | goto error; |
| 1090 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1091 | |
| 1092 | LY_TREE_FOR(next->child, node) { |
| 1093 | if (!strcmp(node->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 1094 | rc = fill_yin_iffeature((struct lys_node *)type->parent, 0, node, |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1095 | &enms_sc->iffeature[enms_sc->iffeature_size], unres); |
| 1096 | enms_sc->iffeature_size++; |
| 1097 | if (rc) { |
| 1098 | type->info.enums.count = i + 1; |
| 1099 | goto error; |
| 1100 | } |
| 1101 | } |
| 1102 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1103 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1104 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1105 | } |
| 1106 | break; |
| 1107 | |
| 1108 | case LY_TYPE_IDENT: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 1109 | /* RFC 6020 9.10 - base */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1110 | |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1111 | /* get base specification, at least one must be present */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1112 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1113 | |
Michal Vasko | e29c662 | 2015-11-27 15:02:31 +0100 | [diff] [blame] | 1114 | if (strcmp(node->name, "base")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1115 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1116 | goto error; |
| 1117 | } |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1118 | |
| 1119 | GETVAL(value, yin->child, "name"); |
| 1120 | /* store in the JSON format */ |
| 1121 | value = transform_schema2json(module, value); |
| 1122 | if (!value) { |
| 1123 | goto error; |
| 1124 | } |
| 1125 | rc = unres_schema_add_str(module, unres, type, UNRES_TYPE_IDENTREF, value); |
| 1126 | lydict_remove(module->ctx, value); |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1127 | if (rc == -1) { |
| 1128 | goto error; |
| 1129 | } |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 1130 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1131 | if (lyp_yin_parse_subnode_ext(module, type, LYEXT_PAR_TYPE, node, LYEXT_SUBSTMT_BASE, 0, unres)) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 1132 | goto error; |
| 1133 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1134 | } |
| 1135 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1136 | if (!yin->child) { |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 1137 | if (type->der->type.der) { |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1138 | /* this is just a derived type with no base required */ |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 1139 | break; |
| 1140 | } |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1141 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "base", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1142 | goto error; |
Pavol Vican | f0046f4 | 2016-09-07 15:11:09 +0200 | [diff] [blame] | 1143 | } else { |
| 1144 | if (type->der->type.der) { |
| 1145 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "base"); |
| 1146 | goto error; |
| 1147 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1148 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1149 | if (yin->child->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1150 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, yin->child->next->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1151 | goto error; |
| 1152 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1153 | break; |
| 1154 | |
| 1155 | case LY_TYPE_INST: |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1156 | /* RFC 6020 9.13.2 - require-instance */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1157 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1158 | |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1159 | if (!strcmp(node->name, "require-instance")) { |
| 1160 | if (type->info.inst.req) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1161 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1162 | goto error; |
| 1163 | } |
| 1164 | GETVAL(value, node, "value"); |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 1165 | if (!strcmp(value, "true")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1166 | type->info.inst.req = 1; |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 1167 | } else if (!strcmp(value, "false")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1168 | type->info.inst.req = -1; |
| 1169 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1170 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1171 | goto error; |
| 1172 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1173 | |
| 1174 | /* extensions */ |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 1175 | if (lyp_yin_parse_subnode_ext(module, type, LYEXT_PAR_TYPE, node, LYEXT_SUBSTMT_REQINSTANCE, 0, unres)) { |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1176 | goto error; |
| 1177 | } |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1178 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1179 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1180 | goto error; |
| 1181 | } |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1182 | } |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 1183 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1184 | break; |
| 1185 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1186 | case LY_TYPE_BINARY: |
| 1187 | /* RFC 6020 9.8.1, 9.4.4 - length, number of octets it contains */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1188 | case LY_TYPE_INT8: |
| 1189 | case LY_TYPE_INT16: |
| 1190 | case LY_TYPE_INT32: |
| 1191 | case LY_TYPE_INT64: |
| 1192 | case LY_TYPE_UINT8: |
| 1193 | case LY_TYPE_UINT16: |
| 1194 | case LY_TYPE_UINT32: |
| 1195 | case LY_TYPE_UINT64: |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1196 | /* RFC 6020 9.2.4 - range */ |
| 1197 | |
| 1198 | /* length and range are actually the same restriction, so process |
| 1199 | * them by this common code, we just need to differ the name and |
| 1200 | * structure where the information will be stored |
| 1201 | */ |
| 1202 | if (type->base == LY_TYPE_BINARY) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1203 | restrs = &type->info.binary.length; |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1204 | name = "length"; |
| 1205 | } else { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1206 | restrs = &type->info.num.range; |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1207 | name = "range"; |
| 1208 | } |
| 1209 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1210 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1211 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1212 | if (!strcmp(node->name, name)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1213 | if (*restrs) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1214 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1215 | goto error; |
| 1216 | } |
| 1217 | |
| 1218 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 1219 | if (lyp_check_length_range(value, type)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1220 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1221 | goto error; |
| 1222 | } |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1223 | *restrs = calloc(1, sizeof **restrs); |
| 1224 | if (!(*restrs)) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1225 | LOGMEM; |
| 1226 | goto error; |
| 1227 | } |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1228 | (*restrs)->expr = lydict_insert(module->ctx, value, 0); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1229 | |
| 1230 | /* get possible substatements */ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 1231 | if (read_restr_substmt(module, *restrs, node, unres)) { |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1232 | goto error; |
| 1233 | } |
| 1234 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1235 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1236 | goto error; |
| 1237 | } |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1238 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1239 | break; |
| 1240 | |
| 1241 | case LY_TYPE_LEAFREF: |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1242 | /* flag resolving for later use */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1243 | if (!parenttype) { |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1244 | for (siter = parent; siter && siter->nodetype != LYS_GROUPING; siter = lys_parent(siter)); |
| 1245 | if (siter) { |
| 1246 | /* just a flag - do not resolve */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1247 | parenttype = 1; |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1248 | } |
| 1249 | } |
| 1250 | |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1251 | /* RFC 6020 9.9.2 - path */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1252 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1253 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1254 | if (!strcmp(node->name, "path") && !type->der->type.der) { |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1255 | if (type->info.lref.path) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1256 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1257 | goto error; |
| 1258 | } |
| 1259 | |
| 1260 | GETVAL(value, node, "value"); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 1261 | /* store in the JSON format */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1262 | type->info.lref.path = transform_schema2json(module, value); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 1263 | if (!type->info.lref.path) { |
| 1264 | goto error; |
| 1265 | } |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1266 | |
| 1267 | /* try to resolve leafref path only when this is instantiated |
| 1268 | * leaf, so it is not: |
| 1269 | * - typedef's type, |
| 1270 | * - in grouping definition, |
| 1271 | * - just instantiated in a grouping definition, |
| 1272 | * because in those cases the nodes referenced in path might not be present |
| 1273 | * and it is not a bug. */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1274 | if (!parenttype && unres_schema_add_node(module, unres, type, UNRES_TYPE_LEAFREF, parent) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1275 | goto error; |
| 1276 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1277 | |
| 1278 | /* extensions */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1279 | if (lyp_yin_parse_subnode_ext(module, type, LYEXT_PAR_TYPE, node, LYEXT_SUBSTMT_PATH, 0, unres)) { |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1280 | goto error; |
| 1281 | } |
Radek Krejci | d6353ed | 2016-09-15 13:30:45 +0200 | [diff] [blame] | 1282 | } else if (module->version >= 2 && !strcmp(node->name, "require-instance")) { |
Michal Vasko | 08ae53e | 2016-09-02 12:40:04 +0200 | [diff] [blame] | 1283 | if (type->info.lref.req) { |
| 1284 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
| 1285 | goto error; |
| 1286 | } |
| 1287 | GETVAL(value, node, "value"); |
| 1288 | if (!strcmp(value, "true")) { |
| 1289 | type->info.lref.req = 1; |
| 1290 | } else if (!strcmp(value, "false")) { |
| 1291 | type->info.lref.req = -1; |
| 1292 | } else { |
| 1293 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
| 1294 | goto error; |
| 1295 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1296 | |
| 1297 | /* extensions */ |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 1298 | if (lyp_yin_parse_subnode_ext(module, type, LYEXT_PAR_TYPE, node, LYEXT_SUBSTMT_REQINSTANCE, 0, unres)) { |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1299 | goto error; |
| 1300 | } |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1301 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1302 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1303 | goto error; |
| 1304 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1305 | } |
| 1306 | |
Radek Krejci | 742be35 | 2016-07-17 12:18:54 +0200 | [diff] [blame] | 1307 | if (!type->info.lref.path) { |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1308 | if (!type->der->type.der) { |
| 1309 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "path", "type"); |
| 1310 | goto error; |
| 1311 | } else { |
| 1312 | /* copy leafref definition into the derived type */ |
| 1313 | type->info.lref.path = lydict_insert(module->ctx, type->der->type.info.lref.path, 0); |
| 1314 | /* and resolve the path at the place we are (if not in grouping/typedef) */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1315 | if (!parenttype && unres_schema_add_node(module, unres, type, UNRES_TYPE_LEAFREF, parent) == -1) { |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1316 | goto error; |
| 1317 | } |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1318 | } |
Radek Krejci | 742be35 | 2016-07-17 12:18:54 +0200 | [diff] [blame] | 1319 | } |
| 1320 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1321 | break; |
| 1322 | |
| 1323 | case LY_TYPE_STRING: |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1324 | /* RFC 6020 9.4.4 - length */ |
| 1325 | /* RFC 6020 9.4.6 - pattern */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1326 | i = 0; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1327 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1328 | |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1329 | if (!strcmp(node->name, "length")) { |
| 1330 | if (type->info.str.length) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1331 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1332 | goto error; |
| 1333 | } |
| 1334 | |
| 1335 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 1336 | if (lyp_check_length_range(value, type)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1337 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "length"); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1338 | goto error; |
| 1339 | } |
| 1340 | type->info.str.length = calloc(1, sizeof *type->info.str.length); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1341 | if (!type->info.str.length) { |
| 1342 | LOGMEM; |
| 1343 | goto error; |
| 1344 | } |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1345 | type->info.str.length->expr = lydict_insert(module->ctx, value, 0); |
| 1346 | |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1347 | /* get possible sub-statements */ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 1348 | if (read_restr_substmt(module, type->info.str.length, node, unres)) { |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1349 | goto error; |
| 1350 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1351 | lyxml_free(module->ctx, node); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1352 | } else if (!strcmp(node->name, "pattern")) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1353 | i++; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1354 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1355 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1356 | goto error; |
| 1357 | } |
| 1358 | } |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1359 | /* store patterns in array */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1360 | if (i) { |
| 1361 | type->info.str.patterns = calloc(i, sizeof *type->info.str.patterns); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1362 | if (!type->info.str.patterns) { |
| 1363 | LOGMEM; |
| 1364 | goto error; |
| 1365 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1366 | LY_TREE_FOR(yin->child, node) { |
Michal Vasko | 5b64da2 | 2015-11-23 15:22:30 +0100 | [diff] [blame] | 1367 | GETVAL(value, node, "value"); |
Michal Vasko | 0aee5c1 | 2016-06-17 14:27:26 +0200 | [diff] [blame] | 1368 | if (lyp_check_pattern(value, NULL)) { |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1369 | free(type->info.str.patterns); |
Radek Krejci | 9f1e853 | 2016-06-16 11:18:21 +0200 | [diff] [blame] | 1370 | type->info.str.patterns = NULL; |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1371 | goto error; |
| 1372 | } |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1373 | restr = &type->info.str.patterns[type->info.str.pat_count]; /* shortcut */ |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1374 | |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1375 | modifier = 0x06; /* ACK */ |
| 1376 | name = NULL; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1377 | if (module->version >= 2) { |
| 1378 | LY_TREE_FOR_SAFE(node->child, next2, child) { |
| 1379 | if (child->ns && !strcmp(child->ns->value, LY_NSYIN) && !strcmp(child->name, "modifier")) { |
| 1380 | if (name) { |
| 1381 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "modifier", node->name); |
| 1382 | goto error; |
| 1383 | } |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1384 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1385 | GETVAL(name, child, "value"); |
| 1386 | if (!strcmp(name, "invert-match")) { |
| 1387 | modifier = 0x15; /* NACK */ |
| 1388 | } else { |
| 1389 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, name, "modifier"); |
| 1390 | goto error; |
| 1391 | } |
| 1392 | /* get extensions of the modifier */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1393 | if (lyp_yin_parse_subnode_ext(module, restr, LYEXT_PAR_RESTR, child, |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 1394 | LYEXT_SUBSTMT_MODIFIER, 0, unres)) { |
| 1395 | goto error; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1396 | } |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1397 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1398 | lyxml_free(module->ctx, child); |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1399 | } |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1400 | } |
| 1401 | } |
| 1402 | |
| 1403 | len = strlen(value); |
| 1404 | buf = malloc((len + 2) * sizeof *buf); /* modifier byte + value + terminating NULL byte */ |
| 1405 | buf[0] = modifier; |
| 1406 | strcpy(&buf[1], value); |
| 1407 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1408 | restr->expr = lydict_insert_zc(module->ctx, buf); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1409 | |
| 1410 | /* get possible sub-statements */ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 1411 | if (read_restr_substmt(module, restr, node, unres)) { |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1412 | free(type->info.str.patterns); |
Pavol Vican | 9fc5d64 | 2016-08-30 15:23:19 +0200 | [diff] [blame] | 1413 | type->info.str.patterns = NULL; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1414 | goto error; |
| 1415 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1416 | type->info.str.pat_count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1417 | } |
| 1418 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1419 | break; |
| 1420 | |
| 1421 | case LY_TYPE_UNION: |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1422 | /* RFC 6020 7.4 - type */ |
| 1423 | /* count number of types in union */ |
| 1424 | i = 0; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1425 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1426 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1427 | if (!strcmp(node->name, "type")) { |
Radek Krejci | 038d5d9 | 2016-09-12 15:07:15 +0200 | [diff] [blame] | 1428 | if (type->der->type.der) { |
| 1429 | /* type can be a substatement only in "union" type, not in derived types */ |
| 1430 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "derived type"); |
| 1431 | goto error; |
| 1432 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1433 | i++; |
| 1434 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1435 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1436 | goto error; |
| 1437 | } |
| 1438 | } |
| 1439 | |
Radek Krejci | 038d5d9 | 2016-09-12 15:07:15 +0200 | [diff] [blame] | 1440 | if (!i && !type->der->type.der) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1441 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", "(union) type"); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1442 | goto error; |
| 1443 | } |
| 1444 | |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1445 | /* inherit instid presence information */ |
| 1446 | if ((type->der->type.base == LY_TYPE_UNION) && type->der->type.info.uni.has_ptr_type) { |
| 1447 | type->info.uni.has_ptr_type = 1; |
| 1448 | } |
| 1449 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1450 | /* allocate array for union's types ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1451 | type->info.uni.types = calloc(i, sizeof *type->info.uni.types); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1452 | if (!type->info.uni.types) { |
| 1453 | LOGMEM; |
| 1454 | goto error; |
| 1455 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1456 | /* ... and fill the structures */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1457 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 1458 | type->info.uni.types[type->info.uni.count].parent = type->parent; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1459 | rc = fill_yin_type(module, parent, node, &type->info.uni.types[type->info.uni.count], parenttype, unres); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1460 | if (!rc) { |
| 1461 | type->info.uni.count++; |
| 1462 | |
Radek Krejci | 7de36cf | 2016-09-12 16:18:50 +0200 | [diff] [blame] | 1463 | if (module->version < 2) { |
| 1464 | /* union's type cannot be empty or leafref */ |
| 1465 | if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_EMPTY) { |
| 1466 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "empty", node->name); |
| 1467 | rc = -1; |
| 1468 | } else if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_LEAFREF) { |
| 1469 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "leafref", node->name); |
| 1470 | rc = -1; |
| 1471 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1472 | } |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1473 | |
| 1474 | if ((type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_INST) |
| 1475 | || (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_LEAFREF)) { |
| 1476 | type->info.uni.has_ptr_type = 1; |
| 1477 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1478 | } |
| 1479 | if (rc) { |
| 1480 | /* even if we got EXIT_FAILURE, throw it all away, too much trouble doing something else */ |
| 1481 | for (i = 0; i < type->info.uni.count; ++i) { |
| 1482 | lys_type_free(module->ctx, &type->info.uni.types[i]); |
| 1483 | } |
| 1484 | free(type->info.uni.types); |
| 1485 | type->info.uni.types = NULL; |
| 1486 | type->info.uni.count = 0; |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1487 | type->info.uni.has_ptr_type = 0; |
Michal Vasko | eac0818 | 2016-07-21 12:16:32 +0200 | [diff] [blame] | 1488 | type->der = NULL; |
| 1489 | type->base = LY_TYPE_DER; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1490 | |
| 1491 | if (rc == EXIT_FAILURE) { |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 1492 | ret = EXIT_FAILURE; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1493 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1494 | goto error; |
| 1495 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1496 | } |
| 1497 | break; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1498 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1499 | case LY_TYPE_BOOL: |
| 1500 | case LY_TYPE_EMPTY: |
| 1501 | /* no sub-statement allowed */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1502 | if (yin->child) { |
| 1503 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, yin->child->name); |
| 1504 | goto error; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1505 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1506 | break; |
| 1507 | |
| 1508 | default: |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1509 | LOGINT; |
| 1510 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | return EXIT_SUCCESS; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 1514 | |
| 1515 | error: |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 1516 | if (type->module_name) { |
| 1517 | lydict_remove(module->ctx, type->module_name); |
| 1518 | type->module_name = NULL; |
| 1519 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1520 | lyxml_free_withsiblings(module->ctx, exts.child); |
| 1521 | |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 1522 | return ret; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1523 | } |
| 1524 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1525 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1526 | static int |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1527 | fill_yin_typedef(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_tpdf *tpdf, |
| 1528 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1529 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1530 | const char *value; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1531 | struct lyxml_elem *node, *next; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1532 | int rc, has_type = 0, c_ext = 0; |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1533 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1534 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1535 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1536 | if (lyp_check_identifier(value, LY_IDENT_TYPE, module, parent)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1537 | goto error; |
| 1538 | } |
| 1539 | tpdf->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1540 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1541 | /* generic part - status, description, reference */ |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1542 | if (read_yin_common(module, NULL, tpdf, LYEXT_PAR_TPDF, yin, OPT_MODULE, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1543 | goto error; |
| 1544 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1545 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1546 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1547 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 1548 | /* extension */ |
| 1549 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1550 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1551 | } else if (!strcmp(node->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 1552 | if (has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1553 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1554 | goto error; |
| 1555 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1556 | /* HACK for unres */ |
| 1557 | tpdf->type.der = (struct lys_tpdf *)node; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 1558 | tpdf->type.parent = tpdf; |
Michal Vasko | 5d63140 | 2016-07-21 13:15:15 +0200 | [diff] [blame] | 1559 | if (unres_schema_add_node(module, unres, &tpdf->type, UNRES_TYPE_DER_TPDF, parent) == -1) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1560 | goto error; |
| 1561 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1562 | has_type = 1; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1563 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1564 | /* skip lyxml_free() at the end of the loop, node was freed or at least unlinked in unres processing */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1565 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1566 | } else if (!strcmp(node->name, "default")) { |
| 1567 | if (tpdf->dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1568 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1569 | goto error; |
| 1570 | } |
| 1571 | GETVAL(value, node, "value"); |
| 1572 | tpdf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1573 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1574 | if (lyp_yin_parse_subnode_ext(module, tpdf, LYEXT_PAR_TPDF, node, LYEXT_SUBSTMT_DEFAULT, 0, unres)) { |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1575 | goto error; |
| 1576 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1577 | } else if (!strcmp(node->name, "units")) { |
| 1578 | if (tpdf->units) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1579 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1580 | goto error; |
| 1581 | } |
| 1582 | GETVAL(value, node, "name"); |
| 1583 | tpdf->units = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1584 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1585 | if (lyp_yin_parse_subnode_ext(module, tpdf, LYEXT_PAR_TPDF, node, LYEXT_SUBSTMT_UNITS, 0, unres)) { |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1586 | goto error; |
| 1587 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1588 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1589 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1590 | goto error; |
| 1591 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1592 | |
| 1593 | lyxml_free(module->ctx, node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1594 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 1595 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1596 | /* check mandatory value */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1597 | if (!has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1598 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1599 | goto error; |
| 1600 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1601 | |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 1602 | /* check default value (if not defined, there still could be some restrictions |
| 1603 | * that need to be checked against a default value from a derived type) */ |
Radek Krejci | ab08f0f | 2017-03-09 16:37:15 +0100 | [diff] [blame] | 1604 | if (unres_schema_add_node(module, unres, &tpdf->type, UNRES_TYPEDEF_DFLT, (struct lys_node *)(&tpdf->dflt)) == -1) { |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 1605 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1606 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1607 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1608 | /* finish extensions parsing */ |
| 1609 | if (c_ext) { |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1610 | /* some extensions may be already present from the substatements */ |
| 1611 | reallocated = realloc(tpdf->ext, (c_ext + tpdf->ext_size) * sizeof *tpdf->ext); |
| 1612 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1613 | LOGMEM; |
| 1614 | goto error; |
| 1615 | } |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1616 | tpdf->ext = reallocated; |
| 1617 | |
| 1618 | /* init memory */ |
| 1619 | memset(&tpdf->ext[tpdf->ext_size], 0, c_ext * sizeof *tpdf->ext); |
| 1620 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1621 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 1622 | rc = lyp_yin_fill_ext(tpdf, LYEXT_PAR_TYPE, 0, 0, module, node, &tpdf->ext, tpdf->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1623 | tpdf->ext_size++; |
| 1624 | if (rc) { |
| 1625 | goto error; |
| 1626 | } |
| 1627 | } |
| 1628 | } |
| 1629 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1630 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1631 | |
| 1632 | error: |
| 1633 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1634 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1635 | } |
| 1636 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1637 | static int |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1638 | fill_yin_extension(struct lys_module *module, struct lyxml_elem *yin, struct lys_ext *ext, struct unres_schema *unres) |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1639 | { |
| 1640 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1641 | struct lyxml_elem *child, *node, *next, *next2; |
| 1642 | int c_ext = 0, rc; |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1643 | void *reallocated; |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1644 | |
| 1645 | GETVAL(value, yin, "name"); |
| 1646 | |
| 1647 | if (lyp_check_identifier(value, LY_IDENT_EXTENSION, module, NULL)) { |
| 1648 | goto error; |
| 1649 | } |
| 1650 | ext->name = lydict_insert(module->ctx, value, strlen(value)); |
| 1651 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1652 | if (read_yin_common(module, NULL, ext, LYEXT_PAR_EXT, yin, OPT_MODULE, unres)) { |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1653 | goto error; |
| 1654 | } |
| 1655 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1656 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 1657 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 1658 | /* possible extension instance */ |
| 1659 | c_ext++; |
| 1660 | } else if (!strcmp(node->name, "argument")) { |
| 1661 | /* argument */ |
| 1662 | GETVAL(value, node, "name"); |
| 1663 | ext->argument = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1664 | if (lyp_yin_parse_subnode_ext(module, ext, LYEXT_PAR_EXT, node, LYEXT_SUBSTMT_ARGUMENT, 0, unres)) { |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1665 | goto error; |
| 1666 | } |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1667 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1668 | /* yin-element */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1669 | LY_TREE_FOR_SAFE(node->child, next2, child) { |
| 1670 | if (child->ns == node->ns && !strcmp(child->name, "yin-element")) { |
| 1671 | GETVAL(value, child, "value"); |
| 1672 | if (ly_strequal(value, "true", 0)) { |
| 1673 | ext->flags |= LYS_YINELEM; |
| 1674 | } |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1675 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1676 | if (lyp_yin_parse_subnode_ext(module, ext, LYEXT_PAR_EXT, child, LYEXT_SUBSTMT_YINELEM, 0, unres)) { |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1677 | goto error; |
| 1678 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1679 | } else if (child->ns) { |
| 1680 | /* unexpected YANG statement */ |
| 1681 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->name); |
| 1682 | goto error; |
| 1683 | } /* else garbage, but save resource needed for unlinking */ |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1684 | } |
| 1685 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1686 | lyxml_free(module->ctx, node); |
| 1687 | } else { |
| 1688 | /* unexpected YANG statement */ |
| 1689 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->name); |
| 1690 | goto error; |
| 1691 | } |
| 1692 | } |
| 1693 | |
| 1694 | if (c_ext) { |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1695 | /* some extensions may be already present from the substatements */ |
| 1696 | reallocated = realloc(ext->ext, (c_ext + ext->ext_size) * sizeof *ext->ext); |
| 1697 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1698 | LOGMEM; |
| 1699 | goto error; |
| 1700 | } |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1701 | ext->ext = reallocated; |
| 1702 | |
| 1703 | /* init memory */ |
| 1704 | memset(&ext->ext[ext->ext_size], 0, c_ext * sizeof *ext->ext); |
| 1705 | |
| 1706 | /* process the extension instances of the extension itself */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1707 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 1708 | rc = lyp_yin_fill_ext(ext, LYEXT_PAR_EXT, 0, 0, module, node, &ext->ext, ext->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1709 | ext->ext_size++; |
| 1710 | if (rc) { |
| 1711 | goto error; |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1712 | } |
| 1713 | } |
| 1714 | } |
| 1715 | |
Radek Krejci | 0a498f8 | 2017-01-04 16:24:15 +0100 | [diff] [blame] | 1716 | /* search for plugin */ |
| 1717 | ext->plugin = ext_get_plugin(ext->name, ext->module->name, ext->module->rev ? ext->module->rev[0].date : NULL); |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1718 | |
| 1719 | return EXIT_SUCCESS; |
| 1720 | |
| 1721 | error: |
| 1722 | return EXIT_FAILURE; |
| 1723 | } |
| 1724 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1725 | /* logs directly */ |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1726 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 1727 | fill_yin_feature(struct lys_module *module, struct lyxml_elem *yin, struct lys_feature *f, struct unres_schema *unres) |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1728 | { |
| 1729 | const char *value; |
| 1730 | struct lyxml_elem *child, *next; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1731 | int c_ftrs = 0, c_ext = 0, ret; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 1732 | void *reallocated; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1733 | |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1734 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1735 | if (lyp_check_identifier(value, LY_IDENT_FEATURE, module, NULL)) { |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1736 | goto error; |
| 1737 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1738 | f->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 1739 | f->module = module; |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1740 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1741 | if (read_yin_common(module, NULL, f, LYEXT_PAR_FEATURE, yin, 0, unres)) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1742 | goto error; |
| 1743 | } |
| 1744 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1745 | LY_TREE_FOR(yin->child, child) { |
| 1746 | if (strcmp(child->ns->value, LY_NSYIN)) { |
| 1747 | /* extension */ |
| 1748 | c_ext++; |
| 1749 | } else if (!strcmp(child->name, "if-feature")) { |
| 1750 | c_ftrs++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1751 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1752 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1753 | goto error; |
| 1754 | } |
| 1755 | } |
| 1756 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1757 | if (c_ftrs) { |
| 1758 | f->iffeature = calloc(c_ftrs, sizeof *f->iffeature); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 1759 | if (!f->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1760 | LOGMEM; |
| 1761 | goto error; |
| 1762 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1763 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1764 | if (c_ext) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 1765 | /* some extensions may be already present from the substatements */ |
| 1766 | reallocated = realloc(f->ext, (c_ext + f->ext_size) * sizeof *f->ext); |
| 1767 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1768 | LOGMEM; |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1769 | goto error; |
| 1770 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 1771 | f->ext = reallocated; |
| 1772 | |
| 1773 | /* init memory */ |
| 1774 | memset(&f->ext[f->ext_size], 0, c_ext * sizeof *f->ext); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1775 | } |
| 1776 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1777 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 1778 | if (strcmp(child->ns->value, LY_NSYIN)) { |
| 1779 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 1780 | ret = lyp_yin_fill_ext(f, LYEXT_PAR_FEATURE, 0, 0, module, child, &f->ext, f->ext_size, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1781 | f->ext_size++; |
| 1782 | if (ret) { |
| 1783 | goto error; |
| 1784 | } |
| 1785 | } else { /* if-feature */ |
| 1786 | ret = fill_yin_iffeature((struct lys_node *)f, 1, child, &f->iffeature[f->iffeature_size], unres); |
| 1787 | f->iffeature_size++; |
| 1788 | if (ret) { |
| 1789 | goto error; |
| 1790 | } |
| 1791 | } |
| 1792 | } |
| 1793 | |
Radek Krejci | c79c6b1 | 2016-07-26 15:11:49 +0200 | [diff] [blame] | 1794 | /* check for circular dependencies */ |
| 1795 | if (f->iffeature_size) { |
| 1796 | if (unres_schema_add_node(module, unres, f, UNRES_FEATURE, NULL) == -1) { |
| 1797 | goto error; |
| 1798 | } |
| 1799 | } |
| 1800 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1801 | return EXIT_SUCCESS; |
| 1802 | |
| 1803 | error: |
| 1804 | |
| 1805 | return EXIT_FAILURE; |
| 1806 | } |
| 1807 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1808 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1809 | static int |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1810 | fill_yin_must(struct lys_module *module, struct lyxml_elem *yin, struct lys_restr *must, struct unres_schema *unres) |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1811 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1812 | const char *value; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1813 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1814 | GETVAL(value, yin, "condition"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1815 | must->expr = transform_schema2json(module, value); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 1816 | if (!must->expr) { |
| 1817 | goto error; |
| 1818 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1819 | |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 1820 | return read_restr_substmt(module, must, yin, unres); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1821 | |
Michal Vasko | 77dc565 | 2016-02-15 12:32:42 +0100 | [diff] [blame] | 1822 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1823 | return EXIT_FAILURE; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1824 | } |
| 1825 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1826 | static int |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 1827 | fill_yin_revision(struct lys_module *module, struct lyxml_elem *yin, struct lys_revision *rev, |
| 1828 | struct unres_schema *unres) |
| 1829 | { |
| 1830 | struct lyxml_elem *next, *child; |
| 1831 | const char *value; |
| 1832 | |
| 1833 | GETVAL(value, yin, "date"); |
| 1834 | if (lyp_check_date(value)) { |
| 1835 | goto error; |
| 1836 | } |
| 1837 | memcpy(rev->date, value, LY_REV_SIZE - 1); |
| 1838 | |
| 1839 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 1840 | if (!child->ns) { |
| 1841 | /* garbage */ |
| 1842 | continue; |
| 1843 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 1844 | /* possible extension instance */ |
| 1845 | if (lyp_yin_parse_subnode_ext(module, rev, LYEXT_PAR_REVISION, |
| 1846 | child, LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 1847 | goto error; |
| 1848 | } |
| 1849 | } else if (!strcmp(child->name, "description")) { |
| 1850 | if (rev->dsc) { |
| 1851 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 1852 | goto error; |
| 1853 | } |
| 1854 | if (lyp_yin_parse_subnode_ext(module, rev, LYEXT_PAR_REVISION, |
| 1855 | child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
| 1856 | goto error; |
| 1857 | } |
| 1858 | rev->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 1859 | if (!rev->dsc) { |
| 1860 | goto error; |
| 1861 | } |
| 1862 | } else if (!strcmp(child->name, "reference")) { |
| 1863 | if (rev->ref) { |
| 1864 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 1865 | goto error; |
| 1866 | } |
| 1867 | if (lyp_yin_parse_subnode_ext(module, rev, LYEXT_PAR_REVISION, |
| 1868 | child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
| 1869 | goto error; |
| 1870 | } |
| 1871 | rev->ref = read_yin_subnode(module->ctx, child, "text"); |
| 1872 | if (!rev->ref) { |
| 1873 | goto error; |
| 1874 | } |
| 1875 | } else { |
| 1876 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1877 | goto error; |
| 1878 | } |
| 1879 | } |
| 1880 | |
| 1881 | return EXIT_SUCCESS; |
| 1882 | |
| 1883 | error: |
| 1884 | return EXIT_FAILURE; |
| 1885 | } |
| 1886 | |
| 1887 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1888 | fill_yin_unique(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_unique *unique, |
| 1889 | struct unres_schema *unres) |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1890 | { |
| 1891 | int i, j; |
| 1892 | const char *value, *vaux; |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 1893 | struct unres_list_uniq *unique_info; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1894 | |
| 1895 | /* get unique value (list of leafs supposed to be unique */ |
| 1896 | GETVAL(value, yin, "tag"); |
| 1897 | |
| 1898 | /* count the number of unique leafs in the value */ |
| 1899 | vaux = value; |
| 1900 | while ((vaux = strpbrk(vaux, " \t\n"))) { |
Michal Vasko | 98645db | 2016-03-07 14:38:49 +0100 | [diff] [blame] | 1901 | unique->expr_size++; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1902 | while (isspace(*vaux)) { |
| 1903 | vaux++; |
| 1904 | } |
| 1905 | } |
| 1906 | unique->expr_size++; |
| 1907 | unique->expr = calloc(unique->expr_size, sizeof *unique->expr); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1908 | if (!unique->expr) { |
| 1909 | LOGMEM; |
| 1910 | goto error; |
| 1911 | } |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1912 | |
| 1913 | for (i = 0; i < unique->expr_size; i++) { |
| 1914 | vaux = strpbrk(value, " \t\n"); |
| 1915 | if (!vaux) { |
| 1916 | /* the last token, lydict_insert() will count its size on its own */ |
| 1917 | vaux = value; |
| 1918 | } |
| 1919 | |
| 1920 | /* store token into unique structure */ |
| 1921 | unique->expr[i] = lydict_insert(module->ctx, value, vaux - value); |
| 1922 | |
| 1923 | /* check that the expression does not repeat */ |
| 1924 | for (j = 0; j < i; j++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 1925 | if (ly_strequal(unique->expr[j], unique->expr[i], 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1926 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, unique->expr[i], "unique"); |
| 1927 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "The identifier is not unique"); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1928 | goto error; |
| 1929 | } |
| 1930 | } |
| 1931 | |
| 1932 | /* try to resolve leaf */ |
| 1933 | if (unres) { |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 1934 | unique_info = malloc(sizeof *unique_info); |
| 1935 | unique_info->list = parent; |
| 1936 | unique_info->expr = unique->expr[i]; |
| 1937 | unique_info->trg_type = &unique->trg_type; |
| 1938 | 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] | 1939 | goto error; |
| 1940 | } |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1941 | } else { |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 1942 | if (resolve_unique(parent, unique->expr[i], &unique->trg_type)) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1943 | goto error; |
| 1944 | } |
| 1945 | } |
| 1946 | |
| 1947 | /* move to next token */ |
| 1948 | value = vaux; |
| 1949 | while(isspace(*value)) { |
| 1950 | value++; |
| 1951 | } |
| 1952 | } |
| 1953 | |
| 1954 | return EXIT_SUCCESS; |
| 1955 | |
| 1956 | error: |
| 1957 | return EXIT_FAILURE; |
| 1958 | } |
| 1959 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1960 | /* logs directly |
| 1961 | * |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1962 | * type: 0 - min, 1 - max |
| 1963 | */ |
| 1964 | static int |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1965 | 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] | 1966 | { |
| 1967 | const char *value; |
| 1968 | char *endptr; |
| 1969 | unsigned long val; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1970 | uint32_t *ui32val, *min, *max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1971 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1972 | /* del min/max is forbidden */ |
| 1973 | if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1974 | 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] | 1975 | goto error; |
| 1976 | } |
| 1977 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1978 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1979 | if (target->nodetype == LYS_LEAFLIST) { |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1980 | max = &((struct lys_node_leaflist *)target)->max; |
| 1981 | min = &((struct lys_node_leaflist *)target)->min; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1982 | } else if (target->nodetype == LYS_LIST) { |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1983 | max = &((struct lys_node_list *)target)->max; |
| 1984 | min = &((struct lys_node_list *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1985 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1986 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
| 1987 | 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] | 1988 | goto error; |
| 1989 | } |
| 1990 | |
| 1991 | GETVAL(value, node, "value"); |
| 1992 | while (isspace(value[0])) { |
| 1993 | value++; |
| 1994 | } |
| 1995 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1996 | if (type && !strcmp(value, "unbounded")) { |
| 1997 | d->max = val = 0; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 1998 | d->max_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1999 | ui32val = max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2000 | } else { |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2001 | /* convert it to uint32_t */ |
| 2002 | errno = 0; |
| 2003 | endptr = NULL; |
| 2004 | val = strtoul(value, &endptr, 10); |
| 2005 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2006 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2007 | goto error; |
| 2008 | } |
| 2009 | if (type) { |
| 2010 | d->max = (uint32_t)val; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 2011 | d->max_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2012 | ui32val = max; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2013 | } else { |
| 2014 | d->min = (uint32_t)val; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 2015 | d->min_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2016 | ui32val = min; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2017 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2018 | } |
| 2019 | |
| 2020 | if (d->mod == LY_DEVIATE_ADD) { |
| 2021 | /* check that there is no current value */ |
| 2022 | if (*ui32val) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2023 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
| 2024 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2025 | goto error; |
| 2026 | } |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2027 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2028 | /* unfortunately, there is no way to check reliably that there |
| 2029 | * was a value before, it could have been the default */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2030 | } |
| 2031 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2032 | /* add (already checked) and replace */ |
| 2033 | /* set new value specified in deviation */ |
| 2034 | *ui32val = (uint32_t)val; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2035 | |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2036 | /* check min-elements is smaller than max-elements */ |
| 2037 | if (*max && *min > *max) { |
| 2038 | if (type) { |
Radek Krejci | 73f9601 | 2016-10-03 13:53:53 +0200 | [diff] [blame] | 2039 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "max-elements"); |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2040 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"max-elements\" is smaller than \"min-elements\"."); |
| 2041 | } else { |
Radek Krejci | 73f9601 | 2016-10-03 13:53:53 +0200 | [diff] [blame] | 2042 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "min-elements"); |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2043 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"min-elements\" is bigger than \"max-elements\"."); |
| 2044 | } |
| 2045 | goto error; |
| 2046 | } |
| 2047 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2048 | return EXIT_SUCCESS; |
| 2049 | |
| 2050 | error: |
| 2051 | |
| 2052 | return EXIT_FAILURE; |
| 2053 | } |
| 2054 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2055 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2056 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 2057 | fill_yin_deviation(struct lys_module *module, struct lyxml_elem *yin, struct lys_deviation *dev, |
| 2058 | struct unres_schema *unres) |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2059 | { |
| 2060 | const char *value, **stritem; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2061 | struct lyxml_elem *next, *next2, *child, *develem; |
| 2062 | 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] | 2063 | int f_min = 0, f_max = 0; /* flags */ |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2064 | int i, j, k, rc; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2065 | unsigned int u; |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2066 | struct ly_ctx *ctx; |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 2067 | struct lys_deviate *d = NULL; |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2068 | struct lys_node *node = NULL, *parent, *dev_target = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2069 | struct lys_node_choice *choice = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2070 | struct lys_node_leaf *leaf = NULL; |
| 2071 | struct ly_set *dflt_check = ly_set_new(); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2072 | struct lys_node_list *list = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2073 | struct lys_node_leaflist *llist = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2074 | struct lys_type *t = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2075 | uint8_t *trg_must_size = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2076 | struct lys_restr **trg_must = NULL; |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2077 | struct unres_schema tmp_unres; |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 2078 | struct lys_module *mod; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2079 | void *reallocated; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2080 | |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2081 | ctx = module->ctx; |
| 2082 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2083 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2084 | dev->target_name = transform_schema2json(module, value); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 2085 | if (!dev->target_name) { |
| 2086 | goto error; |
| 2087 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2088 | |
| 2089 | /* resolve target node */ |
Radek Krejci | df46e22 | 2016-11-08 11:57:37 +0100 | [diff] [blame] | 2090 | 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] | 2091 | if (rc || !dev_target) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2092 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2093 | goto error; |
| 2094 | } |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 2095 | if (dev_target->module == lys_main_module(module)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2096 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, yin->name); |
| 2097 | 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] | 2098 | goto error; |
| 2099 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2100 | |
| 2101 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2102 | if (!child->ns ) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2103 | /* garbage */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2104 | lyxml_free(ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2105 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2106 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 2107 | /* extension */ |
| 2108 | c_ext++; |
| 2109 | continue; |
| 2110 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2111 | if (dev->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2112 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2113 | goto error; |
| 2114 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2115 | if (lyp_yin_parse_subnode_ext(module, dev, LYEXT_PAR_DEVIATION, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2116 | goto error; |
| 2117 | } |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2118 | dev->dsc = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2119 | if (!dev->dsc) { |
| 2120 | goto error; |
| 2121 | } |
| 2122 | } else if (!strcmp(child->name, "reference")) { |
| 2123 | if (dev->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2124 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2125 | goto error; |
| 2126 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2127 | if (lyp_yin_parse_subnode_ext(module, dev, LYEXT_PAR_DEVIATION, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2128 | goto error; |
| 2129 | } |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2130 | dev->ref = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2131 | if (!dev->ref) { |
| 2132 | goto error; |
| 2133 | } |
| 2134 | } else if (!strcmp(child->name, "deviate")) { |
| 2135 | c_dev++; |
| 2136 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2137 | /* skip lyxml_free() at the end of the loop, node will be |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2138 | * further processed later |
| 2139 | */ |
| 2140 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 2141 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2142 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2143 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2144 | goto error; |
| 2145 | } |
| 2146 | |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2147 | lyxml_free(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2148 | } |
| 2149 | |
| 2150 | if (c_dev) { |
| 2151 | dev->deviate = calloc(c_dev, sizeof *dev->deviate); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2152 | if (!dev->deviate) { |
| 2153 | LOGMEM; |
| 2154 | goto error; |
| 2155 | } |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2156 | } else { |
| 2157 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "deviate", "deviation"); |
| 2158 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2159 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2160 | if (c_ext) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2161 | /* some extensions may be already present from the substatements */ |
| 2162 | reallocated = realloc(dev->ext, (c_ext + dev->ext_size) * sizeof *dev->ext); |
| 2163 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2164 | LOGMEM; |
| 2165 | goto error; |
| 2166 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2167 | dev->ext = reallocated; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2168 | |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2169 | /* init memory */ |
| 2170 | memset(&dev->ext[dev->ext_size], 0, c_ext * sizeof *dev->ext); |
| 2171 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2172 | |
| 2173 | LY_TREE_FOR_SAFE(yin->child, next, develem) { |
| 2174 | if (strcmp(develem->ns->value, LY_NSYIN)) { |
| 2175 | /* deviation's extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 2176 | 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] | 2177 | dev->ext_size++; |
| 2178 | if (rc) { |
| 2179 | goto error; |
| 2180 | } |
| 2181 | continue; |
| 2182 | } |
| 2183 | |
| 2184 | /* deviate */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2185 | /* init */ |
| 2186 | f_min = 0; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2187 | f_max = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2188 | c_must = 0; |
| 2189 | c_uniq = 0; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2190 | c_dflt = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2191 | c_ext = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2192 | |
| 2193 | /* get deviation type */ |
| 2194 | GETVAL(value, develem, "value"); |
| 2195 | if (!strcmp(value, "not-supported")) { |
| 2196 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_NO; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2197 | /* no other deviate statement is expected, |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 2198 | * not-supported deviation must be the only deviation of the target |
| 2199 | */ |
| 2200 | if (dev->deviate_size || develem->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2201 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
| 2202 | 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] | 2203 | goto error; |
| 2204 | } |
| 2205 | |
Michal Vasko | ad1f7b7 | 2016-02-17 11:13:58 +0100 | [diff] [blame] | 2206 | /* you cannot remove a key leaf */ |
Michal Vasko | 43c9477 | 2016-05-03 11:47:44 +0200 | [diff] [blame] | 2207 | if ((dev_target->nodetype == LYS_LEAF) && lys_parent(dev_target) && (lys_parent(dev_target)->nodetype == LYS_LIST)) { |
| 2208 | for (i = 0; i < ((struct lys_node_list *)lys_parent(dev_target))->keys_size; ++i) { |
| 2209 | 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] | 2210 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
| 2211 | 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] | 2212 | goto error; |
| 2213 | } |
| 2214 | } |
| 2215 | } |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 2216 | |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2217 | /* unlink and store the original node */ |
Radek Krejci | 30bfcd2 | 2017-01-27 16:54:48 +0100 | [diff] [blame] | 2218 | parent = dev_target->parent; |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2219 | lys_node_unlink(dev_target); |
Radek Krejci | 30bfcd2 | 2017-01-27 16:54:48 +0100 | [diff] [blame] | 2220 | if (parent && parent->nodetype == LYS_AUGMENT) { |
| 2221 | /* hack for augment, because when the original will be sometime reconnected back, we actually need |
| 2222 | * to reconnect it to both - the augment and its target (which is deduced from the deviations target |
| 2223 | * path), so we need to remember the augment as an addition */ |
| 2224 | dev_target->parent = parent; |
| 2225 | } |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2226 | dev->orig_node = dev_target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2227 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2228 | } else if (!strcmp(value, "add")) { |
| 2229 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_ADD; |
| 2230 | } else if (!strcmp(value, "replace")) { |
| 2231 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_RPL; |
| 2232 | } else if (!strcmp(value, "delete")) { |
| 2233 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_DEL; |
| 2234 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2235 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2236 | goto error; |
| 2237 | } |
| 2238 | d = &dev->deviate[dev->deviate_size]; |
Michal Vasko | 0f7d7ee | 2016-03-08 09:20:25 +0100 | [diff] [blame] | 2239 | dev->deviate_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2240 | |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2241 | /* store a shallow copy of the original node */ |
| 2242 | if (!dev->orig_node) { |
| 2243 | memset(&tmp_unres, 0, sizeof tmp_unres); |
Radek Krejci | 6ff885d | 2017-01-03 14:06:22 +0100 | [diff] [blame] | 2244 | 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] | 2245 | /* just to be safe */ |
| 2246 | if (tmp_unres.count) { |
| 2247 | LOGINT; |
| 2248 | goto error; |
| 2249 | } |
| 2250 | } |
| 2251 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2252 | /* process deviation properties */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2253 | LY_TREE_FOR_SAFE(develem->child, next2, child) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2254 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2255 | /* garbage */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2256 | lyxml_free(ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2257 | continue; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2258 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 2259 | /* extensions */ |
| 2260 | c_ext++; |
| 2261 | } else if (d->mod == LY_DEVIATE_NO) { |
| 2262 | /* no YIN substatement expected in this case */ |
| 2263 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2264 | goto error; |
| 2265 | } else if (!strcmp(child->name, "config")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2266 | if (d->flags & LYS_CONFIG_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2267 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2268 | goto error; |
| 2269 | } |
| 2270 | |
| 2271 | /* for we deviate from RFC 6020 and allow config property even it is/is not |
| 2272 | * specified in the target explicitly since config property inherits. So we expect |
| 2273 | * that config is specified in every node. But for delete, we check that the value |
| 2274 | * is the same as here in deviation |
| 2275 | */ |
| 2276 | GETVAL(value, child, "value"); |
| 2277 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2278 | d->flags |= LYS_CONFIG_R; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2279 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2280 | d->flags |= LYS_CONFIG_W; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2281 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2282 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2283 | goto error; |
| 2284 | } |
| 2285 | |
| 2286 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2287 | /* del config is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2288 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "config", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2289 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2290 | } else { /* add and replace are the same in this case */ |
| 2291 | /* remove current config value of the target ... */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2292 | dev_target->flags &= ~LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2293 | |
| 2294 | /* ... and replace it with the value specified in deviation */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2295 | dev_target->flags |= d->flags & LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2296 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2297 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2298 | if (lyp_yin_parse_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_CONFIG, 0, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2299 | goto error; |
| 2300 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2301 | } else if (!strcmp(child->name, "default")) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2302 | if (lyp_yin_parse_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_DEFAULT, c_dflt, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2303 | goto error; |
| 2304 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2305 | c_dflt++; |
| 2306 | |
| 2307 | /* check target node type */ |
| 2308 | if (module->version < 2 && dev_target->nodetype == LYS_LEAFLIST) { |
| 2309 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2310 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"default\" property."); |
| 2311 | goto error; |
| 2312 | } else if (c_dflt > 1 && dev_target->nodetype != LYS_LEAFLIST) { /* from YANG 1.1 */ |
| 2313 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2314 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow multiple \"default\" properties."); |
| 2315 | goto error; |
| 2316 | } else if (c_dflt == 1 && (!(dev_target->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_CHOICE)))) { |
| 2317 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2318 | 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] | 2319 | goto error; |
| 2320 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2321 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2322 | /* skip lyxml_free() at the end of the loop, this node will be processed later */ |
| 2323 | continue; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2324 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2325 | } else if (!strcmp(child->name, "mandatory")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2326 | if (d->flags & LYS_MAND_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2327 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2328 | goto error; |
| 2329 | } |
| 2330 | |
| 2331 | /* check target node type */ |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2332 | if (!(dev_target->nodetype & (LYS_LEAF | LYS_CHOICE | LYS_ANYDATA))) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2333 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2334 | 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] | 2335 | goto error; |
| 2336 | } |
| 2337 | |
| 2338 | GETVAL(value, child, "value"); |
| 2339 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2340 | d->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2341 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2342 | d->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2343 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2344 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2345 | goto error; |
| 2346 | } |
| 2347 | |
| 2348 | if (d->mod == LY_DEVIATE_ADD) { |
| 2349 | /* check that there is no current value */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2350 | if (dev_target->flags & LYS_MAND_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2351 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2352 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2353 | goto error; |
| 2354 | } |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2355 | |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 2356 | /* check collision with default-stmt */ |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2357 | if (d->flags & LYS_MAND_TRUE) { |
| 2358 | if (dev_target->nodetype == LYS_CHOICE) { |
| 2359 | if (((struct lys_node_choice *)(dev_target))->dflt) { |
| 2360 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 2361 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2362 | "Adding the \"mandatory\" statement is forbidden on choice with the \"default\" statement."); |
| 2363 | goto error; |
| 2364 | } |
| 2365 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 2366 | if (((struct lys_node_leaf *)(dev_target))->dflt) { |
| 2367 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 2368 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2369 | "Adding the \"mandatory\" statement is forbidden on leaf with the \"default\" statement."); |
| 2370 | goto error; |
| 2371 | } |
| 2372 | } |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 2373 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2374 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2375 | dev_target->flags |= d->flags & LYS_MAND_MASK; |
| 2376 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2377 | /* check that there was a value before */ |
| 2378 | if (!(dev_target->flags & LYS_MAND_MASK)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2379 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2380 | 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] | 2381 | goto error; |
| 2382 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2383 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2384 | dev_target->flags &= ~LYS_MAND_MASK; |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2385 | dev_target->flags |= d->flags & LYS_MAND_MASK; |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2386 | } else if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2387 | /* del mandatory is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2388 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "mandatory", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2389 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2390 | } |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2391 | |
| 2392 | /* check for mandatory node in default case, first find the closest parent choice to the changed node */ |
| 2393 | for (parent = dev_target->parent; |
| 2394 | parent && !(parent->nodetype & (LYS_CHOICE | LYS_GROUPING | LYS_ACTION)); |
| 2395 | parent = parent->parent) { |
| 2396 | if (parent->nodetype == LYS_CONTAINER && ((struct lys_node_container *)parent)->presence) { |
| 2397 | /* stop also on presence containers */ |
| 2398 | break; |
| 2399 | } |
| 2400 | } |
| 2401 | /* and if it is a choice with the default case, check it for presence of a mandatory node in it */ |
| 2402 | if (parent && parent->nodetype == LYS_CHOICE && ((struct lys_node_choice *)parent)->dflt) { |
| 2403 | if (lyp_check_mandatory_choice(parent)) { |
| 2404 | goto error; |
| 2405 | } |
| 2406 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2407 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2408 | if (lyp_yin_parse_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_MANDATORY, 0, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2409 | goto error; |
| 2410 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2411 | } else if (!strcmp(child->name, "min-elements")) { |
| 2412 | if (f_min) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2413 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2414 | goto error; |
| 2415 | } |
| 2416 | f_min = 1; |
| 2417 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2418 | if (deviate_minmax(dev_target, child, d, 0)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2419 | goto error; |
| 2420 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2421 | if (lyp_yin_parse_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_MIN, 0, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2422 | goto error; |
| 2423 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2424 | } else if (!strcmp(child->name, "max-elements")) { |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2425 | if (f_max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2426 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2427 | goto error; |
| 2428 | } |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2429 | f_max = 1; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2430 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2431 | if (deviate_minmax(dev_target, child, d, 1)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2432 | goto error; |
| 2433 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2434 | if (lyp_yin_parse_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_MAX, 0, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2435 | goto error; |
| 2436 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2437 | } else if (!strcmp(child->name, "must")) { |
| 2438 | c_must++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2439 | /* 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] | 2440 | continue; |
| 2441 | } else if (!strcmp(child->name, "type")) { |
| 2442 | if (d->type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2443 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2444 | goto error; |
| 2445 | } |
| 2446 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2447 | /* add, del type is forbidden */ |
| 2448 | if (d->mod == LY_DEVIATE_ADD) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2449 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "deviate add"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2450 | goto error; |
| 2451 | } else if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2452 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2453 | goto error; |
| 2454 | } |
| 2455 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2456 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2457 | if (dev_target->nodetype == LYS_LEAF) { |
| 2458 | t = &((struct lys_node_leaf *)dev_target)->type; |
Pavol Vican | 2e32282 | 2016-09-07 15:48:13 +0200 | [diff] [blame] | 2459 | if (((struct lys_node_leaf *)dev_target)->dflt) { |
| 2460 | ly_set_add(dflt_check, dev_target, 0); |
| 2461 | } |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2462 | } else if (dev_target->nodetype == LYS_LEAFLIST) { |
| 2463 | t = &((struct lys_node_leaflist *)dev_target)->type; |
Pavol Vican | 2e32282 | 2016-09-07 15:48:13 +0200 | [diff] [blame] | 2464 | if (((struct lys_node_leaflist *)dev_target)->dflt) { |
| 2465 | ly_set_add(dflt_check, dev_target, 0); |
| 2466 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2467 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2468 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2469 | 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] | 2470 | goto error; |
| 2471 | } |
| 2472 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2473 | /* replace */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2474 | lys_type_free(ctx, t); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 2475 | /* HACK for unres */ |
| 2476 | t->der = (struct lys_tpdf *)child; |
Michal Vasko | 3767fb2 | 2016-07-21 12:10:57 +0200 | [diff] [blame] | 2477 | 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] | 2478 | goto error; |
| 2479 | } |
| 2480 | d->type = t; |
| 2481 | } else if (!strcmp(child->name, "unique")) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2482 | if (lyp_yin_parse_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_UNIQUE, c_uniq, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2483 | goto error; |
| 2484 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2485 | c_uniq++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2486 | /* 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] | 2487 | continue; |
| 2488 | } else if (!strcmp(child->name, "units")) { |
| 2489 | if (d->units) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2490 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2491 | goto error; |
| 2492 | } |
| 2493 | |
| 2494 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2495 | if (dev_target->nodetype == LYS_LEAFLIST) { |
| 2496 | stritem = &((struct lys_node_leaflist *)dev_target)->units; |
| 2497 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 2498 | stritem = &((struct lys_node_leaf *)dev_target)->units; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2499 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2500 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2501 | 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] | 2502 | goto error; |
| 2503 | } |
| 2504 | |
| 2505 | /* get units value */ |
| 2506 | GETVAL(value, child, "name"); |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2507 | d->units = lydict_insert(ctx, value, 0); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2508 | |
| 2509 | /* apply to target */ |
| 2510 | if (d->mod == LY_DEVIATE_ADD) { |
| 2511 | /* check that there is no current value */ |
| 2512 | if (*stritem) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2513 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2514 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2515 | goto error; |
| 2516 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2517 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2518 | *stritem = lydict_insert(ctx, value, 0); |
| 2519 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2520 | /* check that there was a value before */ |
| 2521 | if (!*stritem) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2522 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2523 | 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] | 2524 | goto error; |
| 2525 | } |
| 2526 | |
| 2527 | lydict_remove(ctx, *stritem); |
| 2528 | *stritem = lydict_insert(ctx, value, 0); |
| 2529 | } else if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2530 | /* check values */ |
Michal Vasko | b42b697 | 2016-06-06 14:21:30 +0200 | [diff] [blame] | 2531 | if (!ly_strequal(*stritem, d->units, 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2532 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
| 2533 | 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] | 2534 | goto error; |
| 2535 | } |
| 2536 | /* remove current units value of the target */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2537 | lydict_remove(ctx, *stritem); |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2538 | (*stritem) = NULL; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2539 | |
| 2540 | /* remove its extensions */ |
| 2541 | j = -1; |
| 2542 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_UNITS)) != -1) { |
| 2543 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2544 | --j; |
| 2545 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2546 | } |
| 2547 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2548 | if (lyp_yin_parse_subnode_ext(module, d, LYEXT_PAR_DEVIATE, child, LYEXT_SUBSTMT_UNITS, 0, unres)) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2549 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2550 | } |
| 2551 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2552 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2553 | goto error; |
| 2554 | } |
| 2555 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 2556 | /* 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] | 2557 | } |
| 2558 | |
| 2559 | if (c_must) { |
| 2560 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2561 | switch (dev_target->nodetype) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2562 | case LYS_LEAF: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2563 | trg_must = &((struct lys_node_leaf *)dev_target)->must; |
| 2564 | trg_must_size = &((struct lys_node_leaf *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2565 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2566 | case LYS_CONTAINER: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2567 | trg_must = &((struct lys_node_container *)dev_target)->must; |
| 2568 | trg_must_size = &((struct lys_node_container *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2569 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2570 | case LYS_LEAFLIST: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2571 | trg_must = &((struct lys_node_leaflist *)dev_target)->must; |
| 2572 | trg_must_size = &((struct lys_node_leaflist *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2573 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2574 | case LYS_LIST: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2575 | trg_must = &((struct lys_node_list *)dev_target)->must; |
| 2576 | trg_must_size = &((struct lys_node_list *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2577 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2578 | case LYS_ANYXML: |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2579 | case LYS_ANYDATA: |
| 2580 | trg_must = &((struct lys_node_anydata *)dev_target)->must; |
| 2581 | trg_must_size = &((struct lys_node_anydata *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2582 | break; |
| 2583 | default: |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2584 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "must"); |
| 2585 | 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] | 2586 | goto error; |
| 2587 | } |
| 2588 | |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 2589 | dev_target->flags &= ~LYS_XPATH_DEP; |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 2590 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2591 | if (d->mod == LY_DEVIATE_RPL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2592 | /* replace must is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2593 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "must", "deviate replace"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2594 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2595 | } else if (d->mod == LY_DEVIATE_ADD) { |
| 2596 | /* reallocate the must array of the target */ |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2597 | 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] | 2598 | if (!d->must) { |
| 2599 | LOGMEM; |
| 2600 | goto error; |
| 2601 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2602 | *trg_must = d->must; |
Michal Vasko | 979ad5b | 2015-10-23 10:12:55 +0200 | [diff] [blame] | 2603 | d->must = &((*trg_must)[*trg_must_size]); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2604 | d->must_size = c_must; |
| 2605 | } else { /* LY_DEVIATE_DEL */ |
| 2606 | d->must = calloc(c_must, sizeof *d->must); |
| 2607 | } |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2608 | if (!d->must) { |
| 2609 | LOGMEM; |
| 2610 | goto error; |
| 2611 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2612 | } |
| 2613 | if (c_uniq) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2614 | /* replace unique is forbidden */ |
| 2615 | if (d->mod == LY_DEVIATE_RPL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2616 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "unique", "deviate replace"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2617 | goto error; |
| 2618 | } |
| 2619 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2620 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2621 | if (dev_target->nodetype != LYS_LIST) { |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2622 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "unique"); |
| 2623 | 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] | 2624 | goto error; |
| 2625 | } |
| 2626 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2627 | list = (struct lys_node_list *)dev_target; |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2628 | if (d->mod == LY_DEVIATE_ADD) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2629 | /* reallocate the unique array of the target */ |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2630 | 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] | 2631 | list->unique = d->unique; |
| 2632 | d->unique = &list->unique[list->unique_size]; |
| 2633 | d->unique_size = c_uniq; |
| 2634 | } else { /* LY_DEVIATE_DEL */ |
| 2635 | d->unique = calloc(c_uniq, sizeof *d->unique); |
| 2636 | } |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2637 | if (!d->unique) { |
| 2638 | LOGMEM; |
| 2639 | goto error; |
| 2640 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2641 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2642 | if (c_dflt) { |
| 2643 | if (d->mod == LY_DEVIATE_ADD) { |
| 2644 | /* check that there is no current value */ |
| 2645 | if ((dev_target->nodetype == LYS_LEAF && ((struct lys_node_leaf *)dev_target)->dflt) || |
| 2646 | (dev_target->nodetype == LYS_CHOICE && ((struct lys_node_choice *)dev_target)->dflt)) { |
| 2647 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2648 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
| 2649 | goto error; |
| 2650 | } |
| 2651 | |
| 2652 | /* check collision with mandatory/min-elements */ |
| 2653 | if ((dev_target->flags & LYS_MAND_TRUE) || |
| 2654 | (dev_target->nodetype == LYS_LEAFLIST && ((struct lys_node_leaflist *)dev_target)->min)) { |
| 2655 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 2656 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2657 | "Adding the \"default\" statement is forbidden on %s statement.", |
| 2658 | (dev_target->flags & LYS_MAND_TRUE) ? "nodes with the \"mandatory\"" : "leaflists with non-zero \"min-elements\""); |
| 2659 | goto error; |
| 2660 | } |
| 2661 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2662 | /* check that there was a value before */ |
| 2663 | if (((dev_target->nodetype & (LYS_LEAF | LYS_LEAFLIST)) && !((struct lys_node_leaf *)dev_target)->dflt) || |
| 2664 | (dev_target->nodetype == LYS_CHOICE && !((struct lys_node_choice *)dev_target)->dflt)) { |
| 2665 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2666 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Replacing a property that does not exist."); |
| 2667 | goto error; |
| 2668 | } |
| 2669 | } |
| 2670 | |
| 2671 | if (dev_target->nodetype == LYS_LEAFLIST) { |
| 2672 | /* reallocate default list in the target */ |
| 2673 | llist = (struct lys_node_leaflist *)dev_target; |
| 2674 | if (d->mod == LY_DEVIATE_ADD) { |
| 2675 | /* reallocate (enlarge) the unique array of the target */ |
| 2676 | llist->dflt = ly_realloc(llist->dflt, (c_dflt + llist->dflt_size) * sizeof *d->dflt); |
| 2677 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2678 | /* reallocate (replace) the unique array of the target */ |
| 2679 | for (i = 0; i < llist->dflt_size; i++) { |
| 2680 | lydict_remove(llist->module->ctx, llist->dflt[i]); |
| 2681 | } |
| 2682 | llist->dflt = ly_realloc(llist->dflt, c_dflt * sizeof *d->dflt); |
| 2683 | llist->dflt_size = 0; |
| 2684 | } |
| 2685 | } |
| 2686 | d->dflt = calloc(c_dflt, sizeof *d->dflt); |
| 2687 | if (!d->dflt) { |
| 2688 | LOGMEM; |
| 2689 | goto error; |
| 2690 | } |
| 2691 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2692 | if (c_ext) { |
| 2693 | /* some extensions may be already present from the substatements */ |
| 2694 | reallocated = realloc(d->ext, (c_ext + d->ext_size) * sizeof *d->ext); |
| 2695 | if (!reallocated) { |
| 2696 | LOGMEM; |
| 2697 | goto error; |
| 2698 | } |
| 2699 | d->ext = reallocated; |
| 2700 | |
| 2701 | /* init memory */ |
| 2702 | memset(&d->ext[d->ext_size], 0, c_ext * sizeof *d->ext); |
| 2703 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2704 | |
| 2705 | /* process deviation properties with 0..n cardinality */ |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2706 | LY_TREE_FOR_SAFE(develem->child, next2, child) { |
| 2707 | if (strcmp(child->ns->value, LY_NSYIN)) { |
| 2708 | /* extension */ |
| 2709 | if (lyp_yin_fill_ext(d, LYEXT_PAR_DEVIATE, 0, 0, module, child, &d->ext, d->ext_size, unres)) { |
| 2710 | goto error; |
| 2711 | } |
| 2712 | d->ext_size++; |
| 2713 | } else if (!strcmp(child->name, "must")) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2714 | if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 2715 | if (fill_yin_must(module, child, &d->must[d->must_size], unres)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2716 | goto error; |
| 2717 | } |
| 2718 | |
| 2719 | /* find must to delete, we are ok with just matching conditions */ |
| 2720 | for (i = 0; i < *trg_must_size; i++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 2721 | 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] | 2722 | /* we have a match, free the must structure ... */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2723 | lys_restr_free(ctx, &((*trg_must)[i])); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2724 | /* ... and maintain the array */ |
| 2725 | (*trg_must_size)--; |
| 2726 | if (i != *trg_must_size) { |
| 2727 | (*trg_must)[i].expr = (*trg_must)[*trg_must_size].expr; |
| 2728 | (*trg_must)[i].dsc = (*trg_must)[*trg_must_size].dsc; |
| 2729 | (*trg_must)[i].ref = (*trg_must)[*trg_must_size].ref; |
| 2730 | (*trg_must)[i].eapptag = (*trg_must)[*trg_must_size].eapptag; |
| 2731 | (*trg_must)[i].emsg = (*trg_must)[*trg_must_size].emsg; |
| 2732 | } |
| 2733 | if (!(*trg_must_size)) { |
| 2734 | free(*trg_must); |
| 2735 | *trg_must = NULL; |
| 2736 | } else { |
| 2737 | (*trg_must)[*trg_must_size].expr = NULL; |
| 2738 | (*trg_must)[*trg_must_size].dsc = NULL; |
| 2739 | (*trg_must)[*trg_must_size].ref = NULL; |
| 2740 | (*trg_must)[*trg_must_size].eapptag = NULL; |
| 2741 | (*trg_must)[*trg_must_size].emsg = NULL; |
| 2742 | } |
| 2743 | |
| 2744 | i = -1; /* set match flag */ |
| 2745 | break; |
| 2746 | } |
| 2747 | } |
| 2748 | d->must_size++; |
| 2749 | if (i != -1) { |
| 2750 | /* no match found */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2751 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, |
Radek Krejci | adb5761 | 2016-02-16 13:34:34 +0100 | [diff] [blame] | 2752 | d->must[d->must_size - 1].expr, child->name); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2753 | 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] | 2754 | goto error; |
| 2755 | } |
| 2756 | } else { /* replace or add */ |
Michal Vasko | f92a728 | 2016-02-11 12:35:57 +0100 | [diff] [blame] | 2757 | memset(&((*trg_must)[*trg_must_size]), 0, sizeof **trg_must); |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 2758 | if (fill_yin_must(module, child, &((*trg_must)[*trg_must_size]), unres)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2759 | goto error; |
| 2760 | } |
| 2761 | (*trg_must_size)++; |
| 2762 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 2763 | |
| 2764 | /* check XPath dependencies again */ |
Michal Vasko | e873426 | 2016-09-29 14:12:06 +0200 | [diff] [blame] | 2765 | 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] | 2766 | goto error; |
| 2767 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2768 | } else if (!strcmp(child->name, "unique")) { |
| 2769 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | a0a10ab | 2016-03-07 14:41:23 +0100 | [diff] [blame] | 2770 | memset(&d->unique[d->unique_size], 0, sizeof *d->unique); |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2771 | 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] | 2772 | d->unique_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2773 | goto error; |
| 2774 | } |
| 2775 | |
| 2776 | /* find unique structures to delete */ |
| 2777 | for (i = 0; i < list->unique_size; i++) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2778 | 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] | 2779 | continue; |
| 2780 | } |
| 2781 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2782 | for (j = 0; j < d->unique[d->unique_size].expr_size; j++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 2783 | 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] | 2784 | break; |
| 2785 | } |
| 2786 | } |
| 2787 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2788 | if (j == d->unique[d->unique_size].expr_size) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2789 | /* we have a match, free the unique structure ... */ |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2790 | for (j = 0; j < list->unique[i].expr_size; j++) { |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2791 | lydict_remove(ctx, list->unique[i].expr[j]); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2792 | } |
| 2793 | free(list->unique[i].expr); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2794 | /* ... and maintain the array */ |
| 2795 | list->unique_size--; |
| 2796 | if (i != list->unique_size) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2797 | list->unique[i].expr_size = list->unique[list->unique_size].expr_size; |
| 2798 | list->unique[i].expr = list->unique[list->unique_size].expr; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2799 | } |
| 2800 | |
| 2801 | if (!list->unique_size) { |
| 2802 | free(list->unique); |
| 2803 | list->unique = NULL; |
| 2804 | } else { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2805 | list->unique[list->unique_size].expr_size = 0; |
| 2806 | list->unique[list->unique_size].expr = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2807 | } |
| 2808 | |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2809 | k = i; /* remember index for removing extensions */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2810 | i = -1; /* set match flag */ |
| 2811 | break; |
| 2812 | } |
| 2813 | } |
| 2814 | |
| 2815 | d->unique_size++; |
| 2816 | if (i != -1) { |
| 2817 | /* no match found */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2818 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, lyxml_get_attr(child, "tag", NULL), child->name); |
| 2819 | 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] | 2820 | goto error; |
| 2821 | } |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2822 | |
| 2823 | /* remove extensions of this unique instance from the target node */ |
| 2824 | j = -1; |
| 2825 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_UNIQUE)) != -1) { |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2826 | if (dev_target->ext[j]->insubstmt_index == k) { |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2827 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2828 | --j; |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2829 | } else if (dev_target->ext[j]->insubstmt_index > k) { |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2830 | /* decrease the substatement index of the extension because of the changed array of uniques */ |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2831 | dev_target->ext[j]->insubstmt_index--; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2832 | } |
| 2833 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2834 | } else { /* replace or add */ |
Michal Vasko | a0a10ab | 2016-03-07 14:41:23 +0100 | [diff] [blame] | 2835 | memset(&list->unique[list->unique_size], 0, sizeof *list->unique); |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2836 | 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] | 2837 | list->unique_size++; |
| 2838 | if (i) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2839 | goto error; |
| 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 | } else if (!strcmp(child->name, "default")) { |
| 2843 | GETVAL(value, child, "value"); |
| 2844 | u = strlen(value); |
| 2845 | d->dflt[d->dflt_size++] = lydict_insert(module->ctx, value, u); |
| 2846 | |
| 2847 | if (dev_target->nodetype == LYS_CHOICE) { |
| 2848 | choice = (struct lys_node_choice *)dev_target; |
| 2849 | rc = resolve_choice_default_schema_nodeid(value, choice->child, (const struct lys_node **)&node); |
| 2850 | if (rc || !node) { |
| 2851 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2852 | goto error; |
| 2853 | } |
| 2854 | if (d->mod == LY_DEVIATE_DEL) { |
| 2855 | if (!choice->dflt || (choice->dflt != node)) { |
| 2856 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2857 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
| 2858 | goto error; |
| 2859 | } |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2860 | choice->dflt = NULL; |
| 2861 | /* remove extensions of this default instance from the target node */ |
| 2862 | j = -1; |
| 2863 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_DEFAULT)) != -1) { |
| 2864 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2865 | --j; |
| 2866 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2867 | } else { /* add or replace */ |
| 2868 | choice->dflt = node; |
| 2869 | if (!choice->dflt) { |
| 2870 | /* default branch not found */ |
| 2871 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2872 | goto error; |
| 2873 | } |
| 2874 | } |
| 2875 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 2876 | leaf = (struct lys_node_leaf *)dev_target; |
| 2877 | if (d->mod == LY_DEVIATE_DEL) { |
| 2878 | if (!leaf->dflt || !ly_strequal(leaf->dflt, value, 1)) { |
| 2879 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2880 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
| 2881 | goto error; |
| 2882 | } |
| 2883 | /* remove value */ |
| 2884 | lydict_remove(ctx, leaf->dflt); |
| 2885 | leaf->dflt = NULL; |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 2886 | leaf->flags &= ~LYS_DFLTJSON; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2887 | |
| 2888 | /* remove extensions of this default instance from the target node */ |
| 2889 | j = -1; |
| 2890 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_DEFAULT)) != -1) { |
| 2891 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2892 | --j; |
| 2893 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2894 | } else { /* add (already checked) and replace */ |
| 2895 | /* remove value */ |
| 2896 | lydict_remove(ctx, leaf->dflt); |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 2897 | leaf->flags &= ~LYS_DFLTJSON; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2898 | |
| 2899 | /* set new value */ |
| 2900 | leaf->dflt = lydict_insert(ctx, value, u); |
| 2901 | |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 2902 | /* 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] | 2903 | ly_set_add(dflt_check, dev_target, 0); |
| 2904 | } |
| 2905 | } else { /* LYS_LEAFLIST */ |
| 2906 | llist = (struct lys_node_leaflist *)dev_target; |
| 2907 | if (d->mod == LY_DEVIATE_DEL) { |
| 2908 | /* find and remove the value in target list */ |
| 2909 | for (i = 0; i < llist->dflt_size; i++) { |
| 2910 | if (llist->dflt[i] && ly_strequal(llist->dflt[i], value, 1)) { |
| 2911 | /* match, remove the value */ |
| 2912 | lydict_remove(llist->module->ctx, llist->dflt[i]); |
| 2913 | llist->dflt[i] = NULL; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2914 | |
| 2915 | /* remove extensions of this default instance from the target node */ |
| 2916 | j = -1; |
| 2917 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_DEFAULT)) != -1) { |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2918 | if (dev_target->ext[j]->insubstmt_index == i) { |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2919 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2920 | --j; |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2921 | } else if (dev_target->ext[j]->insubstmt_index > i) { |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2922 | /* decrease the substatement index of the extension because of the changed array of defaults */ |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2923 | dev_target->ext[j]->insubstmt_index--; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2924 | } |
| 2925 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2926 | break; |
| 2927 | } |
| 2928 | } |
| 2929 | if (i == llist->dflt_size) { |
| 2930 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2931 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "The default value to delete not found in the target node."); |
| 2932 | goto error; |
| 2933 | } |
| 2934 | } else { |
| 2935 | /* add or replace, anyway we place items into the deviate's list |
| 2936 | which propagates to the target */ |
| 2937 | /* we just want to check that the value isn't already in the list */ |
| 2938 | for (i = 0; i < llist->dflt_size; i++) { |
| 2939 | if (ly_strequal(llist->dflt[i], value, 1)) { |
| 2940 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2941 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Duplicated default value \"%s\".", value); |
| 2942 | goto error; |
| 2943 | } |
| 2944 | } |
| 2945 | /* store it in target node */ |
| 2946 | llist->dflt[llist->dflt_size++] = lydict_insert(module->ctx, value, u); |
| 2947 | |
| 2948 | /* remember to check it later (it may not fit now, but the type can be deviated too) */ |
| 2949 | ly_set_add(dflt_check, dev_target, 0); |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2950 | llist->flags &= ~LYS_DFLTJSON; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2951 | } |
| 2952 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2953 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2954 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2955 | |
| 2956 | if (c_dflt && dev_target->nodetype == LYS_LEAFLIST && d->mod == LY_DEVIATE_DEL) { |
| 2957 | /* consolidate the final list in the target after removing items from it */ |
| 2958 | llist = (struct lys_node_leaflist *)dev_target; |
| 2959 | for (i = j = 0; j < llist->dflt_size; j++) { |
| 2960 | llist->dflt[i] = llist->dflt[j]; |
| 2961 | if (llist->dflt[i]) { |
| 2962 | i++; |
| 2963 | } |
| 2964 | } |
| 2965 | llist->dflt_size = i + 1; |
| 2966 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2967 | } |
| 2968 | |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2969 | /* now check whether default value, if any, matches the type */ |
Pavol Vican | 85991ec | 2016-08-16 14:58:12 +0200 | [diff] [blame] | 2970 | for (u = 0; u < dflt_check->number; ++u) { |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2971 | value = NULL; |
| 2972 | rc = EXIT_SUCCESS; |
| 2973 | if (dflt_check->set.s[u]->nodetype == LYS_LEAF) { |
| 2974 | leaf = (struct lys_node_leaf *)dflt_check->set.s[u]; |
Radek Krejci | 5167320 | 2016-11-01 17:00:32 +0100 | [diff] [blame] | 2975 | value = leaf->dflt; |
| 2976 | 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] | 2977 | } else { /* LYS_LEAFLIST */ |
| 2978 | llist = (struct lys_node_leaflist *)dflt_check->set.s[u]; |
| 2979 | for (j = 0; j < llist->dflt_size; j++) { |
Radek Krejci | 5167320 | 2016-11-01 17:00:32 +0100 | [diff] [blame] | 2980 | rc = unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DFLT, |
| 2981 | (struct lys_node *)(&llist->dflt[j])); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2982 | if (rc == -1) { |
Radek Krejci | 5167320 | 2016-11-01 17:00:32 +0100 | [diff] [blame] | 2983 | value = llist->dflt[j]; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2984 | break; |
| 2985 | } |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2986 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2987 | |
| 2988 | } |
| 2989 | if (rc == -1) { |
| 2990 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2991 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2992 | "The default value \"%s\" of the deviated node \"%s\"no longer matches its type.", |
| 2993 | dev->target_name); |
| 2994 | goto error; |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2995 | } |
| 2996 | } |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2997 | |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 2998 | /* mark all the affected modules as deviated and implemented */ |
| 2999 | for(parent = dev_target; parent; parent = lys_parent(parent)) { |
| 3000 | mod = lys_node_module(parent); |
| 3001 | if (module != mod) { |
| 3002 | mod->deviated = 1; |
Radek Krejci | 2bb5be7 | 2017-02-27 13:07:25 +0100 | [diff] [blame] | 3003 | if (lys_set_implemented(mod)) { |
| 3004 | LOGERR(ly_errno, "Setting the deviated module \"%s\" implemented failed.", mod->name); |
| 3005 | goto error; |
| 3006 | } |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 3007 | } |
| 3008 | } |
| 3009 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3010 | ly_set_free(dflt_check); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3011 | return EXIT_SUCCESS; |
| 3012 | |
| 3013 | error: |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3014 | ly_set_free(dflt_check); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3015 | return EXIT_FAILURE; |
| 3016 | } |
| 3017 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3018 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3019 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3020 | fill_yin_augment(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_node_augment *aug, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3021 | int options, struct unres_schema *unres) |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3022 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3023 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3024 | struct lyxml_elem *sub, *next; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3025 | struct lys_node *node; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3026 | int ret, c_ftrs = 0, c_ext = 0; |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 3027 | void *reallocated; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3028 | |
Michal Vasko | 591e0b2 | 2015-08-13 13:53:43 +0200 | [diff] [blame] | 3029 | aug->nodetype = LYS_AUGMENT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3030 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3031 | aug->target_name = transform_schema2json(module, value); |
Michal Vasko | 488c19e | 2015-10-20 15:21:00 +0200 | [diff] [blame] | 3032 | if (!aug->target_name) { |
| 3033 | goto error; |
| 3034 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3035 | aug->parent = parent; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3036 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3037 | 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] | 3038 | goto error; |
| 3039 | } |
| 3040 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3041 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 3042 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3043 | /* extension */ |
| 3044 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3045 | continue; |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 3046 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3047 | c_ftrs++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3048 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3049 | } else if (!strcmp(sub->name, "when")) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3050 | if (aug->when) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3051 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3052 | goto error; |
| 3053 | } |
| 3054 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3055 | aug->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3056 | if (!aug->when) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3057 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3058 | goto error; |
| 3059 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3060 | lyxml_free(module->ctx, sub); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3061 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3062 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3063 | /* check allowed data sub-statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3064 | } else if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3065 | node = read_yin_container(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3066 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3067 | node = read_yin_leaflist(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3068 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3069 | node = read_yin_leaf(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3070 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3071 | node = read_yin_list(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3072 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3073 | node = read_yin_uses(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3074 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3075 | node = read_yin_choice(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3076 | } else if (!strcmp(sub->name, "case")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3077 | node = read_yin_case(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3078 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3079 | node = read_yin_anydata(module, (struct lys_node *)aug, sub, LYS_ANYXML, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3080 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3081 | node = read_yin_anydata(module, (struct lys_node *)aug, sub, LYS_ANYDATA, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3082 | } else if (!strcmp(sub->name, "action")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3083 | node = read_yin_rpc_action(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3084 | } else if (!strcmp(sub->name, "notification")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3085 | node = read_yin_notif(module, (struct lys_node *)aug, sub, options, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3086 | } else { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3087 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3088 | goto error; |
| 3089 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3090 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3091 | if (!node) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3092 | goto error; |
| 3093 | } |
| 3094 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3095 | node = NULL; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3096 | lyxml_free(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3097 | } |
| 3098 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3099 | if (c_ftrs) { |
| 3100 | aug->iffeature = calloc(c_ftrs, sizeof *aug->iffeature); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 3101 | if (!aug->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3102 | LOGMEM; |
| 3103 | goto error; |
| 3104 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3105 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3106 | if (c_ext) { |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 3107 | /* some extensions may be already present from the substatements */ |
| 3108 | reallocated = realloc(aug->ext, (c_ext + aug->ext_size) * sizeof *aug->ext); |
| 3109 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3110 | LOGMEM; |
| 3111 | goto error; |
| 3112 | } |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 3113 | aug->ext = reallocated; |
| 3114 | |
| 3115 | /* init memory */ |
| 3116 | memset(&aug->ext[aug->ext_size], 0, c_ext * sizeof *aug->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3117 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3118 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3119 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 3120 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3121 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3122 | 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] | 3123 | aug->ext_size++; |
| 3124 | if (ret) { |
| 3125 | goto error; |
| 3126 | } |
| 3127 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3128 | 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] | 3129 | aug->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3130 | if (ret) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3131 | goto error; |
| 3132 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3133 | lyxml_free(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3134 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3135 | } |
| 3136 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3137 | /* aug->child points to the parsed nodes, they must now be |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 3138 | * connected to the tree and adjusted (if possible right now). |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 3139 | * 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] | 3140 | * when the uses does and cannot be resolved now for sure |
| 3141 | * (the grouping was not yet copied into uses). |
| 3142 | */ |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 3143 | if (!parent) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3144 | if (unres_schema_add_node(module, unres, aug, UNRES_AUGMENT, NULL) == -1) { |
Michal Vasko | 4adc10f | 2015-08-11 15:26:17 +0200 | [diff] [blame] | 3145 | goto error; |
| 3146 | } |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 3147 | } |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3148 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 3149 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3150 | if (aug->when) { |
| 3151 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame^] | 3152 | if (lyxp_node_check_syntax((struct lys_node *)aug)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3153 | goto error; |
| 3154 | } |
| 3155 | } else { |
| 3156 | if (unres_schema_add_node(module, unres, (struct lys_node *)aug, UNRES_XPATH, NULL) == -1) { |
| 3157 | goto error; |
| 3158 | } |
| 3159 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 3160 | } |
| 3161 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3162 | return EXIT_SUCCESS; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3163 | |
| 3164 | error: |
| 3165 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3166 | return EXIT_FAILURE; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3167 | } |
| 3168 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3169 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3170 | static int |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3171 | 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] | 3172 | { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3173 | struct lys_module *module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3174 | struct lyxml_elem *sub, *next; |
| 3175 | const char *value; |
| 3176 | char *endptr; |
| 3177 | int f_mand = 0, f_min = 0, f_max = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3178 | 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] | 3179 | int r; |
| 3180 | unsigned long int val; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3181 | void *reallocated; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3182 | |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3183 | assert(uses); |
| 3184 | module = uses->module; /* shorthand */ |
| 3185 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3186 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3187 | rfn->target_name = transform_schema2json(module, value); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 3188 | if (!rfn->target_name) { |
| 3189 | goto error; |
| 3190 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3191 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3192 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3193 | if (!sub->ns) { |
| 3194 | /* garbage */ |
| 3195 | } else if (strcmp(sub->ns->value, LY_NSYIN)) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3196 | /* extension */ |
| 3197 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3198 | continue; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3199 | |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3200 | } else if (!strcmp(sub->name, "description")) { |
| 3201 | if (rfn->dsc) { |
| 3202 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3203 | goto error; |
| 3204 | } |
| 3205 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3206 | if (lyp_yin_parse_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3207 | goto error; |
| 3208 | } |
| 3209 | |
| 3210 | rfn->dsc = read_yin_subnode(module->ctx, sub, "text"); |
| 3211 | if (!rfn->dsc) { |
| 3212 | goto error; |
| 3213 | } |
| 3214 | } else if (!strcmp(sub->name, "reference")) { |
| 3215 | if (rfn->ref) { |
| 3216 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3217 | goto error; |
| 3218 | } |
| 3219 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3220 | if (lyp_yin_parse_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3221 | goto error; |
| 3222 | } |
| 3223 | |
| 3224 | rfn->ref = read_yin_subnode(module->ctx, sub, "text"); |
| 3225 | if (!rfn->ref) { |
| 3226 | goto error; |
| 3227 | } |
| 3228 | } else if (!strcmp(sub->name, "config")) { |
| 3229 | if (rfn->flags & LYS_CONFIG_MASK) { |
| 3230 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3231 | goto error; |
| 3232 | } |
| 3233 | GETVAL(value, sub, "value"); |
| 3234 | if (!strcmp(value, "false")) { |
| 3235 | rfn->flags |= LYS_CONFIG_R; |
| 3236 | } else if (!strcmp(value, "true")) { |
| 3237 | rfn->flags |= LYS_CONFIG_W; |
| 3238 | } else { |
| 3239 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
| 3240 | goto error; |
| 3241 | } |
| 3242 | rfn->flags |= LYS_CONFIG_SET; |
| 3243 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3244 | if (lyp_yin_parse_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_CONFIG, 0, unres)) { |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3245 | goto error; |
| 3246 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3247 | } else if (!strcmp(sub->name, "default")) { |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3248 | /* leaf, leaf-list or choice */ |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3249 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3250 | /* check possibility of statements combination */ |
| 3251 | if (rfn->target_type) { |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3252 | if (c_dflt) { |
| 3253 | /* multiple defaults are allowed only in leaf-list */ |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3254 | if (module->version < 2) { |
| 3255 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3256 | goto error; |
| 3257 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3258 | rfn->target_type &= LYS_LEAFLIST; |
| 3259 | } else { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3260 | if (module->version < 2) { |
| 3261 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE); |
| 3262 | } else { |
| 3263 | /* YANG 1.1 */ |
| 3264 | rfn->target_type &= (LYS_LEAFLIST | LYS_LEAF | LYS_CHOICE); |
| 3265 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3266 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3267 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3268 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3269 | 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] | 3270 | goto error; |
| 3271 | } |
| 3272 | } else { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3273 | if (module->version < 2) { |
| 3274 | rfn->target_type = LYS_LEAF | LYS_CHOICE; |
| 3275 | } else { |
| 3276 | /* YANG 1.1 */ |
| 3277 | rfn->target_type = LYS_LEAFLIST | LYS_LEAF | LYS_CHOICE; |
| 3278 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3279 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3280 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3281 | if (lyp_yin_parse_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_DEFAULT, c_dflt, unres)) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3282 | goto error; |
| 3283 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3284 | c_dflt++; |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3285 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3286 | } else if (!strcmp(sub->name, "mandatory")) { |
| 3287 | /* leaf, choice or anyxml */ |
| 3288 | if (f_mand) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3289 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3290 | goto error; |
| 3291 | } |
| 3292 | /* just checking the flags in leaf is not sufficient, we would allow |
| 3293 | * multiple mandatory statements with the "false" value |
| 3294 | */ |
| 3295 | f_mand = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3296 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3297 | /* check possibility of statements combination */ |
| 3298 | if (rfn->target_type) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3299 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE | LYS_ANYDATA); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3300 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3301 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3302 | 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] | 3303 | goto error; |
| 3304 | } |
| 3305 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3306 | rfn->target_type = LYS_LEAF | LYS_CHOICE | LYS_ANYDATA; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3307 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3308 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3309 | GETVAL(value, sub, "value"); |
| 3310 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3311 | rfn->flags |= LYS_MAND_TRUE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3312 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3313 | rfn->flags |= LYS_MAND_FALSE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3314 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3315 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3316 | goto error; |
| 3317 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3318 | if (lyp_yin_parse_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_MANDATORY, 0, unres)) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3319 | goto error; |
| 3320 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3321 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3322 | /* list or leaf-list */ |
| 3323 | if (f_min) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3324 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3325 | goto error; |
| 3326 | } |
| 3327 | f_min = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3328 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3329 | /* check possibility of statements combination */ |
| 3330 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3331 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3332 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3333 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3334 | 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] | 3335 | goto error; |
| 3336 | } |
| 3337 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3338 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3339 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3340 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3341 | GETVAL(value, sub, "value"); |
| 3342 | while (isspace(value[0])) { |
| 3343 | value++; |
| 3344 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3345 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3346 | /* convert it to uint32_t */ |
| 3347 | errno = 0; |
| 3348 | endptr = NULL; |
| 3349 | val = strtoul(value, &endptr, 10); |
| 3350 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3351 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3352 | goto error; |
| 3353 | } |
| 3354 | rfn->mod.list.min = (uint32_t) val; |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 3355 | rfn->flags |= LYS_RFN_MINSET; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3356 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3357 | if (lyp_yin_parse_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_MIN, 0, unres)) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3358 | goto error; |
| 3359 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3360 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3361 | /* list or leaf-list */ |
| 3362 | if (f_max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3363 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3364 | goto error; |
| 3365 | } |
| 3366 | f_max = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3367 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3368 | /* check possibility of statements combination */ |
| 3369 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3370 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3371 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3372 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3373 | 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] | 3374 | goto error; |
| 3375 | } |
| 3376 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3377 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3378 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3379 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3380 | GETVAL(value, sub, "value"); |
| 3381 | while (isspace(value[0])) { |
| 3382 | value++; |
| 3383 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3384 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 3385 | if (!strcmp(value, "unbounded")) { |
| 3386 | rfn->mod.list.max = 0; |
| 3387 | } else { |
| 3388 | /* convert it to uint32_t */ |
| 3389 | errno = 0; |
| 3390 | endptr = NULL; |
| 3391 | val = strtoul(value, &endptr, 10); |
| 3392 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3393 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 3394 | goto error; |
| 3395 | } |
| 3396 | rfn->mod.list.max = (uint32_t) val; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3397 | } |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 3398 | rfn->flags |= LYS_RFN_MAXSET; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3399 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3400 | if (lyp_yin_parse_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_MAX, 0, unres)) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3401 | goto error; |
| 3402 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3403 | } else if (!strcmp(sub->name, "presence")) { |
| 3404 | /* container */ |
| 3405 | if (rfn->mod.presence) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3406 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3407 | goto error; |
| 3408 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3409 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3410 | /* check possibility of statements combination */ |
| 3411 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3412 | rfn->target_type &= LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3413 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3414 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3415 | 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] | 3416 | goto error; |
| 3417 | } |
| 3418 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3419 | rfn->target_type = LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3420 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3421 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3422 | GETVAL(value, sub, "value"); |
| 3423 | rfn->mod.presence = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3424 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3425 | if (lyp_yin_parse_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_PRESENCE, 0, unres)) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3426 | goto error; |
| 3427 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3428 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3429 | /* leafm leaf-list, list, container or anyxml */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3430 | /* check possibility of statements combination */ |
| 3431 | if (rfn->target_type) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3432 | 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] | 3433 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3434 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3435 | 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] | 3436 | goto error; |
| 3437 | } |
| 3438 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3439 | 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] | 3440 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3441 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3442 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3443 | continue; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3444 | |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3445 | } else if ((module->version >= 2) && !strcmp(sub->name, "if-feature")) { |
| 3446 | /* leaf, leaf-list, list, container or anyxml */ |
| 3447 | /* check possibility of statements combination */ |
| 3448 | if (rfn->target_type) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3449 | 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] | 3450 | if (!rfn->target_type) { |
| 3451 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3452 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid refine target nodetype for the substatements."); |
| 3453 | goto error; |
| 3454 | } |
| 3455 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3456 | 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] | 3457 | } |
| 3458 | |
| 3459 | c_ftrs++; |
| 3460 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3461 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3462 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3463 | goto error; |
| 3464 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3465 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3466 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3467 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3468 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3469 | /* process nodes with cardinality of 0..n */ |
| 3470 | if (c_must) { |
| 3471 | rfn->must = calloc(c_must, sizeof *rfn->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3472 | if (!rfn->must) { |
| 3473 | LOGMEM; |
| 3474 | goto error; |
| 3475 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3476 | } |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3477 | if (c_ftrs) { |
Radek Krejci | 947e034 | 2016-08-15 09:42:56 +0200 | [diff] [blame] | 3478 | rfn->iffeature = calloc(c_ftrs, sizeof *rfn->iffeature); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3479 | if (!rfn->iffeature) { |
| 3480 | LOGMEM; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3481 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3482 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3483 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3484 | if (c_dflt) { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3485 | rfn->dflt = calloc(c_dflt, sizeof *rfn->dflt); |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3486 | if (!rfn->dflt) { |
| 3487 | LOGMEM; |
| 3488 | goto error; |
| 3489 | } |
| 3490 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3491 | if (c_ext) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3492 | /* some extensions may be already present from the substatements */ |
| 3493 | reallocated = realloc(rfn->ext, (c_ext + rfn->ext_size) * sizeof *rfn->ext); |
| 3494 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3495 | LOGMEM; |
| 3496 | goto error; |
| 3497 | } |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3498 | rfn->ext = reallocated; |
| 3499 | |
| 3500 | /* init memory */ |
| 3501 | memset(&rfn->ext[rfn->ext_size], 0, c_ext * sizeof *rfn->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3502 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3503 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3504 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 3505 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3506 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3507 | 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] | 3508 | rfn->ext_size++; |
| 3509 | if (r) { |
| 3510 | goto error; |
| 3511 | } |
| 3512 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 3513 | 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] | 3514 | rfn->iffeature_size++; |
| 3515 | if (r) { |
| 3516 | goto error; |
| 3517 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3518 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 3519 | r = fill_yin_must(module, sub, &rfn->must[rfn->must_size], unres); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3520 | rfn->must_size++; |
| 3521 | if (r) { |
| 3522 | goto error; |
| 3523 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3524 | } else { /* default */ |
| 3525 | GETVAL(value, sub, "value"); |
| 3526 | |
| 3527 | /* check for duplicity */ |
| 3528 | for (r = 0; r < rfn->dflt_size; r++) { |
| 3529 | if (ly_strequal(rfn->dflt[r], value, 1)) { |
| 3530 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 3531 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Duplicated default value \"%s\".", value); |
| 3532 | goto error; |
| 3533 | } |
| 3534 | } |
| 3535 | rfn->dflt[rfn->dflt_size++] = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3536 | } |
| 3537 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3538 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3539 | return EXIT_SUCCESS; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3540 | |
| 3541 | error: |
| 3542 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3543 | return EXIT_FAILURE; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3544 | } |
| 3545 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3546 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3547 | static int |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3548 | 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] | 3549 | { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3550 | struct lyxml_elem *child, *next, exts; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3551 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3552 | int r, c_ext = 0; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3553 | void *reallocated; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3554 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3555 | /* init */ |
| 3556 | memset(&exts, 0, sizeof exts); |
| 3557 | |
| 3558 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 3559 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3560 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3561 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3562 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 3563 | /* extension */ |
| 3564 | c_ext++; |
| 3565 | lyxml_unlink_elem(module->ctx, child, 2); |
| 3566 | lyxml_add_child(module->ctx, &exts, child); |
| 3567 | } else if (!strcmp(child->name, "prefix")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3568 | GETVAL(value, child, "value"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3569 | if (lyp_check_identifier(value, LY_IDENT_PREFIX, module, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3570 | goto error; |
| 3571 | } |
| 3572 | imp->prefix = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3573 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3574 | if (lyp_yin_parse_subnode_ext(module, imp, LYEXT_PAR_IMPORT, child, LYEXT_SUBSTMT_PREFIX, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3575 | goto error; |
| 3576 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3577 | } else if (!strcmp(child->name, "revision-date")) { |
| 3578 | if (imp->rev[0]) { |
Radek Krejci | d52195b | 2016-06-22 11:18:49 +0200 | [diff] [blame] | 3579 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3580 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3581 | } |
| 3582 | GETVAL(value, child, "date"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3583 | if (lyp_check_date(value)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3584 | goto error; |
| 3585 | } |
| 3586 | memcpy(imp->rev, value, LY_REV_SIZE - 1); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3587 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3588 | if (lyp_yin_parse_subnode_ext(module, imp, LYEXT_PAR_IMPORT, child, LYEXT_SUBSTMT_REVISIONDATE, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3589 | goto error; |
| 3590 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3591 | } else if ((module->version >= 2) && !strcmp(child->name, "description")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3592 | if (imp->dsc) { |
| 3593 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3594 | goto error; |
| 3595 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3596 | if (lyp_yin_parse_subnode_ext(module, imp, LYEXT_PAR_IMPORT, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3597 | goto error; |
| 3598 | } |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3599 | imp->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 3600 | if (!imp->dsc) { |
| 3601 | goto error; |
| 3602 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3603 | } else if ((module->version >= 2) && !strcmp(child->name, "reference")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3604 | if (imp->ref) { |
| 3605 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3606 | goto error; |
| 3607 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3608 | if (lyp_yin_parse_subnode_ext(module, imp, LYEXT_PAR_IMPORT, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3609 | goto error; |
| 3610 | } |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3611 | imp->ref = read_yin_subnode(module->ctx, child, "text"); |
| 3612 | if (!imp->ref) { |
| 3613 | goto error; |
| 3614 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3615 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3616 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3617 | goto error; |
| 3618 | } |
| 3619 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3620 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3621 | /* check mandatory information */ |
| 3622 | if (!imp->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3623 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3624 | goto error; |
| 3625 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 3626 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3627 | /* process extensions */ |
| 3628 | if (c_ext) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3629 | /* some extensions may be already present from the substatements */ |
| 3630 | reallocated = realloc(imp->ext, (c_ext + imp->ext_size) * sizeof *imp->ext); |
| 3631 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3632 | LOGMEM; |
| 3633 | goto error; |
| 3634 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3635 | imp->ext = reallocated; |
| 3636 | |
| 3637 | /* init memory */ |
| 3638 | memset(&imp->ext[imp->ext_size], 0, c_ext * sizeof *imp->ext); |
| 3639 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3640 | LY_TREE_FOR_SAFE(exts.child, next, child) { |
| 3641 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3642 | 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] | 3643 | imp->ext_size++; |
| 3644 | if (r) { |
| 3645 | goto error; |
| 3646 | } |
| 3647 | } |
| 3648 | } |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 3649 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3650 | GETVAL(value, yin, "module"); |
Pavol Vican | e994fda | 2016-03-22 10:47:58 +0100 | [diff] [blame] | 3651 | return lyp_check_import(module, value, imp); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 3652 | |
| 3653 | error: |
| 3654 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3655 | while (exts.child) { |
| 3656 | lyxml_free(module->ctx, exts.child); |
| 3657 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3658 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3659 | } |
| 3660 | |
Radek Krejci | 5b2c8a8 | 2016-06-17 15:36:03 +0200 | [diff] [blame] | 3661 | /* logs directly |
| 3662 | * returns: |
| 3663 | * 0 - inc successfully filled |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 3664 | * -1 - error |
Radek Krejci | 5b2c8a8 | 2016-06-17 15:36:03 +0200 | [diff] [blame] | 3665 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3666 | static int |
Michal Vasko | 5ff7882 | 2016-02-12 09:33:31 +0100 | [diff] [blame] | 3667 | fill_yin_include(struct lys_module *module, struct lys_submodule *submodule, struct lyxml_elem *yin, |
| 3668 | struct lys_include *inc, struct unres_schema *unres) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3669 | { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3670 | struct lyxml_elem *child, *next, exts; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3671 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3672 | int r, c_ext = 0; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3673 | void *reallocated; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3674 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3675 | /* init */ |
| 3676 | memset(&exts, 0, sizeof exts); |
| 3677 | |
| 3678 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 3679 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3680 | /* garbage */ |
| 3681 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3682 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 3683 | /* extension */ |
| 3684 | c_ext++; |
| 3685 | lyxml_unlink_elem(module->ctx, child, 2); |
| 3686 | lyxml_add_child(module->ctx, &exts, child); |
| 3687 | } else if (!strcmp(child->name, "revision-date")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3688 | if (inc->rev[0]) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3689 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3690 | goto error; |
| 3691 | } |
| 3692 | GETVAL(value, child, "date"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3693 | if (lyp_check_date(value)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3694 | goto error; |
| 3695 | } |
| 3696 | memcpy(inc->rev, value, LY_REV_SIZE - 1); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3697 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3698 | if (lyp_yin_parse_subnode_ext(module, inc, LYEXT_PAR_INCLUDE, child, LYEXT_SUBSTMT_REVISIONDATE, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3699 | goto error; |
| 3700 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3701 | } else if ((module->version >= 2) && !strcmp(child->name, "description")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3702 | if (inc->dsc) { |
| 3703 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3704 | goto error; |
| 3705 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3706 | if (lyp_yin_parse_subnode_ext(module, inc, LYEXT_PAR_INCLUDE, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3707 | goto error; |
| 3708 | } |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3709 | inc->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 3710 | if (!inc->dsc) { |
| 3711 | goto error; |
| 3712 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3713 | } else if ((module->version >= 2) && !strcmp(child->name, "reference")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3714 | if (inc->ref) { |
| 3715 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3716 | goto error; |
| 3717 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3718 | if (lyp_yin_parse_subnode_ext(module, inc, LYEXT_PAR_INCLUDE, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3719 | goto error; |
| 3720 | } |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3721 | inc->ref = read_yin_subnode(module->ctx, child, "text"); |
| 3722 | if (!inc->ref) { |
| 3723 | goto error; |
| 3724 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3725 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3726 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3727 | goto error; |
| 3728 | } |
| 3729 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3730 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3731 | /* process extensions */ |
| 3732 | if (c_ext) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3733 | /* some extensions may be already present from the substatements */ |
| 3734 | reallocated = realloc(inc->ext, (c_ext + inc->ext_size) * sizeof *inc->ext); |
| 3735 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3736 | LOGMEM; |
| 3737 | goto error; |
| 3738 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3739 | inc->ext = reallocated; |
| 3740 | |
| 3741 | /* init memory */ |
| 3742 | memset(&inc->ext[inc->ext_size], 0, c_ext * sizeof *inc->ext); |
| 3743 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3744 | LY_TREE_FOR_SAFE(exts.child, next, child) { |
| 3745 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3746 | 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] | 3747 | inc->ext_size++; |
| 3748 | if (r) { |
| 3749 | goto error; |
| 3750 | } |
| 3751 | } |
| 3752 | } |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 3753 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3754 | GETVAL(value, yin, "module"); |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 3755 | 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] | 3756 | |
| 3757 | error: |
| 3758 | |
Radek Krejci | 83e3f5b | 2016-06-24 14:55:25 +0200 | [diff] [blame] | 3759 | return -1; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3760 | } |
| 3761 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3762 | /* logs directly |
| 3763 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3764 | * Covers: |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 3765 | * description, reference, status, optionaly config |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 3766 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3767 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3768 | static int |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3769 | read_yin_common(struct lys_module *module, struct lys_node *parent, void *stmt, LYEXT_PAR stmt_type, |
| 3770 | struct lyxml_elem *xmlnode, int opt, struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3771 | { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3772 | struct lys_node *node = stmt; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3773 | const char *value; |
| 3774 | struct lyxml_elem *sub, *next; |
| 3775 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3776 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3777 | if (opt & OPT_MODULE) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3778 | node->module = module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3779 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3780 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3781 | if (opt & OPT_IDENT) { |
| 3782 | GETVAL(value, xmlnode, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3783 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3784 | goto error; |
| 3785 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3786 | node->name = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3787 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3788 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3789 | /* process local parameters */ |
| 3790 | LY_TREE_FOR_SAFE(xmlnode->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3791 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3792 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3793 | lyxml_free(ctx, sub); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3794 | continue; |
| 3795 | } |
| 3796 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
Radek Krejci | 6ff885d | 2017-01-03 14:06:22 +0100 | [diff] [blame] | 3797 | /* 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] | 3798 | continue; |
| 3799 | } |
| 3800 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3801 | if (!strcmp(sub->name, "description")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3802 | if (node->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3803 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3804 | goto error; |
| 3805 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3806 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3807 | if (lyp_yin_parse_subnode_ext(module, stmt, stmt_type, sub, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3808 | goto error; |
| 3809 | } |
| 3810 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3811 | node->dsc = read_yin_subnode(ctx, sub, "text"); |
| 3812 | if (!node->dsc) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3813 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3814 | } |
| 3815 | } else if (!strcmp(sub->name, "reference")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3816 | if (node->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3817 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3818 | goto error; |
| 3819 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3820 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3821 | if (lyp_yin_parse_subnode_ext(module, stmt, stmt_type, sub, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3822 | goto error; |
| 3823 | } |
| 3824 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3825 | node->ref = read_yin_subnode(ctx, sub, "text"); |
| 3826 | if (!node->ref) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3827 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3828 | } |
| 3829 | } else if (!strcmp(sub->name, "status")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3830 | if (node->flags & LYS_STATUS_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3831 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3832 | goto error; |
| 3833 | } |
| 3834 | GETVAL(value, sub, "value"); |
| 3835 | if (!strcmp(value, "current")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3836 | node->flags |= LYS_STATUS_CURR; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3837 | } else if (!strcmp(value, "deprecated")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3838 | node->flags |= LYS_STATUS_DEPRC; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3839 | } else if (!strcmp(value, "obsolete")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3840 | node->flags |= LYS_STATUS_OBSLT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3841 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3842 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3843 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3844 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3845 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3846 | if (lyp_yin_parse_subnode_ext(module, stmt, stmt_type, sub, LYEXT_SUBSTMT_STATUS, 0, unres)) { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3847 | goto error; |
| 3848 | } |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3849 | } else if ((opt & (OPT_CFG_PARSE | OPT_CFG_IGNORE)) && !strcmp(sub->name, "config")) { |
| 3850 | if (opt & OPT_CFG_PARSE) { |
| 3851 | if (node->flags & LYS_CONFIG_MASK) { |
| 3852 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
| 3853 | goto error; |
| 3854 | } |
| 3855 | GETVAL(value, sub, "value"); |
| 3856 | if (!strcmp(value, "false")) { |
| 3857 | node->flags |= LYS_CONFIG_R; |
| 3858 | } else if (!strcmp(value, "true")) { |
| 3859 | node->flags |= LYS_CONFIG_W; |
| 3860 | } else { |
| 3861 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
| 3862 | goto error; |
| 3863 | } |
| 3864 | node->flags |= LYS_CONFIG_SET; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3865 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3866 | if (lyp_yin_parse_subnode_ext(module, stmt, stmt_type, sub, LYEXT_SUBSTMT_CONFIG, 0, unres)) { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3867 | goto error; |
| 3868 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3869 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3870 | } else { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3871 | /* skip the lyxml_free */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3872 | continue; |
| 3873 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3874 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3875 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3876 | |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3877 | if ((opt & OPT_CFG_INHERIT) && !(node->flags & LYS_CONFIG_MASK)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3878 | /* get config flag from parent */ |
Radek Krejci | f71f48f | 2016-10-25 16:37:24 +0200 | [diff] [blame] | 3879 | if (parent) { |
| 3880 | node->flags |= parent->flags & LYS_CONFIG_MASK; |
| 3881 | } else if (!parent) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3882 | /* default config is true */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3883 | node->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3884 | } |
| 3885 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3886 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3887 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 3888 | |
| 3889 | error: |
| 3890 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3891 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3892 | } |
| 3893 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3894 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3895 | static struct lys_when * |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3896 | 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] | 3897 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3898 | struct lys_when *retval = NULL; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3899 | struct lyxml_elem *child, *next; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3900 | const char *value; |
| 3901 | |
| 3902 | retval = calloc(1, sizeof *retval); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3903 | if (!retval) { |
| 3904 | LOGMEM; |
| 3905 | return NULL; |
| 3906 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3907 | |
| 3908 | GETVAL(value, yin, "condition"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3909 | retval->cond = transform_schema2json(module, value); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 3910 | if (!retval->cond) { |
| 3911 | goto error; |
| 3912 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3913 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3914 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 3915 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3916 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3917 | continue; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3918 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 3919 | /* extensions */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3920 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_WHEN, child, LYEXT_SUBSTMT_SELF, 0, unres)) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3921 | goto error; |
| 3922 | } |
| 3923 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3924 | if (retval->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3925 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3926 | goto error; |
| 3927 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3928 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3929 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_WHEN, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3930 | goto error; |
| 3931 | } |
| 3932 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3933 | retval->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 3934 | if (!retval->dsc) { |
| 3935 | goto error; |
| 3936 | } |
| 3937 | } else if (!strcmp(child->name, "reference")) { |
| 3938 | if (retval->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3939 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3940 | goto error; |
| 3941 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3942 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3943 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_WHEN, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3944 | goto error; |
| 3945 | } |
| 3946 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3947 | retval->ref = read_yin_subnode(module->ctx, child, "text"); |
| 3948 | if (!retval->ref) { |
| 3949 | goto error; |
| 3950 | } |
| 3951 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3952 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3953 | goto error; |
| 3954 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3955 | } |
| 3956 | |
| 3957 | return retval; |
| 3958 | |
| 3959 | error: |
| 3960 | |
Michal Vasko | 0308dd6 | 2015-10-07 09:14:40 +0200 | [diff] [blame] | 3961 | lys_when_free(module->ctx, retval); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3962 | return NULL; |
| 3963 | } |
| 3964 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3965 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3966 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3967 | read_yin_case(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int options, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3968 | struct unres_schema *unres) |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3969 | { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3970 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3971 | struct lys_node_case *cs; |
| 3972 | struct lys_node *retval, *node = NULL; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3973 | int c_ftrs = 0, c_ext = 0, ret; |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 3974 | void *reallocated; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3975 | |
Radek Krejci | e867c85 | 2015-08-27 09:52:34 +0200 | [diff] [blame] | 3976 | /* init */ |
| 3977 | memset(&root, 0, sizeof root); |
| 3978 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3979 | cs = calloc(1, sizeof *cs); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3980 | if (!cs) { |
| 3981 | LOGMEM; |
| 3982 | return NULL; |
| 3983 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3984 | cs->nodetype = LYS_CASE; |
| 3985 | cs->prev = (struct lys_node *)cs; |
| 3986 | retval = (struct lys_node *)cs; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3987 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3988 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3989 | OPT_IDENT | OPT_MODULE | (!(options & LYS_PARSE_OPT_CFG_MASK) ? OPT_CFG_INHERIT : 0), unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3990 | goto error; |
| 3991 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3992 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 3993 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3994 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3995 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 3996 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3997 | goto error; |
| 3998 | } |
| 3999 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4000 | /* process choice's specific children */ |
| 4001 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4002 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4003 | /* extension */ |
| 4004 | c_ext++; |
| 4005 | } else if (!strcmp(sub->name, "container") || |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4006 | !strcmp(sub->name, "leaf-list") || |
| 4007 | !strcmp(sub->name, "leaf") || |
| 4008 | !strcmp(sub->name, "list") || |
| 4009 | !strcmp(sub->name, "uses") || |
| 4010 | !strcmp(sub->name, "choice") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 4011 | !strcmp(sub->name, "anyxml") || |
| 4012 | !strcmp(sub->name, "anydata")) { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4013 | |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4014 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4015 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4016 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4017 | c_ftrs++; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4018 | } else if (!strcmp(sub->name, "when")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4019 | if (cs->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4020 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4021 | goto error; |
| 4022 | } |
| 4023 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4024 | cs->when = read_yin_when(module, sub, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4025 | if (!cs->when) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4026 | goto error; |
| 4027 | } |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4028 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4029 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4030 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4031 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4032 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4033 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4034 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4035 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4036 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4037 | cs->iffeature = calloc(c_ftrs, sizeof *cs->iffeature); |
| 4038 | if (!cs->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4039 | LOGMEM; |
| 4040 | goto error; |
| 4041 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4042 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4043 | if (c_ext) { |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4044 | /* some extensions may be already present from the substatements */ |
| 4045 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 4046 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4047 | LOGMEM; |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4048 | goto error; |
| 4049 | } |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4050 | retval->ext = reallocated; |
| 4051 | |
| 4052 | /* init memory */ |
| 4053 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4054 | } |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4055 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4056 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4057 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4058 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4059 | 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] | 4060 | retval->ext_size++; |
| 4061 | if (ret) { |
| 4062 | goto error; |
| 4063 | } |
| 4064 | } else { |
| 4065 | /* if-feature */ |
| 4066 | ret = fill_yin_iffeature(retval, 0, sub, &cs->iffeature[cs->iffeature_size], unres); |
| 4067 | cs->iffeature_size++; |
| 4068 | if (ret) { |
| 4069 | goto error; |
| 4070 | } |
| 4071 | } |
| 4072 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 4073 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4074 | /* last part - process data nodes */ |
| 4075 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4076 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4077 | node = read_yin_container(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4078 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4079 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4080 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4081 | node = read_yin_leaf(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4082 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4083 | node = read_yin_list(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4084 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4085 | node = read_yin_choice(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4086 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4087 | node = read_yin_uses(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4088 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4089 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4090 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4091 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4092 | } |
| 4093 | if (!node) { |
| 4094 | goto error; |
| 4095 | } |
| 4096 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4097 | lyxml_free(module->ctx, sub); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4098 | } |
| 4099 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4100 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4101 | if (cs->when) { |
| 4102 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame^] | 4103 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4104 | goto error; |
| 4105 | } |
| 4106 | } else { |
| 4107 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 4108 | goto error; |
| 4109 | } |
| 4110 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4111 | } |
| 4112 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4113 | return retval; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4114 | |
| 4115 | error: |
| 4116 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4117 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4118 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4119 | } |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4120 | lys_node_free(retval, NULL, 0); |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4121 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4122 | return NULL; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4123 | } |
| 4124 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4125 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4126 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4127 | read_yin_choice(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int options, |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4128 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4129 | { |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4130 | struct lyxml_elem *sub, *next, *dflt = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4131 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4132 | struct lys_node *retval, *node = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4133 | struct lys_node_choice *choice; |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4134 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4135 | int f_mand = 0, c_ftrs = 0, c_ext = 0, ret; |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4136 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4137 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4138 | choice = calloc(1, sizeof *choice); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4139 | if (!choice) { |
| 4140 | LOGMEM; |
| 4141 | return NULL; |
| 4142 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4143 | choice->nodetype = LYS_CHOICE; |
| 4144 | choice->prev = (struct lys_node *)choice; |
| 4145 | retval = (struct lys_node *)choice; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4146 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4147 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4148 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
| 4149 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), |
| 4150 | unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4151 | goto error; |
| 4152 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4153 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 4154 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4155 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4156 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4157 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4158 | goto error; |
| 4159 | } |
| 4160 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4161 | /* process choice's specific children */ |
| 4162 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4163 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4164 | /* extension */ |
| 4165 | c_ext++; |
| 4166 | /* keep it for later processing, skip lyxml_free() */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4167 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4168 | } else if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4169 | if (!(node = read_yin_container(module, retval, sub, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4170 | goto error; |
| 4171 | } |
| 4172 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4173 | if (!(node = read_yin_leaflist(module, retval, sub, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4174 | goto error; |
| 4175 | } |
| 4176 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4177 | if (!(node = read_yin_leaf(module, retval, sub, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4178 | goto error; |
| 4179 | } |
| 4180 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4181 | if (!(node = read_yin_list(module, retval, sub, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4182 | goto error; |
| 4183 | } |
| 4184 | } else if (!strcmp(sub->name, "case")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4185 | if (!(node = read_yin_case(module, retval, sub, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4186 | goto error; |
| 4187 | } |
| 4188 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4189 | if (!(node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres))) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4190 | goto error; |
| 4191 | } |
| 4192 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4193 | if (!(node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4194 | goto error; |
| 4195 | } |
| 4196 | } else if (!strcmp(sub->name, "default")) { |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4197 | if (dflt) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4198 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4199 | goto error; |
| 4200 | } |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4201 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4202 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_DEFAULT, 0, unres)) { |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4203 | goto error; |
| 4204 | } |
| 4205 | |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4206 | dflt = sub; |
| 4207 | lyxml_unlink_elem(ctx, dflt, 0); |
Radek Krejci | f9a312c | 2016-06-06 15:14:30 +0200 | [diff] [blame] | 4208 | continue; |
| 4209 | /* skip lyxml_free() at the end of the loop, the sub node is processed later as dflt */ |
| 4210 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4211 | } else if (!strcmp(sub->name, "mandatory")) { |
| 4212 | if (f_mand) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4213 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4214 | goto error; |
| 4215 | } |
| 4216 | /* just checking the flags in leaf is not sufficient, we would allow |
| 4217 | * multiple mandatory statements with the "false" value |
| 4218 | */ |
| 4219 | f_mand = 1; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4220 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4221 | GETVAL(value, sub, "value"); |
| 4222 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4223 | choice->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4224 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4225 | choice->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4226 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4227 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4228 | goto error; |
| 4229 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4230 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4231 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MANDATORY, 0, unres)) { |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4232 | goto error; |
| 4233 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4234 | } else if (!strcmp(sub->name, "when")) { |
| 4235 | if (choice->when) { |
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 | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4237 | goto error; |
| 4238 | } |
| 4239 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4240 | choice->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4241 | if (!choice->when) { |
| 4242 | goto error; |
| 4243 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4244 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4245 | c_ftrs++; |
| 4246 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4247 | /* 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] | 4248 | continue; |
Radek Krejci | 2f792db | 2016-09-12 10:52:33 +0200 | [diff] [blame] | 4249 | } else if (module->version >= 2 && !strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4250 | if (!(node = read_yin_choice(module, retval, sub, options, unres))) { |
Radek Krejci | 2f792db | 2016-09-12 10:52:33 +0200 | [diff] [blame] | 4251 | goto error; |
| 4252 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4253 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4254 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4255 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4256 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4257 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4258 | node = NULL; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4259 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4260 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4261 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4262 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4263 | choice->iffeature = calloc(c_ftrs, sizeof *choice->iffeature); |
| 4264 | if (!choice->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4265 | LOGMEM; |
| 4266 | goto error; |
| 4267 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4268 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4269 | if (c_ext) { |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4270 | /* some extensions may be already present from the substatements */ |
| 4271 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 4272 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4273 | LOGMEM; |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4274 | goto error; |
| 4275 | } |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4276 | retval->ext = reallocated; |
| 4277 | |
| 4278 | /* init memory */ |
| 4279 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4280 | } |
| 4281 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4282 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4283 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4284 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4285 | 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] | 4286 | retval->ext_size++; |
| 4287 | if (ret) { |
| 4288 | goto error; |
| 4289 | } |
| 4290 | } else { |
| 4291 | ret = fill_yin_iffeature(retval, 0, sub, &choice->iffeature[choice->iffeature_size], unres); |
| 4292 | choice->iffeature_size++; |
| 4293 | if (ret) { |
| 4294 | goto error; |
| 4295 | } |
| 4296 | } |
| 4297 | } |
| 4298 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4299 | /* check - default is prohibited in combination with mandatory */ |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4300 | if (dflt && (choice->flags & LYS_MAND_TRUE)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4301 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "default", "choice"); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4302 | 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] | 4303 | goto error; |
| 4304 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4305 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4306 | /* link default with the case */ |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4307 | if (dflt) { |
| 4308 | GETVAL(value, dflt, "value"); |
| 4309 | 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] | 4310 | goto error; |
| 4311 | } |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4312 | lyxml_free(ctx, dflt); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4313 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4314 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4315 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4316 | if (choice->when) { |
| 4317 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame^] | 4318 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4319 | goto error; |
| 4320 | } |
| 4321 | } else { |
| 4322 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 4323 | goto error; |
| 4324 | } |
| 4325 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4326 | } |
| 4327 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4328 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4329 | |
| 4330 | error: |
| 4331 | |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4332 | lyxml_free(ctx, dflt); |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4333 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4334 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4335 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4336 | } |
| 4337 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4338 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4339 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4340 | read_yin_anydata(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, LYS_NODE type, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4341 | int options, struct unres_schema *unres) |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4342 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4343 | struct lys_node *retval; |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4344 | struct lys_node_anydata *anyxml; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4345 | struct lyxml_elem *sub, *next; |
| 4346 | const char *value; |
| 4347 | int r; |
| 4348 | int f_mand = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4349 | int c_must = 0, c_ftrs = 0, c_ext = 0; |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4350 | void *reallocated; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4351 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4352 | anyxml = calloc(1, sizeof *anyxml); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4353 | if (!anyxml) { |
| 4354 | LOGMEM; |
| 4355 | return NULL; |
| 4356 | } |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4357 | anyxml->nodetype = type; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4358 | anyxml->prev = (struct lys_node *)anyxml; |
| 4359 | retval = (struct lys_node *)anyxml; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4360 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4361 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4362 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
| 4363 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), |
| 4364 | unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4365 | goto error; |
| 4366 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4367 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 4368 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4369 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4370 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4371 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4372 | goto error; |
| 4373 | } |
| 4374 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4375 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4376 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4377 | /* extension */ |
| 4378 | c_ext++; |
| 4379 | } else if (!strcmp(sub->name, "mandatory")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4380 | if (f_mand) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4381 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4382 | goto error; |
| 4383 | } |
| 4384 | /* just checking the flags in leaf is not sufficient, we would allow |
| 4385 | * multiple mandatory statements with the "false" value |
| 4386 | */ |
| 4387 | f_mand = 1; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4388 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4389 | GETVAL(value, sub, "value"); |
| 4390 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4391 | anyxml->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4392 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4393 | anyxml->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4394 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4395 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4396 | goto error; |
| 4397 | } |
| 4398 | /* else false is the default value, so we can ignore it */ |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4399 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4400 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MANDATORY, 0, unres)) { |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4401 | goto error; |
| 4402 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4403 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4404 | } else if (!strcmp(sub->name, "when")) { |
| 4405 | if (anyxml->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4406 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4407 | goto error; |
| 4408 | } |
| 4409 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4410 | anyxml->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4411 | if (!anyxml->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4412 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4413 | goto error; |
| 4414 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4415 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4416 | } else if (!strcmp(sub->name, "must")) { |
| 4417 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4418 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4419 | c_ftrs++; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4420 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4421 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4422 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4423 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4424 | } |
| 4425 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4426 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4427 | /* middle part - process nodes with cardinality of 0..n */ |
| 4428 | if (c_must) { |
| 4429 | anyxml->must = calloc(c_must, sizeof *anyxml->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4430 | if (!anyxml->must) { |
| 4431 | LOGMEM; |
| 4432 | goto error; |
| 4433 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4434 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4435 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4436 | anyxml->iffeature = calloc(c_ftrs, sizeof *anyxml->iffeature); |
| 4437 | if (!anyxml->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4438 | LOGMEM; |
| 4439 | goto error; |
| 4440 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4441 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4442 | if (c_ext) { |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4443 | /* some extensions may be already present from the substatements */ |
| 4444 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 4445 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4446 | LOGMEM; |
| 4447 | goto error; |
| 4448 | } |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4449 | retval->ext = reallocated; |
| 4450 | |
| 4451 | /* init memory */ |
| 4452 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4453 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4454 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4455 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4456 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4457 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4458 | 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] | 4459 | retval->ext_size++; |
| 4460 | if (r) { |
| 4461 | goto error; |
| 4462 | } |
| 4463 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4464 | r = fill_yin_must(module, sub, &anyxml->must[anyxml->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4465 | anyxml->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4466 | if (r) { |
| 4467 | goto error; |
| 4468 | } |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 4469 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 4470 | 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] | 4471 | anyxml->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4472 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4473 | goto error; |
| 4474 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4475 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4476 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4477 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4478 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4479 | if (anyxml->when || anyxml->must) { |
| 4480 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame^] | 4481 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4482 | goto error; |
| 4483 | } |
| 4484 | } else { |
| 4485 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 4486 | goto error; |
| 4487 | } |
| 4488 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4489 | } |
| 4490 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4491 | return retval; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4492 | |
| 4493 | error: |
| 4494 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4495 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4496 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4497 | return NULL; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4498 | } |
| 4499 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4500 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4501 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4502 | read_yin_leaf(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int options, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4503 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4504 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4505 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4506 | struct lys_node_leaf *leaf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4507 | struct lyxml_elem *sub, *next; |
| 4508 | const char *value; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4509 | int r, has_type = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4510 | 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] | 4511 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4512 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4513 | leaf = calloc(1, sizeof *leaf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4514 | if (!leaf) { |
| 4515 | LOGMEM; |
| 4516 | return NULL; |
| 4517 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4518 | leaf->nodetype = LYS_LEAF; |
| 4519 | leaf->prev = (struct lys_node *)leaf; |
| 4520 | retval = (struct lys_node *)leaf; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4521 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4522 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4523 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
| 4524 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), |
| 4525 | unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4526 | goto error; |
| 4527 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4528 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 4529 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4530 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4531 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4532 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4533 | goto error; |
| 4534 | } |
| 4535 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4536 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4537 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4538 | /* extension */ |
| 4539 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4540 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4541 | } else if (!strcmp(sub->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 4542 | if (has_type) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4543 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4544 | goto error; |
| 4545 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4546 | /* HACK for unres */ |
| 4547 | leaf->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 4548 | leaf->type.parent = (struct lys_tpdf *)leaf; |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4549 | /* postpone type resolution when if-feature parsing is done since we need |
| 4550 | * if-feature for check_leafref_features() */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4551 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4552 | } else if (!strcmp(sub->name, "default")) { |
| 4553 | if (leaf->dflt) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4554 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4555 | goto error; |
| 4556 | } |
| 4557 | GETVAL(value, sub, "value"); |
| 4558 | leaf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 1abcdae | 2017-01-18 14:14:18 +0100 | [diff] [blame] | 4559 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4560 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_DEFAULT, 0, unres)) { |
Radek Krejci | 1abcdae | 2017-01-18 14:14:18 +0100 | [diff] [blame] | 4561 | goto error; |
| 4562 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4563 | } else if (!strcmp(sub->name, "units")) { |
| 4564 | if (leaf->units) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4565 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4566 | goto error; |
| 4567 | } |
| 4568 | GETVAL(value, sub, "name"); |
| 4569 | leaf->units = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4570 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4571 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_UNITS, 0, unres)) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4572 | goto error; |
| 4573 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4574 | } else if (!strcmp(sub->name, "mandatory")) { |
| 4575 | if (f_mand) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4576 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4577 | goto error; |
| 4578 | } |
| 4579 | /* just checking the flags in leaf is not sufficient, we would allow |
| 4580 | * multiple mandatory statements with the "false" value |
| 4581 | */ |
| 4582 | f_mand = 1; |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4583 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4584 | GETVAL(value, sub, "value"); |
| 4585 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4586 | leaf->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4587 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4588 | leaf->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4589 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4590 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4591 | goto error; |
| 4592 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4593 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4594 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MANDATORY, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4595 | goto error; |
| 4596 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4597 | } else if (!strcmp(sub->name, "when")) { |
| 4598 | if (leaf->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4599 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4600 | goto error; |
| 4601 | } |
| 4602 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4603 | leaf->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4604 | if (!leaf->when) { |
| 4605 | goto error; |
| 4606 | } |
| 4607 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4608 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4609 | c_must++; |
| 4610 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4611 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4612 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4613 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4614 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4615 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4616 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4617 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4618 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4619 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4620 | /* 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] | 4621 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4622 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4623 | /* check mandatory parameters */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4624 | if (!has_type) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4625 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_LYS, retval, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4626 | goto error; |
| 4627 | } |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 4628 | if (leaf->dflt && (leaf->flags & LYS_MAND_TRUE)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4629 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "mandatory", "leaf"); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4630 | LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 4631 | "The \"mandatory\" statement is forbidden on leaf with the \"default\" statement."); |
| 4632 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4633 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4634 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4635 | /* middle part - process nodes with cardinality of 0..n */ |
| 4636 | if (c_must) { |
| 4637 | leaf->must = calloc(c_must, sizeof *leaf->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4638 | if (!leaf->must) { |
| 4639 | LOGMEM; |
| 4640 | goto error; |
| 4641 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4642 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4643 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4644 | leaf->iffeature = calloc(c_ftrs, sizeof *leaf->iffeature); |
| 4645 | if (!leaf->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4646 | LOGMEM; |
| 4647 | goto error; |
| 4648 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4649 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4650 | if (c_ext) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4651 | /* some extensions may be already present from the substatements */ |
| 4652 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 4653 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4654 | LOGMEM; |
| 4655 | goto error; |
| 4656 | } |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4657 | retval->ext = reallocated; |
| 4658 | |
| 4659 | /* init memory */ |
| 4660 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4661 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4662 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4663 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4664 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4665 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4666 | 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] | 4667 | retval->ext_size++; |
| 4668 | if (r) { |
| 4669 | goto error; |
| 4670 | } |
| 4671 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4672 | r = fill_yin_must(module, sub, &leaf->must[leaf->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4673 | leaf->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4674 | if (r) { |
| 4675 | goto error; |
| 4676 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4677 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 4678 | 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] | 4679 | leaf->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4680 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4681 | goto error; |
| 4682 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4683 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4684 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4685 | |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4686 | /* finalize type parsing */ |
| 4687 | if (unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DER, retval) == -1) { |
| 4688 | leaf->type.der = NULL; |
| 4689 | goto error; |
| 4690 | } |
| 4691 | |
| 4692 | /* check default value (if not defined, there still could be some restrictions |
| 4693 | * that need to be checked against a default value from a derived type) */ |
Radek Krejci | ab08f0f | 2017-03-09 16:37:15 +0100 | [diff] [blame] | 4694 | if (!(options & LYS_PARSE_OPT_INGRP) && |
| 4695 | (unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DFLT, |
| 4696 | (struct lys_node *)(&leaf->dflt)) == -1)) { |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4697 | goto error; |
| 4698 | } |
| 4699 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4700 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4701 | if (leaf->when || leaf->must) { |
| 4702 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame^] | 4703 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4704 | goto error; |
| 4705 | } |
| 4706 | } else { |
| 4707 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 4708 | goto error; |
| 4709 | } |
| 4710 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4711 | } |
| 4712 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4713 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4714 | |
| 4715 | error: |
| 4716 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4717 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4718 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4719 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4720 | } |
| 4721 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4722 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4723 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4724 | read_yin_leaflist(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int options, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4725 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4726 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4727 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4728 | struct lys_node_leaflist *llist; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4729 | struct lyxml_elem *sub, *next; |
| 4730 | const char *value; |
| 4731 | char *endptr; |
| 4732 | unsigned long val; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4733 | int r, has_type = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4734 | 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] | 4735 | int f_ordr = 0, f_min = 0, f_max = 0; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4736 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4737 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4738 | llist = calloc(1, sizeof *llist); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4739 | if (!llist) { |
| 4740 | LOGMEM; |
| 4741 | return NULL; |
| 4742 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4743 | llist->nodetype = LYS_LEAFLIST; |
| 4744 | llist->prev = (struct lys_node *)llist; |
| 4745 | retval = (struct lys_node *)llist; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4746 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4747 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4748 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
| 4749 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), |
| 4750 | unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4751 | goto error; |
| 4752 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4753 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 4754 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4755 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4756 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4757 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4758 | goto error; |
| 4759 | } |
| 4760 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4761 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4762 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4763 | /* extension */ |
| 4764 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4765 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4766 | } else if (!strcmp(sub->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 4767 | if (has_type) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4768 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4769 | goto error; |
| 4770 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4771 | /* HACK for unres */ |
| 4772 | llist->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 4773 | llist->type.parent = (struct lys_tpdf *)llist; |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4774 | /* postpone type resolution when if-feature parsing is done since we need |
| 4775 | * if-feature for check_leafref_features() */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4776 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4777 | } else if (!strcmp(sub->name, "units")) { |
| 4778 | if (llist->units) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4779 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4780 | goto error; |
| 4781 | } |
| 4782 | GETVAL(value, sub, "name"); |
| 4783 | llist->units = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4784 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4785 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_UNITS, 0, unres)) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4786 | goto error; |
| 4787 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4788 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 4789 | if (f_ordr) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4790 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4791 | goto error; |
| 4792 | } |
| 4793 | /* just checking the flags in llist is not sufficient, we would |
| 4794 | * allow multiple ordered-by statements with the "system" value |
| 4795 | */ |
| 4796 | f_ordr = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4797 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4798 | if (llist->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4799 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 4800 | * state data |
| 4801 | */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4802 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4803 | continue; |
| 4804 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4805 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4806 | GETVAL(value, sub, "value"); |
| 4807 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4808 | llist->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4809 | } else if (strcmp(value, "system")) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4810 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4811 | goto error; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4812 | } /* else system is the default value, so we can ignore it */ |
| 4813 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4814 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_ORDEREDBY, 0, unres)) { |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 4815 | goto error; |
| 4816 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4817 | } else if (!strcmp(sub->name, "must")) { |
| 4818 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4819 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4820 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4821 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4822 | continue; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4823 | } else if ((module->version >= 2) && !strcmp(sub->name, "default")) { |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 4824 | /* read the default's extension instances */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4825 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_DEFAULT, c_dflt, unres)) { |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 4826 | goto error; |
| 4827 | } |
| 4828 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4829 | c_dflt++; |
| 4830 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4831 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4832 | } else if (!strcmp(sub->name, "min-elements")) { |
| 4833 | if (f_min) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4834 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4835 | goto error; |
| 4836 | } |
| 4837 | f_min = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4838 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4839 | GETVAL(value, sub, "value"); |
| 4840 | while (isspace(value[0])) { |
| 4841 | value++; |
| 4842 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4843 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4844 | /* convert it to uint32_t */ |
| 4845 | errno = 0; |
| 4846 | endptr = NULL; |
| 4847 | val = strtoul(value, &endptr, 10); |
| 4848 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4849 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4850 | goto error; |
| 4851 | } |
| 4852 | llist->min = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 4853 | if (llist->max && (llist->min > llist->max)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4854 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4855 | 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] | 4856 | goto error; |
| 4857 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4858 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4859 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MIN, 0, unres)) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4860 | goto error; |
| 4861 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4862 | } else if (!strcmp(sub->name, "max-elements")) { |
| 4863 | if (f_max) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4864 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4865 | goto error; |
| 4866 | } |
| 4867 | f_max = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4868 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4869 | GETVAL(value, sub, "value"); |
| 4870 | while (isspace(value[0])) { |
| 4871 | value++; |
| 4872 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4873 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 4874 | if (!strcmp(value, "unbounded")) { |
| 4875 | llist->max = 0; |
| 4876 | } else { |
| 4877 | /* convert it to uint32_t */ |
| 4878 | errno = 0; |
| 4879 | endptr = NULL; |
| 4880 | val = strtoul(value, &endptr, 10); |
| 4881 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4882 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 4883 | goto error; |
| 4884 | } |
| 4885 | llist->max = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 4886 | if (llist->min > llist->max) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4887 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4888 | 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] | 4889 | goto error; |
| 4890 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4891 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4892 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4893 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MAX, 0, unres)) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4894 | goto error; |
| 4895 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4896 | } else if (!strcmp(sub->name, "when")) { |
| 4897 | if (llist->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4898 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4899 | goto error; |
| 4900 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4901 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4902 | llist->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4903 | if (!llist->when) { |
| 4904 | goto error; |
| 4905 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4906 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4907 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4908 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4909 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4910 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4911 | /* 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] | 4912 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4913 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4914 | /* check constraints */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4915 | if (!has_type) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4916 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_LYS, retval, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4917 | goto error; |
| 4918 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4919 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4920 | /* middle part - process nodes with cardinality of 0..n */ |
| 4921 | if (c_must) { |
| 4922 | llist->must = calloc(c_must, sizeof *llist->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4923 | if (!llist->must) { |
| 4924 | LOGMEM; |
| 4925 | goto error; |
| 4926 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4927 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4928 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4929 | llist->iffeature = calloc(c_ftrs, sizeof *llist->iffeature); |
| 4930 | if (!llist->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4931 | LOGMEM; |
| 4932 | goto error; |
| 4933 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4934 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4935 | if (c_dflt) { |
| 4936 | llist->dflt = calloc(c_dflt, sizeof *llist->dflt); |
| 4937 | if (!llist->dflt) { |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4938 | LOGMEM; |
| 4939 | goto error; |
| 4940 | } |
| 4941 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4942 | if (c_ext) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4943 | /* some extensions may be already present from the substatements */ |
| 4944 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 4945 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4946 | LOGMEM; |
| 4947 | goto error; |
| 4948 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4949 | retval->ext = reallocated; |
| 4950 | |
| 4951 | /* init memory */ |
| 4952 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4953 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4954 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4955 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4956 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4957 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4958 | 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] | 4959 | retval->ext_size++; |
| 4960 | if (r) { |
| 4961 | goto error; |
| 4962 | } |
| 4963 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4964 | r = fill_yin_must(module, sub, &llist->must[llist->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4965 | llist->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4966 | if (r) { |
| 4967 | goto error; |
| 4968 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4969 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 4970 | 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] | 4971 | llist->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4972 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4973 | goto error; |
| 4974 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4975 | } else if (!strcmp(sub->name, "default")) { |
| 4976 | GETVAL(value, sub, "value"); |
| 4977 | |
Radek Krejci | ac1a52c | 2016-09-15 14:42:40 +0200 | [diff] [blame] | 4978 | /* check for duplicity in case of configuration data, |
| 4979 | * in case of status data duplicities are allowed */ |
| 4980 | if (llist->flags & LYS_CONFIG_W) { |
| 4981 | for (r = 0; r < llist->dflt_size; r++) { |
| 4982 | if (ly_strequal(llist->dflt[r], value, 1)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4983 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, "default"); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4984 | LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "Duplicated default value \"%s\".", value); |
Radek Krejci | ac1a52c | 2016-09-15 14:42:40 +0200 | [diff] [blame] | 4985 | goto error; |
| 4986 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4987 | } |
| 4988 | } |
| 4989 | llist->dflt[llist->dflt_size++] = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4990 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4991 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4992 | |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4993 | /* finalize type parsing */ |
| 4994 | if (unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DER, retval) == -1) { |
| 4995 | llist->type.der = NULL; |
| 4996 | goto error; |
| 4997 | } |
| 4998 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4999 | if (llist->dflt_size && llist->min) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5000 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "min-elements", "leaf-list"); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 5001 | LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 5002 | "The \"min-elements\" statement with non-zero value is forbidden on leaf-lists with the \"default\" statement."); |
| 5003 | goto error; |
| 5004 | } |
| 5005 | |
| 5006 | /* check default value (if not defined, there still could be some restrictions |
| 5007 | * that need to be checked against a default value from a derived type) */ |
| 5008 | for (r = 0; r < llist->dflt_size; r++) { |
Radek Krejci | ab08f0f | 2017-03-09 16:37:15 +0100 | [diff] [blame] | 5009 | if (!(options & LYS_PARSE_OPT_INGRP) && |
| 5010 | (unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DFLT, |
| 5011 | (struct lys_node *)(&llist->dflt[r])) == -1)) { |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 5012 | goto error; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 5013 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5014 | } |
| 5015 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5016 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5017 | if (llist->when || llist->must) { |
| 5018 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame^] | 5019 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5020 | goto error; |
| 5021 | } |
| 5022 | } else { |
| 5023 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 5024 | goto error; |
| 5025 | } |
| 5026 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5027 | } |
| 5028 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5029 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5030 | |
| 5031 | error: |
| 5032 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5033 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5034 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5035 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5036 | } |
| 5037 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5038 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5039 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5040 | read_yin_list(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int options, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 5041 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5042 | { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5043 | struct lys_node *retval, *node; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5044 | struct lys_node_list *list; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5045 | struct lyxml_elem *sub, *next, root, uniq; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5046 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5047 | 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] | 5048 | int f_ordr = 0, f_max = 0, f_min = 0; |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 5049 | const char *value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5050 | char *auxs; |
| 5051 | unsigned long val; |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5052 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5053 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5054 | /* init */ |
| 5055 | memset(&root, 0, sizeof root); |
| 5056 | memset(&uniq, 0, sizeof uniq); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5057 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5058 | list = calloc(1, sizeof *list); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5059 | if (!list) { |
| 5060 | LOGMEM; |
| 5061 | return NULL; |
| 5062 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5063 | list->nodetype = LYS_LIST; |
| 5064 | list->prev = (struct lys_node *)list; |
| 5065 | retval = (struct lys_node *)list; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5066 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5067 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5068 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
| 5069 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), |
| 5070 | unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5071 | goto error; |
| 5072 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5073 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 5074 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5075 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5076 | /* insert the node into the schema tree */ |
| 5077 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5078 | goto error; |
| 5079 | } |
| 5080 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5081 | /* process list's specific children */ |
| 5082 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5083 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5084 | /* extension */ |
| 5085 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5086 | continue; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5087 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5088 | /* data statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5089 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5090 | !strcmp(sub->name, "leaf-list") || |
| 5091 | !strcmp(sub->name, "leaf") || |
| 5092 | !strcmp(sub->name, "list") || |
| 5093 | !strcmp(sub->name, "choice") || |
| 5094 | !strcmp(sub->name, "uses") || |
| 5095 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5096 | !strcmp(sub->name, "anyxml") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 5097 | !strcmp(sub->name, "anydata") || |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 5098 | !strcmp(sub->name, "action") || |
| 5099 | !strcmp(sub->name, "notification")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5100 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5101 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5102 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5103 | /* array counters */ |
| 5104 | } else if (!strcmp(sub->name, "key")) { |
| 5105 | /* check cardinality 0..1 */ |
| 5106 | if (list->keys_size) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5107 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, list->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5108 | goto error; |
| 5109 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5110 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5111 | /* count the number of keys */ |
| 5112 | GETVAL(value, sub, "value"); |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 5113 | list->keys_str = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5114 | while ((value = strpbrk(value, " \t\n"))) { |
| 5115 | list->keys_size++; |
| 5116 | while (isspace(*value)) { |
| 5117 | value++; |
| 5118 | } |
| 5119 | } |
| 5120 | list->keys_size++; |
| 5121 | list->keys = calloc(list->keys_size, sizeof *list->keys); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5122 | if (!list->keys) { |
| 5123 | LOGMEM; |
| 5124 | goto error; |
| 5125 | } |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5126 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5127 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_KEY, 0, unres)) { |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5128 | goto error; |
| 5129 | } |
| 5130 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5131 | } else if (!strcmp(sub->name, "unique")) { |
| 5132 | c_uniq++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5133 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5134 | lyxml_add_child(module->ctx, &uniq, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5135 | } else if (!strcmp(sub->name, "typedef")) { |
| 5136 | c_tpdf++; |
| 5137 | } else if (!strcmp(sub->name, "must")) { |
| 5138 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5139 | } else if (!strcmp(sub->name, "if-feature")) { |
| 5140 | c_ftrs++; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5141 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5142 | /* optional stetments */ |
| 5143 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 5144 | if (f_ordr) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5145 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5146 | goto error; |
| 5147 | } |
| 5148 | /* just checking the flags in llist is not sufficient, we would |
| 5149 | * allow multiple ordered-by statements with the "system" value |
| 5150 | */ |
| 5151 | f_ordr = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5152 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 5153 | if (list->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5154 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 5155 | * state data |
| 5156 | */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5157 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5158 | continue; |
| 5159 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5160 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5161 | GETVAL(value, sub, "value"); |
| 5162 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 5163 | list->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5164 | } else if (strcmp(value, "system")) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5165 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5166 | goto error; |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5167 | } /* else system is the default value, so we can ignore it */ |
| 5168 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5169 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_ORDEREDBY, 0, unres)) { |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5170 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5171 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5172 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5173 | } else if (!strcmp(sub->name, "min-elements")) { |
| 5174 | if (f_min) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5175 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5176 | goto error; |
| 5177 | } |
| 5178 | f_min = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5179 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5180 | GETVAL(value, sub, "value"); |
| 5181 | while (isspace(value[0])) { |
| 5182 | value++; |
| 5183 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5184 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5185 | /* convert it to uint32_t */ |
| 5186 | errno = 0; |
| 5187 | auxs = NULL; |
| 5188 | val = strtoul(value, &auxs, 10); |
| 5189 | if (*auxs || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5190 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5191 | goto error; |
| 5192 | } |
| 5193 | list->min = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 5194 | if (list->max && (list->min > list->max)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5195 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 5196 | 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] | 5197 | lyxml_free(module->ctx, sub); |
| 5198 | goto error; |
| 5199 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5200 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MIN, 0, unres)) { |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5201 | goto error; |
| 5202 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5203 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5204 | } else if (!strcmp(sub->name, "max-elements")) { |
| 5205 | if (f_max) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5206 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5207 | goto error; |
| 5208 | } |
| 5209 | f_max = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5210 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5211 | GETVAL(value, sub, "value"); |
| 5212 | while (isspace(value[0])) { |
| 5213 | value++; |
| 5214 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5215 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 5216 | if (!strcmp(value, "unbounded")) { |
| 5217 | list->max = 0;; |
| 5218 | } else { |
| 5219 | /* convert it to uint32_t */ |
| 5220 | errno = 0; |
| 5221 | auxs = NULL; |
| 5222 | val = strtoul(value, &auxs, 10); |
| 5223 | if (*auxs || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5224 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 5225 | goto error; |
| 5226 | } |
| 5227 | list->max = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 5228 | if (list->min > list->max) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5229 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 5230 | 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] | 5231 | goto error; |
| 5232 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5233 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5234 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_MAX, 0, unres)) { |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5235 | goto error; |
| 5236 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5237 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5238 | } else if (!strcmp(sub->name, "when")) { |
| 5239 | if (list->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5240 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5241 | goto error; |
| 5242 | } |
| 5243 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 5244 | list->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5245 | if (!list->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5246 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5247 | goto error; |
| 5248 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5249 | lyxml_free(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5250 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5251 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5252 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5253 | } |
| 5254 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5255 | |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5256 | /* check - if list is configuration, key statement is mandatory |
| 5257 | * (but only if we are not in a grouping or augment, then the check is deferred) */ |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 5258 | for (node = retval; node && !(node->nodetype & (LYS_GROUPING | LYS_AUGMENT | LYS_EXT)); node = node->parent); |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 5259 | if (!node && (list->flags & LYS_CONFIG_W) && !list->keys_str) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5260 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_LYS, retval, "key", "list"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5261 | goto error; |
| 5262 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5263 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5264 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5265 | if (c_tpdf) { |
| 5266 | list->tpdf = calloc(c_tpdf, sizeof *list->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5267 | if (!list->tpdf) { |
| 5268 | LOGMEM; |
| 5269 | goto error; |
| 5270 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5271 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5272 | if (c_must) { |
| 5273 | list->must = calloc(c_must, sizeof *list->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5274 | if (!list->must) { |
| 5275 | LOGMEM; |
| 5276 | goto error; |
| 5277 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5278 | } |
| 5279 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5280 | list->iffeature = calloc(c_ftrs, sizeof *list->iffeature); |
| 5281 | if (!list->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5282 | LOGMEM; |
| 5283 | goto error; |
| 5284 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5285 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5286 | if (c_ext) { |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5287 | /* some extensions may be already present from the substatements */ |
| 5288 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 5289 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5290 | LOGMEM; |
| 5291 | goto error; |
| 5292 | } |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5293 | retval->ext = reallocated; |
| 5294 | |
| 5295 | /* init memory */ |
| 5296 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5297 | } |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5298 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5299 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5300 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5301 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5302 | 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] | 5303 | retval->ext_size++; |
| 5304 | if (r) { |
| 5305 | goto error; |
| 5306 | } |
| 5307 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5308 | r = fill_yin_typedef(module, retval, sub, &list->tpdf[list->tpdf_size], unres); |
| 5309 | list->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5310 | if (r) { |
| 5311 | goto error; |
| 5312 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5313 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 5314 | 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] | 5315 | list->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 5316 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 5317 | goto error; |
| 5318 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5319 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5320 | r = fill_yin_must(module, sub, &list->must[list->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5321 | list->must_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5322 | if (r) { |
| 5323 | goto error; |
| 5324 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5325 | } |
| 5326 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5327 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5328 | /* last part - process data nodes */ |
| 5329 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5330 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5331 | node = read_yin_container(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5332 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5333 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5334 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5335 | node = read_yin_leaf(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5336 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5337 | node = read_yin_list(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5338 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5339 | node = read_yin_choice(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5340 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5341 | node = read_yin_uses(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5342 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5343 | node = read_yin_grouping(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5344 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5345 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5346 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5347 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5348 | } else if (!strcmp(sub->name, "action")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5349 | node = read_yin_rpc_action(module, retval, sub, options, unres); |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 5350 | } else if (!strcmp(sub->name, "notification")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5351 | node = read_yin_notif(module, retval, sub, options, unres); |
Michal Vasko | c07187d | 2015-08-13 15:20:57 +0200 | [diff] [blame] | 5352 | } else { |
| 5353 | LOGINT; |
| 5354 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5355 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5356 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5357 | goto error; |
| 5358 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5359 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5360 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5361 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5362 | |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 5363 | if (list->keys_str) { |
| 5364 | /* check that we are not in grouping */ |
| 5365 | for (node = parent; node && node->nodetype != LYS_GROUPING; node = lys_parent(node)); |
| 5366 | 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] | 5367 | goto error; |
| 5368 | } |
| 5369 | } /* 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] | 5370 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5371 | /* process unique statements */ |
| 5372 | if (c_uniq) { |
| 5373 | list->unique = calloc(c_uniq, sizeof *list->unique); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5374 | if (!list->unique) { |
| 5375 | LOGMEM; |
| 5376 | goto error; |
| 5377 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 5378 | |
Radek Krejci | 461efb9 | 2016-02-12 15:52:18 +0100 | [diff] [blame] | 5379 | LY_TREE_FOR_SAFE(uniq.child, next, sub) { |
| 5380 | r = fill_yin_unique(module, retval, sub, &list->unique[list->unique_size], unres); |
| 5381 | list->unique_size++; |
| 5382 | if (r) { |
| 5383 | goto error; |
| 5384 | } |
| 5385 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5386 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5387 | LYEXT_SUBSTMT_UNIQUE, list->unique_size - 1, unres)) { |
| 5388 | goto error; |
| 5389 | } |
Radek Krejci | 461efb9 | 2016-02-12 15:52:18 +0100 | [diff] [blame] | 5390 | lyxml_free(module->ctx, sub); |
| 5391 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5392 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 5393 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5394 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5395 | if (list->when || list->must) { |
| 5396 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame^] | 5397 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5398 | goto error; |
| 5399 | } |
| 5400 | } else { |
| 5401 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 5402 | goto error; |
| 5403 | } |
| 5404 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5405 | } |
| 5406 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5407 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5408 | |
| 5409 | error: |
| 5410 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5411 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5412 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5413 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5414 | } |
| 5415 | while (uniq.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5416 | lyxml_free(module->ctx, uniq.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5417 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5418 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5419 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5420 | } |
| 5421 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5422 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5423 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5424 | read_yin_container(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int options, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 5425 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5426 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5427 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5428 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5429 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5430 | struct lys_node_container *cont; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5431 | const char *value; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5432 | void *reallocated; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5433 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5434 | 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] | 5435 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5436 | /* init */ |
| 5437 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5438 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5439 | cont = calloc(1, sizeof *cont); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5440 | if (!cont) { |
| 5441 | LOGMEM; |
| 5442 | return NULL; |
| 5443 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5444 | cont->nodetype = LYS_CONTAINER; |
| 5445 | cont->prev = (struct lys_node *)cont; |
| 5446 | retval = (struct lys_node *)cont; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5447 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5448 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5449 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
| 5450 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), |
| 5451 | unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5452 | goto error; |
| 5453 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5454 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 5455 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5456 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5457 | /* insert the node into the schema tree */ |
| 5458 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5459 | goto error; |
| 5460 | } |
| 5461 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5462 | /* process container's specific children */ |
| 5463 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5464 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5465 | /* extension */ |
| 5466 | c_ext++; |
| 5467 | } else if (!strcmp(sub->name, "presence")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5468 | if (cont->presence) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5469 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5470 | goto error; |
| 5471 | } |
| 5472 | GETVAL(value, sub, "value"); |
| 5473 | cont->presence = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 5474 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5475 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_PRESENCE, 0, unres)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5476 | goto error; |
| 5477 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5478 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5479 | } else if (!strcmp(sub->name, "when")) { |
| 5480 | if (cont->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5481 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5482 | goto error; |
| 5483 | } |
| 5484 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 5485 | cont->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5486 | if (!cont->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5487 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5488 | goto error; |
| 5489 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5490 | lyxml_free(module->ctx, sub); |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 5491 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5492 | /* data statements */ |
| 5493 | } else if (!strcmp(sub->name, "container") || |
| 5494 | !strcmp(sub->name, "leaf-list") || |
| 5495 | !strcmp(sub->name, "leaf") || |
| 5496 | !strcmp(sub->name, "list") || |
| 5497 | !strcmp(sub->name, "choice") || |
| 5498 | !strcmp(sub->name, "uses") || |
| 5499 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5500 | !strcmp(sub->name, "anyxml") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 5501 | !strcmp(sub->name, "anydata") || |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 5502 | !strcmp(sub->name, "action") || |
| 5503 | !strcmp(sub->name, "notification")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5504 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5505 | lyxml_add_child(module->ctx, &root, sub); |
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 | /* array counters */ |
| 5508 | } else if (!strcmp(sub->name, "typedef")) { |
| 5509 | c_tpdf++; |
| 5510 | } else if (!strcmp(sub->name, "must")) { |
| 5511 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5512 | } else if (!strcmp(sub->name, "if-feature")) { |
| 5513 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5514 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5515 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5516 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5517 | } |
| 5518 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5519 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5520 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5521 | if (c_tpdf) { |
| 5522 | cont->tpdf = calloc(c_tpdf, sizeof *cont->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5523 | if (!cont->tpdf) { |
| 5524 | LOGMEM; |
| 5525 | goto error; |
| 5526 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5527 | } |
| 5528 | if (c_must) { |
| 5529 | cont->must = calloc(c_must, sizeof *cont->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5530 | if (!cont->must) { |
| 5531 | LOGMEM; |
| 5532 | goto error; |
| 5533 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5534 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5535 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5536 | cont->iffeature = calloc(c_ftrs, sizeof *cont->iffeature); |
| 5537 | if (!cont->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5538 | LOGMEM; |
| 5539 | goto error; |
| 5540 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5541 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5542 | if (c_ext) { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5543 | /* some extensions may be already present from the substatements */ |
| 5544 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 5545 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5546 | LOGMEM; |
| 5547 | goto error; |
| 5548 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5549 | retval->ext = reallocated; |
| 5550 | |
| 5551 | /* init memory */ |
| 5552 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5553 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 5554 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5555 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5556 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5557 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5558 | 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] | 5559 | retval->ext_size++; |
| 5560 | if (r) { |
| 5561 | goto error; |
| 5562 | } |
| 5563 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5564 | r = fill_yin_typedef(module, retval, sub, &cont->tpdf[cont->tpdf_size], unres); |
| 5565 | cont->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5566 | if (r) { |
| 5567 | goto error; |
| 5568 | } |
| 5569 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5570 | r = fill_yin_must(module, sub, &cont->must[cont->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5571 | cont->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5572 | if (r) { |
| 5573 | goto error; |
| 5574 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5575 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 5576 | 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] | 5577 | cont->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 5578 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 5579 | goto error; |
| 5580 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5581 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5582 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5583 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5584 | /* last part - process data nodes */ |
| 5585 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5586 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5587 | node = read_yin_container(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5588 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5589 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5590 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5591 | node = read_yin_leaf(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5592 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5593 | node = read_yin_list(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5594 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5595 | node = read_yin_choice(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5596 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5597 | node = read_yin_uses(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5598 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5599 | node = read_yin_grouping(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5600 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5601 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5602 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5603 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5604 | } else if (!strcmp(sub->name, "action")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5605 | node = read_yin_rpc_action(module, retval, sub, options, unres); |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 5606 | } else if (!strcmp(sub->name, "notification")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5607 | node = read_yin_notif(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5608 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5609 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5610 | goto error; |
| 5611 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5612 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5613 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5614 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5615 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5616 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5617 | if (cont->when || cont->must) { |
| 5618 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame^] | 5619 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5620 | goto error; |
| 5621 | } |
| 5622 | } else { |
| 5623 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 5624 | goto error; |
| 5625 | } |
| 5626 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5627 | } |
| 5628 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5629 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5630 | |
| 5631 | error: |
| 5632 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5633 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5634 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5635 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5636 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5637 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5638 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5639 | } |
| 5640 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5641 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5642 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5643 | read_yin_grouping(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int options, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 5644 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5645 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5646 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5647 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5648 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5649 | struct lys_node_grp *grp; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5650 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5651 | int c_tpdf = 0, c_ext = 0; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 5652 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5653 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5654 | /* init */ |
| 5655 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5656 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5657 | grp = calloc(1, sizeof *grp); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5658 | if (!grp) { |
| 5659 | LOGMEM; |
| 5660 | return NULL; |
| 5661 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5662 | grp->nodetype = LYS_GROUPING; |
| 5663 | grp->prev = (struct lys_node *)grp; |
| 5664 | retval = (struct lys_node *)grp; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5665 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5666 | 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] | 5667 | goto error; |
| 5668 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5669 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 5670 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5671 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5672 | /* insert the node into the schema tree */ |
| 5673 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5674 | goto error; |
| 5675 | } |
| 5676 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5677 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5678 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5679 | /* extension */ |
| 5680 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5681 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5682 | /* data statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5683 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5684 | !strcmp(sub->name, "leaf-list") || |
| 5685 | !strcmp(sub->name, "leaf") || |
| 5686 | !strcmp(sub->name, "list") || |
| 5687 | !strcmp(sub->name, "choice") || |
| 5688 | !strcmp(sub->name, "uses") || |
| 5689 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5690 | !strcmp(sub->name, "anyxml") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 5691 | !strcmp(sub->name, "anydata") || |
Michal Vasko | 5acb548 | 2016-09-16 14:35:14 +0200 | [diff] [blame] | 5692 | !strcmp(sub->name, "action") || |
| 5693 | !strcmp(sub->name, "notification")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5694 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5695 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5696 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5697 | /* array counters */ |
| 5698 | } else if (!strcmp(sub->name, "typedef")) { |
| 5699 | c_tpdf++; |
| 5700 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5701 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5702 | goto error; |
| 5703 | } |
| 5704 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5705 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5706 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5707 | if (c_tpdf) { |
| 5708 | grp->tpdf = calloc(c_tpdf, sizeof *grp->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5709 | if (!grp->tpdf) { |
| 5710 | LOGMEM; |
| 5711 | goto error; |
| 5712 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5713 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5714 | if (c_ext) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 5715 | /* some extensions may be already present from the substatements */ |
| 5716 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 5717 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5718 | LOGMEM; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5719 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5720 | } |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 5721 | retval->ext = reallocated; |
| 5722 | |
| 5723 | /* init memory */ |
| 5724 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5725 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5726 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5727 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5728 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5729 | 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] | 5730 | retval->ext_size++; |
| 5731 | if (r) { |
| 5732 | goto error; |
| 5733 | } |
| 5734 | } else { |
| 5735 | /* typedef */ |
| 5736 | r = fill_yin_typedef(module, retval, sub, &grp->tpdf[grp->tpdf_size], unres); |
| 5737 | grp->tpdf_size++; |
| 5738 | if (r) { |
| 5739 | goto error; |
| 5740 | } |
| 5741 | } |
| 5742 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5743 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5744 | /* last part - process data nodes */ |
Michal Vasko | 919dbbc | 2016-05-19 15:22:45 +0200 | [diff] [blame] | 5745 | if (!root.child) { |
| 5746 | LOGWRN("Grouping \"%s\" without children.", retval->name); |
| 5747 | } |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5748 | options |= LYS_PARSE_OPT_INGRP; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5749 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5750 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5751 | node = read_yin_container(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5752 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5753 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5754 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5755 | node = read_yin_leaf(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5756 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5757 | node = read_yin_list(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5758 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5759 | node = read_yin_choice(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5760 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5761 | node = read_yin_uses(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5762 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5763 | node = read_yin_grouping(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5764 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5765 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5766 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5767 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5768 | } else if (!strcmp(sub->name, "action")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5769 | node = read_yin_rpc_action(module, retval, sub, options, unres); |
Michal Vasko | 5acb548 | 2016-09-16 14:35:14 +0200 | [diff] [blame] | 5770 | } else if (!strcmp(sub->name, "notification")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5771 | node = read_yin_notif(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5772 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5773 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5774 | goto error; |
| 5775 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5776 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5777 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5778 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5779 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5780 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5781 | |
| 5782 | error: |
| 5783 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5784 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5785 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5786 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5787 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5788 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5789 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5790 | } |
| 5791 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5792 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5793 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5794 | read_yin_input_output(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5795 | int options, struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5796 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5797 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5798 | struct lys_node *node = NULL; |
Radek Krejci | 31fc30d | 2015-08-13 08:27:38 +0200 | [diff] [blame] | 5799 | struct lys_node *retval = NULL; |
Michal Vasko | 44fb638 | 2016-06-29 11:12:27 +0200 | [diff] [blame] | 5800 | struct lys_node_inout *inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5801 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5802 | int c_tpdf = 0, c_must = 0, c_ext = 0; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5803 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5804 | /* init */ |
| 5805 | memset(&root, 0, sizeof root); |
| 5806 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5807 | inout = calloc(1, sizeof *inout); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5808 | if (!inout) { |
| 5809 | LOGMEM; |
| 5810 | return NULL; |
| 5811 | } |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 5812 | inout->prev = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5813 | |
| 5814 | if (!strcmp(yin->name, "input")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5815 | inout->nodetype = LYS_INPUT; |
Michal Vasko | 0a1aaa4 | 2016-04-19 09:48:25 +0200 | [diff] [blame] | 5816 | inout->name = lydict_insert(module->ctx, "input", 0); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5817 | } else if (!strcmp(yin->name, "output")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5818 | inout->nodetype = LYS_OUTPUT; |
Michal Vasko | 0a1aaa4 | 2016-04-19 09:48:25 +0200 | [diff] [blame] | 5819 | inout->name = lydict_insert(module->ctx, "output", 0); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5820 | } else { |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 5821 | LOGINT; |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 5822 | free(inout); |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 5823 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5824 | } |
| 5825 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5826 | retval = (struct lys_node *)inout; |
Radek Krejci | e777089 | 2017-01-24 13:18:01 +0100 | [diff] [blame] | 5827 | retval->module = module; |
Michal Vasko | ebeac94 | 2015-06-15 12:11:50 +0200 | [diff] [blame] | 5828 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 5829 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5830 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5831 | /* insert the node into the schema tree */ |
| 5832 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5833 | goto error; |
| 5834 | } |
| 5835 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5836 | /* data statements */ |
| 5837 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e777089 | 2017-01-24 13:18:01 +0100 | [diff] [blame] | 5838 | if (!sub->ns) { |
| 5839 | /* garbage */ |
| 5840 | lyxml_free(module->ctx, sub); |
| 5841 | } else if (strcmp(sub->ns->value, LY_NSYIN)) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5842 | /* extension */ |
| 5843 | c_ext++; |
| 5844 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5845 | !strcmp(sub->name, "leaf-list") || |
| 5846 | !strcmp(sub->name, "leaf") || |
| 5847 | !strcmp(sub->name, "list") || |
| 5848 | !strcmp(sub->name, "choice") || |
| 5849 | !strcmp(sub->name, "uses") || |
| 5850 | !strcmp(sub->name, "grouping") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 5851 | !strcmp(sub->name, "anyxml") || |
| 5852 | !strcmp(sub->name, "anydata")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5853 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5854 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5855 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5856 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5857 | } else if (!strcmp(sub->name, "typedef")) { |
| 5858 | c_tpdf++; |
Radek Krejci | d2bfa79 | 2015-07-02 16:45:29 +0200 | [diff] [blame] | 5859 | |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 5860 | } else if ((module->version >= 2) && !strcmp(sub->name, "must")) { |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5861 | c_must++; |
| 5862 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5863 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5864 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5865 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5866 | } |
| 5867 | } |
| 5868 | |
| 5869 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5870 | if (c_tpdf) { |
| 5871 | inout->tpdf = calloc(c_tpdf, sizeof *inout->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5872 | if (!inout->tpdf) { |
| 5873 | LOGMEM; |
| 5874 | goto error; |
| 5875 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5876 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5877 | if (c_must) { |
| 5878 | inout->must = calloc(c_must, sizeof *inout->must); |
| 5879 | if (!inout->must) { |
| 5880 | LOGMEM; |
| 5881 | goto error; |
| 5882 | } |
| 5883 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5884 | if (c_ext) { |
| 5885 | inout->ext = calloc(c_ext, sizeof *inout->ext); |
| 5886 | if (!inout->ext) { |
| 5887 | LOGMEM; |
| 5888 | goto error; |
| 5889 | } |
| 5890 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5891 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5892 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5893 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5894 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5895 | 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] | 5896 | retval->ext_size++; |
| 5897 | if (r) { |
| 5898 | goto error; |
| 5899 | } |
| 5900 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5901 | r = fill_yin_must(module, sub, &inout->must[inout->must_size], unres); |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5902 | inout->must_size++; |
| 5903 | if (r) { |
| 5904 | goto error; |
| 5905 | } |
| 5906 | } else { /* typedef */ |
| 5907 | r = fill_yin_typedef(module, retval, sub, &inout->tpdf[inout->tpdf_size], unres); |
| 5908 | inout->tpdf_size++; |
| 5909 | if (r) { |
| 5910 | goto error; |
| 5911 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5912 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5913 | } |
| 5914 | |
| 5915 | /* last part - process data nodes */ |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5916 | options |= LYS_PARSE_OPT_CFG_IGNORE; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5917 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5918 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5919 | node = read_yin_container(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5920 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5921 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5922 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5923 | node = read_yin_leaf(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5924 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5925 | node = read_yin_list(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5926 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5927 | node = read_yin_choice(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5928 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5929 | node = read_yin_uses(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5930 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5931 | node = read_yin_grouping(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5932 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5933 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5934 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5935 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5936 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5937 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5938 | goto error; |
| 5939 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5940 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5941 | lyxml_free(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5942 | } |
| 5943 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5944 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5945 | if (inout->must) { |
| 5946 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame^] | 5947 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5948 | goto error; |
| 5949 | } |
| 5950 | } else { |
| 5951 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 5952 | goto error; |
| 5953 | } |
| 5954 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5955 | } |
| 5956 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5957 | return retval; |
| 5958 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5959 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5960 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5961 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 5962 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5963 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5964 | } |
| 5965 | |
| 5966 | return NULL; |
| 5967 | } |
| 5968 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5969 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5970 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5971 | read_yin_notif(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5972 | int options, struct unres_schema *unres) |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5973 | { |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 5974 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5975 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5976 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5977 | struct lys_node_notif *notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5978 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5979 | 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] | 5980 | void *reallocated; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5981 | |
Michal Vasko | 6bb7fc1 | 2016-09-21 14:17:22 +0200 | [diff] [blame] | 5982 | if (parent && (module->version < 2)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5983 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, parent, "notification"); |
Michal Vasko | 6bb7fc1 | 2016-09-21 14:17:22 +0200 | [diff] [blame] | 5984 | return NULL; |
| 5985 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5986 | |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 5987 | memset(&root, 0, sizeof root); |
| 5988 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5989 | notif = calloc(1, sizeof *notif); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5990 | if (!notif) { |
| 5991 | LOGMEM; |
| 5992 | return NULL; |
| 5993 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5994 | notif->nodetype = LYS_NOTIF; |
| 5995 | notif->prev = (struct lys_node *)notif; |
| 5996 | retval = (struct lys_node *)notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5997 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5998 | 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] | 5999 | goto error; |
| 6000 | } |
| 6001 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 6002 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6003 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 6004 | /* insert the node into the schema tree */ |
| 6005 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 6006 | goto error; |
| 6007 | } |
| 6008 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6009 | /* process rpc's specific children */ |
| 6010 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6011 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6012 | /* extension */ |
| 6013 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6014 | continue; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6015 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6016 | /* data statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6017 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6018 | !strcmp(sub->name, "leaf-list") || |
| 6019 | !strcmp(sub->name, "leaf") || |
| 6020 | !strcmp(sub->name, "list") || |
| 6021 | !strcmp(sub->name, "choice") || |
| 6022 | !strcmp(sub->name, "uses") || |
| 6023 | !strcmp(sub->name, "grouping") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 6024 | !strcmp(sub->name, "anyxml") || |
| 6025 | !strcmp(sub->name, "anydata")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 6026 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 6027 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6028 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6029 | /* array counters */ |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6030 | } else if (!strcmp(sub->name, "typedef")) { |
| 6031 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6032 | } else if (!strcmp(sub->name, "if-feature")) { |
| 6033 | c_ftrs++; |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 6034 | } else if ((module->version >= 2) && !strcmp(sub->name, "must")) { |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 6035 | c_must++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6036 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6037 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6038 | goto error; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6039 | } |
| 6040 | } |
| 6041 | |
| 6042 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 6043 | if (c_tpdf) { |
| 6044 | notif->tpdf = calloc(c_tpdf, sizeof *notif->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6045 | if (!notif->tpdf) { |
| 6046 | LOGMEM; |
| 6047 | goto error; |
| 6048 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6049 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6050 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 6051 | notif->iffeature = calloc(c_ftrs, sizeof *notif->iffeature); |
| 6052 | if (!notif->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6053 | LOGMEM; |
| 6054 | goto error; |
| 6055 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6056 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 6057 | if (c_must) { |
| 6058 | notif->must = calloc(c_must, sizeof *notif->must); |
| 6059 | if (!notif->must) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6060 | LOGMEM; |
| 6061 | goto error; |
| 6062 | } |
| 6063 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6064 | if (c_ext) { |
Radek Krejci | 478ef1d | 2017-01-24 13:56:09 +0100 | [diff] [blame] | 6065 | /* some extensions may be already present from the substatements */ |
| 6066 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 6067 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6068 | LOGMEM; |
| 6069 | goto error; |
| 6070 | } |
Radek Krejci | 478ef1d | 2017-01-24 13:56:09 +0100 | [diff] [blame] | 6071 | retval->ext = reallocated; |
| 6072 | |
| 6073 | /* init memory */ |
| 6074 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6075 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6076 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6077 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 6078 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6079 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 6080 | 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] | 6081 | retval->ext_size++; |
| 6082 | if (r) { |
| 6083 | goto error; |
| 6084 | } |
| 6085 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 6086 | r = fill_yin_typedef(module, retval, sub, ¬if->tpdf[notif->tpdf_size], unres); |
| 6087 | notif->tpdf_size++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6088 | if (r) { |
| 6089 | goto error; |
| 6090 | } |
Radek Krejci | 9629915 | 2016-06-22 10:17:50 +0200 | [diff] [blame] | 6091 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 6092 | 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] | 6093 | notif->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 6094 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 6095 | goto error; |
| 6096 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 6097 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 6098 | r = fill_yin_must(module, sub, ¬if->must[notif->must_size], unres); |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 6099 | notif->must_size++; |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 6100 | if (r) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6101 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6102 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6103 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6104 | } |
| 6105 | |
| 6106 | /* last part - process data nodes */ |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6107 | options |= LYS_PARSE_OPT_CFG_IGNORE; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6108 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 6109 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6110 | node = read_yin_container(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6111 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6112 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6113 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6114 | node = read_yin_leaf(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6115 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6116 | node = read_yin_list(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6117 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6118 | node = read_yin_choice(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6119 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6120 | node = read_yin_uses(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6121 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6122 | node = read_yin_grouping(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6123 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6124 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 6125 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6126 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6127 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6128 | if (!node) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6129 | goto error; |
| 6130 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 6131 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6132 | lyxml_free(module->ctx, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6133 | } |
| 6134 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 6135 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 6136 | if (notif->must) { |
| 6137 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame^] | 6138 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 6139 | goto error; |
| 6140 | } |
| 6141 | } else { |
| 6142 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 6143 | goto error; |
| 6144 | } |
| 6145 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 6146 | } |
| 6147 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6148 | return retval; |
| 6149 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6150 | error: |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6151 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 6152 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6153 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6154 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 6155 | } |
| 6156 | |
| 6157 | return NULL; |
| 6158 | } |
| 6159 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 6160 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6161 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 6162 | read_yin_rpc_action(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6163 | int options, struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6164 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 6165 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6166 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6167 | struct lys_node *retval; |
Michal Vasko | 44fb638 | 2016-06-29 11:12:27 +0200 | [diff] [blame] | 6168 | struct lys_node_rpc_action *rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6169 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6170 | 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] | 6171 | void *reallocated; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6172 | |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6173 | if (!strcmp(yin->name, "action")) { |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 6174 | if (module->version < 2) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6175 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, parent, "action"); |
Michal Vasko | bb17485 | 2016-07-25 11:00:21 +0200 | [diff] [blame] | 6176 | return NULL; |
| 6177 | } |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6178 | for (node = parent; node; node = lys_parent(node)) { |
Radek Krejci | a3b19f7 | 2016-09-30 13:02:45 +0200 | [diff] [blame] | 6179 | if ((node->nodetype & (LYS_RPC | LYS_ACTION | LYS_NOTIF)) |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6180 | || ((node->nodetype == LYS_LIST) && !((struct lys_node_list *)node)->keys_size)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6181 | LOGVAL(LYE_INPAR, LY_VLOG_LYS, parent, strnodetype(node->nodetype), "action"); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6182 | return NULL; |
| 6183 | } |
| 6184 | } |
| 6185 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6186 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 6187 | /* init */ |
| 6188 | memset(&root, 0, sizeof root); |
| 6189 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6190 | rpc = calloc(1, sizeof *rpc); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6191 | if (!rpc) { |
| 6192 | LOGMEM; |
| 6193 | return NULL; |
| 6194 | } |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6195 | rpc->nodetype = (!strcmp(yin->name, "rpc") ? LYS_RPC : LYS_ACTION); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6196 | rpc->prev = (struct lys_node *)rpc; |
| 6197 | retval = (struct lys_node *)rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6198 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 6199 | 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] | 6200 | goto error; |
| 6201 | } |
| 6202 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 6203 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6204 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 6205 | /* insert the node into the schema tree */ |
| 6206 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 6207 | goto error; |
| 6208 | } |
| 6209 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6210 | /* process rpc's specific children */ |
| 6211 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6212 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6213 | /* extension */ |
| 6214 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6215 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6216 | } else if (!strcmp(sub->name, "input")) { |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6217 | if (c_input) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6218 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6219 | goto error; |
| 6220 | } |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6221 | c_input++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 6222 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 6223 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6224 | } else if (!strcmp(sub->name, "output")) { |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6225 | if (c_output) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6226 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6227 | goto error; |
| 6228 | } |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6229 | c_output++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 6230 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 6231 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6232 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6233 | /* data statements */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6234 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 6235 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 6236 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6237 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6238 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6239 | } else if (!strcmp(sub->name, "typedef")) { |
| 6240 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6241 | } else if (!strcmp(sub->name, "if-feature")) { |
| 6242 | c_ftrs++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6243 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6244 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6245 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6246 | } |
| 6247 | } |
| 6248 | |
| 6249 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 6250 | if (c_tpdf) { |
| 6251 | rpc->tpdf = calloc(c_tpdf, sizeof *rpc->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6252 | if (!rpc->tpdf) { |
| 6253 | LOGMEM; |
| 6254 | goto error; |
| 6255 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6256 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6257 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 6258 | rpc->iffeature = calloc(c_ftrs, sizeof *rpc->iffeature); |
| 6259 | if (!rpc->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6260 | LOGMEM; |
| 6261 | goto error; |
| 6262 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6263 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6264 | if (c_ext) { |
Radek Krejci | 94596cf | 2017-01-24 13:19:16 +0100 | [diff] [blame] | 6265 | /* some extensions may be already present from the substatements */ |
| 6266 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 6267 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6268 | LOGMEM; |
| 6269 | goto error; |
| 6270 | } |
Radek Krejci | 94596cf | 2017-01-24 13:19:16 +0100 | [diff] [blame] | 6271 | retval->ext = reallocated; |
| 6272 | |
| 6273 | /* init memory */ |
| 6274 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6275 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6276 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6277 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 6278 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6279 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 6280 | 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] | 6281 | retval->ext_size++; |
| 6282 | if (r) { |
| 6283 | goto error; |
| 6284 | } |
| 6285 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 6286 | r = fill_yin_typedef(module, retval, sub, &rpc->tpdf[rpc->tpdf_size], unres); |
| 6287 | rpc->tpdf_size++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6288 | if (r) { |
| 6289 | goto error; |
| 6290 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6291 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 6292 | 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] | 6293 | rpc->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 6294 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 6295 | goto error; |
| 6296 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6297 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6298 | } |
| 6299 | |
| 6300 | /* last part - process data nodes */ |
| 6301 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 6302 | if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6303 | node = read_yin_grouping(module, retval, sub, options, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6304 | } else if (!strcmp(sub->name, "input") || !strcmp(sub->name, "output")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6305 | node = read_yin_input_output(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6306 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6307 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6308 | goto error; |
| 6309 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 6310 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6311 | lyxml_free(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6312 | } |
| 6313 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6314 | return retval; |
| 6315 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6316 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6317 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 6318 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 6319 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6320 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6321 | } |
| 6322 | |
| 6323 | return NULL; |
| 6324 | } |
| 6325 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 6326 | /* logs directly |
| 6327 | * |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6328 | * resolve - referenced grouping should be bounded to the namespace (resolved) |
| 6329 | * only when uses does not appear in grouping. In a case of grouping's uses, |
| 6330 | * we just get information but we do not apply augment or refine to it. |
| 6331 | */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6332 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6333 | read_yin_uses(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
| 6334 | int options, struct unres_schema *unres) |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6335 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6336 | struct lyxml_elem *sub, *next; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6337 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 6338 | struct lys_node_uses *uses; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6339 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6340 | 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] | 6341 | int r; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 6342 | void *reallocated; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6343 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6344 | uses = calloc(1, sizeof *uses); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6345 | if (!uses) { |
| 6346 | LOGMEM; |
| 6347 | return NULL; |
| 6348 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6349 | uses->nodetype = LYS_USES; |
| 6350 | uses->prev = (struct lys_node *)uses; |
| 6351 | retval = (struct lys_node *)uses; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6352 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6353 | GETVAL(value, yin, "name"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6354 | uses->name = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 6355 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 6356 | 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] | 6357 | goto error; |
| 6358 | } |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6359 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 6360 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6361 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 6362 | /* insert the node into the schema tree */ |
| 6363 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 6364 | goto error; |
| 6365 | } |
| 6366 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6367 | /* get other properties of uses */ |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6368 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6369 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6370 | /* extension */ |
| 6371 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6372 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6373 | } else if (!strcmp(sub->name, "refine")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6374 | c_ref++; |
| 6375 | } else if (!strcmp(sub->name, "augment")) { |
| 6376 | c_aug++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6377 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 56e8977 | 2015-06-19 10:00:54 +0200 | [diff] [blame] | 6378 | c_ftrs++; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6379 | } else if (!strcmp(sub->name, "when")) { |
| 6380 | if (uses->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6381 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6382 | goto error; |
| 6383 | } |
| 6384 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 6385 | uses->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6386 | if (!uses->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6387 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6388 | goto error; |
| 6389 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6390 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6391 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6392 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6393 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6394 | } |
| 6395 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 6396 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6397 | /* process properties with cardinality 0..n */ |
| 6398 | if (c_ref) { |
| 6399 | uses->refine = calloc(c_ref, sizeof *uses->refine); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6400 | if (!uses->refine) { |
| 6401 | LOGMEM; |
| 6402 | goto error; |
| 6403 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6404 | } |
| 6405 | if (c_aug) { |
| 6406 | uses->augment = calloc(c_aug, sizeof *uses->augment); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6407 | if (!uses->augment) { |
| 6408 | LOGMEM; |
| 6409 | goto error; |
| 6410 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6411 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6412 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 6413 | uses->iffeature = calloc(c_ftrs, sizeof *uses->iffeature); |
| 6414 | if (!uses->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6415 | LOGMEM; |
| 6416 | goto error; |
| 6417 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6418 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6419 | if (c_ext) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 6420 | /* some extensions may be already present from the substatements */ |
| 6421 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
| 6422 | if (!reallocated) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6423 | LOGMEM; |
| 6424 | goto error; |
| 6425 | } |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 6426 | retval->ext = reallocated; |
| 6427 | |
| 6428 | /* init memory */ |
| 6429 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6430 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 6431 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6432 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 6433 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6434 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 6435 | 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] | 6436 | retval->ext_size++; |
| 6437 | if (r) { |
| 6438 | goto error; |
| 6439 | } |
| 6440 | } else if (!strcmp(sub->name, "refine")) { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 6441 | r = fill_yin_refine(retval, sub, &uses->refine[uses->refine_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 6442 | uses->refine_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 6443 | if (r) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6444 | goto error; |
| 6445 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 6446 | } else if (!strcmp(sub->name, "augment")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6447 | r = fill_yin_augment(module, retval, sub, &uses->augment[uses->augment_size], options, unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 6448 | uses->augment_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 6449 | if (r) { |
| 6450 | goto error; |
| 6451 | } |
| 6452 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 6453 | 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] | 6454 | uses->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 6455 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 6456 | goto error; |
| 6457 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6458 | } |
| 6459 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 6460 | |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6461 | if (unres_schema_add_node(module, unres, uses, UNRES_USES, NULL) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 6462 | goto error; |
| 6463 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6464 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 6465 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 6466 | if (uses->when) { |
| 6467 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame^] | 6468 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 6469 | goto error; |
| 6470 | } |
| 6471 | } else { |
| 6472 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 6473 | goto error; |
| 6474 | } |
| 6475 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 6476 | } |
| 6477 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6478 | return retval; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6479 | |
| 6480 | error: |
| 6481 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 6482 | lys_node_free(retval, NULL, 0); |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6483 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6484 | return NULL; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6485 | } |
| 6486 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 6487 | /* logs directly |
| 6488 | * |
| 6489 | * common code for yin_read_module() and yin_read_submodule() |
| 6490 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6491 | static int |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6492 | read_sub_module(struct lys_module *module, struct lys_submodule *submodule, struct lyxml_elem *yin, |
| 6493 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6494 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6495 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 6496 | struct lyxml_elem *next, *child, root, grps, augs, revs, exts; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6497 | struct lys_node *node = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6498 | struct lys_module *trg; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6499 | const char *value; |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6500 | int i, r, ret = -1; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6501 | int version_flag = 0; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6502 | /* (sub)module substatements are ordered in groups, increment this value when moving to another group |
| 6503 | * 0 - header-stmts, 1 - linkage-stmts, 2 - meta-stmts, 3 - revision-stmts, 4 - body-stmts */ |
| 6504 | int substmt_group; |
| 6505 | /* just remember last substatement for logging */ |
| 6506 | const char *substmt_prev; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6507 | /* counters */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6508 | 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; |
| 6509 | int c_ext = 0, c_extinst = 0; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6510 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6511 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6512 | /* to simplify code, store the module/submodule being processed as trg */ |
Michal Vasko | fe7e5a7 | 2016-05-02 14:49:23 +0200 | [diff] [blame] | 6513 | trg = submodule ? (struct lys_module *)submodule : module; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6514 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6515 | /* init */ |
| 6516 | memset(&root, 0, sizeof root); |
| 6517 | memset(&grps, 0, sizeof grps); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6518 | memset(&augs, 0, sizeof augs); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6519 | memset(&exts, 0, sizeof exts); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6520 | memset(&revs, 0, sizeof revs); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 6521 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6522 | /* |
| 6523 | * in the first run, we process elements with cardinality of 1 or 0..1 and |
| 6524 | * count elements with cardinality 0..n. Data elements (choices, containers, |
| 6525 | * leafs, lists, leaf-lists) are moved aside to be processed last, since we |
| 6526 | * need have all top-level and groupings already prepared at that time. In |
| 6527 | * the middle loop, we process other elements with carinality of 0..n since |
| 6528 | * we need to allocate arrays to store them. |
| 6529 | */ |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6530 | substmt_group = 0; |
| 6531 | substmt_prev = NULL; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6532 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6533 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6534 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6535 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6536 | continue; |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame] | 6537 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6538 | /* possible extension instance */ |
| 6539 | lyxml_unlink_elem(module->ctx, child, 2); |
| 6540 | lyxml_add_child(module->ctx, &exts, child); |
| 6541 | c_extinst++; |
| 6542 | } else if (!submodule && !strcmp(child->name, "namespace")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6543 | if (substmt_group > 0) { |
| 6544 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6545 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6546 | child->name, substmt_prev); |
| 6547 | goto error; |
| 6548 | } |
| 6549 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6550 | if (trg->ns) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6551 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6552 | goto error; |
| 6553 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6554 | GETVAL(value, child, "uri"); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6555 | trg->ns = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6556 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6557 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_NAMESPACE, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6558 | goto error; |
| 6559 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6560 | lyxml_free(ctx, child); |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6561 | |
| 6562 | substmt_prev = "namespace"; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6563 | } else if (!submodule && !strcmp(child->name, "prefix")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6564 | if (substmt_group > 0) { |
| 6565 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6566 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6567 | child->name, substmt_prev); |
| 6568 | goto error; |
| 6569 | } |
| 6570 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6571 | if (trg->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6572 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6573 | goto error; |
| 6574 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6575 | GETVAL(value, child, "value"); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6576 | if (lyp_check_identifier(value, LY_IDENT_PREFIX, trg, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6577 | goto error; |
| 6578 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6579 | trg->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6580 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6581 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_PREFIX, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6582 | goto error; |
| 6583 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6584 | lyxml_free(ctx, child); |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6585 | |
| 6586 | substmt_prev = "prefix"; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6587 | } else if (submodule && !strcmp(child->name, "belongs-to")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6588 | if (substmt_group > 0) { |
| 6589 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6590 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6591 | child->name, substmt_prev); |
| 6592 | goto error; |
| 6593 | } |
| 6594 | |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame] | 6595 | if (trg->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6596 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6597 | goto error; |
| 6598 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6599 | GETVAL(value, child, "module"); |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 6600 | if (!ly_strequal(value, submodule->belongsto->name, 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6601 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6602 | goto error; |
| 6603 | } |
Radek Krejci | f388693 | 2015-06-04 17:36:06 +0200 | [diff] [blame] | 6604 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6605 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_BELONGSTO, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6606 | goto error; |
| 6607 | } |
| 6608 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6609 | /* get the prefix substatement, start with checks */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6610 | if (!child->child) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6611 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6612 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6613 | } else if (strcmp(child->child->name, "prefix")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6614 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6615 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6616 | } else if (child->child->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6617 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->child->next->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6618 | goto error; |
| 6619 | } |
| 6620 | /* and now finally get the value */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6621 | GETVAL(value, child->child, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6622 | /* check here differs from a generic prefix check, since this prefix |
| 6623 | * don't have to be unique |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6624 | */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6625 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6626 | goto error; |
| 6627 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6628 | submodule->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 0af1387 | 2015-05-30 11:50:52 +0200 | [diff] [blame] | 6629 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6630 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child->child, LYEXT_SUBSTMT_PREFIX, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6631 | goto error; |
| 6632 | } |
| 6633 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6634 | /* we are done with belongs-to */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6635 | lyxml_free(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6636 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6637 | substmt_prev = "belongs-to"; |
| 6638 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6639 | /* counters (statements with n..1 cardinality) */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6640 | } else if (!strcmp(child->name, "import")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6641 | if (substmt_group > 1) { |
| 6642 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6643 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6644 | child->name, substmt_prev); |
| 6645 | goto error; |
| 6646 | } |
| 6647 | substmt_group = 1; |
| 6648 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6649 | c_imp++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6650 | |
| 6651 | substmt_prev = "import"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6652 | } else if (!strcmp(child->name, "revision")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6653 | if (substmt_group > 3) { |
| 6654 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6655 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6656 | child->name, substmt_prev); |
| 6657 | goto error; |
| 6658 | } |
| 6659 | substmt_group = 3; |
| 6660 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6661 | c_rev++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6662 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6663 | lyxml_unlink_elem(ctx, child, 2); |
| 6664 | lyxml_add_child(ctx, &revs, child); |
| 6665 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6666 | substmt_prev = "revision"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6667 | } else if (!strcmp(child->name, "typedef")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6668 | substmt_group = 4; |
| 6669 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6670 | c_tpdf++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6671 | |
| 6672 | substmt_prev = "typedef"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6673 | } else if (!strcmp(child->name, "identity")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6674 | substmt_group = 4; |
| 6675 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6676 | c_ident++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6677 | |
| 6678 | substmt_prev = "identity"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6679 | } else if (!strcmp(child->name, "include")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6680 | if (substmt_group > 1) { |
| 6681 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6682 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6683 | child->name, substmt_prev); |
| 6684 | goto error; |
| 6685 | } |
| 6686 | substmt_group = 1; |
| 6687 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6688 | c_inc++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6689 | |
| 6690 | substmt_prev = "include"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6691 | } else if (!strcmp(child->name, "augment")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6692 | substmt_group = 4; |
| 6693 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6694 | c_aug++; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6695 | /* keep augments separated, processed last */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6696 | lyxml_unlink_elem(ctx, child, 2); |
| 6697 | lyxml_add_child(ctx, &augs, child); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6698 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6699 | substmt_prev = "augment"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6700 | } else if (!strcmp(child->name, "feature")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6701 | substmt_group = 4; |
| 6702 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6703 | c_ftrs++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6704 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6705 | substmt_prev = "feature"; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6706 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6707 | /* data statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6708 | } else if (!strcmp(child->name, "container") || |
| 6709 | !strcmp(child->name, "leaf-list") || |
| 6710 | !strcmp(child->name, "leaf") || |
| 6711 | !strcmp(child->name, "list") || |
| 6712 | !strcmp(child->name, "choice") || |
| 6713 | !strcmp(child->name, "uses") || |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6714 | !strcmp(child->name, "anyxml") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 6715 | !strcmp(child->name, "anydata") || |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6716 | !strcmp(child->name, "rpc") || |
| 6717 | !strcmp(child->name, "notification")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6718 | substmt_group = 4; |
| 6719 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6720 | lyxml_unlink_elem(ctx, child, 2); |
| 6721 | lyxml_add_child(ctx, &root, child); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6722 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6723 | substmt_prev = "data definition"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6724 | } else if (!strcmp(child->name, "grouping")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6725 | substmt_group = 4; |
| 6726 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6727 | /* keep groupings separated and process them before other data statements */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6728 | lyxml_unlink_elem(ctx, child, 2); |
| 6729 | lyxml_add_child(ctx, &grps, child); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6730 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6731 | substmt_prev = "grouping"; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6732 | /* optional statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6733 | } else if (!strcmp(child->name, "description")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6734 | if (substmt_group > 2) { |
| 6735 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6736 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6737 | child->name, substmt_prev); |
| 6738 | goto error; |
| 6739 | } |
| 6740 | substmt_group = 2; |
| 6741 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6742 | if (trg->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6743 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6744 | goto error; |
| 6745 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6746 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6747 | goto error; |
| 6748 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6749 | trg->dsc = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6750 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6751 | if (!trg->dsc) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6752 | goto error; |
| 6753 | } |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6754 | |
| 6755 | substmt_prev = "description"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6756 | } else if (!strcmp(child->name, "reference")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6757 | if (substmt_group > 2) { |
| 6758 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6759 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6760 | child->name, substmt_prev); |
| 6761 | goto error; |
| 6762 | } |
| 6763 | substmt_group = 2; |
| 6764 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6765 | if (trg->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6766 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6767 | goto error; |
| 6768 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6769 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6770 | goto error; |
| 6771 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6772 | trg->ref = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6773 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6774 | if (!trg->ref) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6775 | goto error; |
| 6776 | } |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6777 | |
| 6778 | substmt_prev = "reference"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6779 | } else if (!strcmp(child->name, "organization")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6780 | if (substmt_group > 2) { |
| 6781 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6782 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6783 | child->name, substmt_prev); |
| 6784 | goto error; |
| 6785 | } |
| 6786 | substmt_group = 2; |
| 6787 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6788 | if (trg->org) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6789 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6790 | goto error; |
| 6791 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6792 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_ORGANIZATION, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6793 | goto error; |
| 6794 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6795 | trg->org = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6796 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6797 | if (!trg->org) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6798 | goto error; |
| 6799 | } |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6800 | |
| 6801 | substmt_prev = "organization"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6802 | } else if (!strcmp(child->name, "contact")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6803 | if (substmt_group > 2) { |
| 6804 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6805 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6806 | child->name, substmt_prev); |
| 6807 | goto error; |
| 6808 | } |
| 6809 | substmt_group = 2; |
| 6810 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6811 | if (trg->contact) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6812 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6813 | goto error; |
| 6814 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6815 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_CONTACT, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6816 | goto error; |
| 6817 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6818 | trg->contact = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6819 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6820 | if (!trg->contact) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6821 | goto error; |
| 6822 | } |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6823 | |
| 6824 | substmt_prev = "contact"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6825 | } else if (!strcmp(child->name, "yang-version")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6826 | if (substmt_group > 0) { |
| 6827 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6828 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6829 | child->name, substmt_prev); |
| 6830 | goto error; |
| 6831 | } |
| 6832 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6833 | if (version_flag) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6834 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6835 | goto error; |
| 6836 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6837 | GETVAL(value, child, "value"); |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6838 | if (strcmp(value, "1") && strcmp(value, "1.1")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6839 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "yang-version"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6840 | goto error; |
| 6841 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6842 | version_flag = 1; |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6843 | if (!strcmp(value, "1")) { |
| 6844 | if (submodule) { |
| 6845 | if (module->version > 1) { |
| 6846 | LOGVAL(LYE_INVER, LY_VLOG_NONE, NULL); |
| 6847 | goto error; |
| 6848 | } |
| 6849 | } else { |
| 6850 | module->version = 1; |
| 6851 | } |
| 6852 | } else { |
| 6853 | if (submodule) { |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 6854 | if (module->version < 2) { |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6855 | LOGVAL(LYE_INVER, LY_VLOG_NONE, NULL); |
| 6856 | goto error; |
| 6857 | } |
| 6858 | } else { |
| 6859 | module->version = 2; |
| 6860 | } |
| 6861 | } |
| 6862 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6863 | if (lyp_yin_parse_subnode_ext(trg, trg, LYEXT_PAR_MODULE, child, LYEXT_SUBSTMT_VERSION, 0, unres)) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6864 | goto error; |
| 6865 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6866 | lyxml_free(ctx, child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6867 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6868 | substmt_prev = "yang-version"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6869 | } else if (!strcmp(child->name, "extension")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6870 | substmt_group = 4; |
| 6871 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6872 | c_ext++; |
Radek Krejci | 5166a89 | 2015-07-02 16:44:24 +0200 | [diff] [blame] | 6873 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6874 | substmt_prev = "extension"; |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6875 | } else if (!strcmp(child->name, "deviation")) { |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame] | 6876 | substmt_group = 4; |
| 6877 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6878 | c_dev++; |
| 6879 | |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame] | 6880 | substmt_prev = "deviation"; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6881 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6882 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6883 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6884 | } |
| 6885 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6886 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6887 | /* check for mandatory statements */ |
Radek Krejci | 6a1e2f4 | 2017-01-19 15:22:00 +0100 | [diff] [blame] | 6888 | if (submodule) { |
| 6889 | if (!submodule->prefix) { |
| 6890 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "belongs-to", "submodule"); |
| 6891 | goto error; |
| 6892 | } |
| 6893 | if (!version_flag) { |
| 6894 | /* check version compatibility with the main module */ |
| 6895 | if (module->version > 1) { |
| 6896 | LOGVAL(LYE_INVER, LY_VLOG_NONE, NULL); |
| 6897 | goto error; |
| 6898 | } |
| 6899 | } |
| 6900 | } else { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6901 | if (!trg->ns) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6902 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "namespace", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6903 | goto error; |
| 6904 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6905 | if (!trg->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6906 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6907 | goto error; |
| 6908 | } |
| 6909 | } |
Radek Krejci | bb3257d | 2015-05-21 23:03:51 +0200 | [diff] [blame] | 6910 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6911 | /* allocate arrays for elements with cardinality of 0..n */ |
| 6912 | if (c_imp) { |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 6913 | trg->imp = calloc(c_imp, sizeof *trg->imp); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6914 | if (!trg->imp) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6915 | LOGMEM; |
| 6916 | goto error; |
| 6917 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6918 | } |
| 6919 | if (c_rev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6920 | trg->rev = calloc(c_rev, sizeof *trg->rev); |
| 6921 | if (!trg->rev) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6922 | LOGMEM; |
| 6923 | goto error; |
| 6924 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6925 | } |
| 6926 | if (c_tpdf) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6927 | trg->tpdf = calloc(c_tpdf, sizeof *trg->tpdf); |
| 6928 | if (!trg->tpdf) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6929 | LOGMEM; |
| 6930 | goto error; |
| 6931 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6932 | } |
| 6933 | if (c_ident) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6934 | trg->ident = calloc(c_ident, sizeof *trg->ident); |
| 6935 | if (!trg->ident) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6936 | LOGMEM; |
| 6937 | goto error; |
| 6938 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6939 | } |
| 6940 | if (c_inc) { |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 6941 | trg->inc = calloc(c_inc, sizeof *trg->inc); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6942 | if (!trg->inc) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6943 | LOGMEM; |
| 6944 | goto error; |
| 6945 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6946 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6947 | if (c_aug) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6948 | trg->augment = calloc(c_aug, sizeof *trg->augment); |
| 6949 | if (!trg->augment) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6950 | LOGMEM; |
| 6951 | goto error; |
| 6952 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6953 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6954 | if (c_ftrs) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6955 | trg->features = calloc(c_ftrs, sizeof *trg->features); |
| 6956 | if (!trg->features) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6957 | LOGMEM; |
| 6958 | goto error; |
| 6959 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6960 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6961 | if (c_dev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6962 | trg->deviation = calloc(c_dev, sizeof *trg->deviation); |
| 6963 | if (!trg->deviation) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 6964 | LOGMEM; |
| 6965 | goto error; |
| 6966 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6967 | } |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6968 | if (c_ext) { |
| 6969 | trg->extensions = calloc(c_ext, sizeof *trg->extensions); |
| 6970 | if (!trg->extensions) { |
| 6971 | LOGMEM; |
| 6972 | goto error; |
| 6973 | } |
| 6974 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6975 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6976 | /* middle part 1 - process revision and then check whether this (sub)module was not already parsed, add it there */ |
| 6977 | LY_TREE_FOR_SAFE(revs.child, next, child) { |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 6978 | r = fill_yin_revision(trg, child, &trg->rev[trg->rev_size], unres); |
| 6979 | trg->rev_size++; |
| 6980 | if (r) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6981 | goto error; |
| 6982 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6983 | |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 6984 | /* check uniqueness of the revision date - not required by RFC */ |
| 6985 | for (i = 0; i < (trg->rev_size - 1); i++) { |
| 6986 | if (!strcmp(trg->rev[i].date, trg->rev[trg->rev_size - 1].date)) { |
| 6987 | LOGWRN("Module's revisions are not unique (%s).", trg->rev[trg->rev_size - 1].date); |
| 6988 | break; |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6989 | } |
| 6990 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6991 | |
| 6992 | lyxml_free(ctx, child); |
| 6993 | } |
| 6994 | |
| 6995 | /* check the module with respect to the context now */ |
| 6996 | if (!submodule) { |
| 6997 | switch (lyp_ctx_check_module(module)) { |
| 6998 | case -1: |
| 6999 | goto error; |
| 7000 | case 0: |
| 7001 | break; |
| 7002 | case 1: |
| 7003 | /* it's already there */ |
| 7004 | ret = 1; |
| 7005 | goto error; |
| 7006 | } |
| 7007 | } |
| 7008 | |
| 7009 | /* middle part 2 - process nodes with cardinality of 0..n except the data nodes and augments */ |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 7010 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7011 | if (!strcmp(child->name, "import")) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 7012 | r = fill_yin_import(trg, child, &trg->imp[trg->imp_size], unres); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7013 | trg->imp_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7014 | if (r) { |
| 7015 | goto error; |
| 7016 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 7017 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7018 | } else if (!strcmp(child->name, "include")) { |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 7019 | r = fill_yin_include(module, submodule, child, &trg->inc[trg->inc_size], unres); |
| 7020 | trg->inc_size++; |
| 7021 | if (r) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7022 | goto error; |
| 7023 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 7024 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7025 | } else if (!strcmp(child->name, "typedef")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7026 | r = fill_yin_typedef(trg, NULL, child, &trg->tpdf[trg->tpdf_size], unres); |
| 7027 | trg->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7028 | if (r) { |
| 7029 | goto error; |
| 7030 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 7031 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7032 | } else if (!strcmp(child->name, "identity")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7033 | r = fill_yin_identity(trg, child, &trg->ident[trg->ident_size], unres); |
| 7034 | trg->ident_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7035 | if (r) { |
| 7036 | goto error; |
| 7037 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 7038 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7039 | } else if (!strcmp(child->name, "feature")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7040 | r = fill_yin_feature(trg, child, &trg->features[trg->features_size], unres); |
| 7041 | trg->features_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 7042 | if (r) { |
| 7043 | goto error; |
| 7044 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 7045 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 7046 | } else if (!strcmp(child->name, "extension")) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 7047 | r = fill_yin_extension(trg, child, &trg->extensions[trg->extensions_size], unres); |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 7048 | trg->extensions_size++; |
| 7049 | if (r) { |
| 7050 | goto error; |
| 7051 | } |
| 7052 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7053 | } else if (!strcmp(child->name, "deviation")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7054 | r = fill_yin_deviation(trg, child, &trg->deviation[trg->deviation_size], unres); |
| 7055 | trg->deviation_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 7056 | if (r) { |
| 7057 | goto error; |
| 7058 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7059 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7060 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7061 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 7062 | /* process extension instances */ |
Radek Krejci | 8ee9480 | 2017-02-10 12:38:40 +0100 | [diff] [blame] | 7063 | if (c_extinst) { |
| 7064 | /* some extensions may be already present from the substatements */ |
| 7065 | reallocated = realloc(trg->ext, (c_extinst + trg->ext_size) * sizeof *trg->ext); |
| 7066 | if (!reallocated) { |
| 7067 | LOGMEM; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 7068 | goto error; |
| 7069 | } |
Radek Krejci | 8ee9480 | 2017-02-10 12:38:40 +0100 | [diff] [blame] | 7070 | trg->ext = reallocated; |
| 7071 | |
| 7072 | /* init memory */ |
| 7073 | memset(&trg->ext[trg->ext_size], 0, c_extinst * sizeof *trg->ext); |
| 7074 | |
| 7075 | LY_TREE_FOR_SAFE(exts.child, next, child) { |
| 7076 | r = lyp_yin_fill_ext(trg, LYEXT_PAR_MODULE, 0, 0, trg, child, &trg->ext, trg->ext_size, unres); |
| 7077 | trg->ext_size++; |
| 7078 | if (r) { |
| 7079 | goto error; |
| 7080 | } |
| 7081 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 7082 | } |
| 7083 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 7084 | /* process data nodes. Start with groupings to allow uses |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7085 | * refer to them. Submodule's data nodes are stored in the |
| 7086 | * main module data tree. |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7087 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7088 | LY_TREE_FOR_SAFE(grps.child, next, child) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7089 | node = read_yin_grouping(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7090 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7091 | goto error; |
| 7092 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 7093 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 7094 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7095 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 7096 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 7097 | /* parse data nodes, ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7098 | LY_TREE_FOR_SAFE(root.child, next, child) { |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7099 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7100 | if (!strcmp(child->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7101 | node = read_yin_container(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7102 | } else if (!strcmp(child->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7103 | node = read_yin_leaflist(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7104 | } else if (!strcmp(child->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7105 | node = read_yin_leaf(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7106 | } else if (!strcmp(child->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7107 | node = read_yin_list(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7108 | } else if (!strcmp(child->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7109 | node = read_yin_choice(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7110 | } else if (!strcmp(child->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7111 | node = read_yin_uses(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7112 | } else if (!strcmp(child->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7113 | node = read_yin_anydata(trg, NULL, child, LYS_ANYXML, 0, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 7114 | } else if (!strcmp(child->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7115 | node = read_yin_anydata(trg, NULL, child, LYS_ANYDATA, 0, unres); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 7116 | } else if (!strcmp(child->name, "rpc")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7117 | node = read_yin_rpc_action(trg, NULL, child, 0, unres); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 7118 | } else if (!strcmp(child->name, "notification")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7119 | node = read_yin_notif(trg, NULL, child, 0, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7120 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 7121 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7122 | goto error; |
| 7123 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 7124 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 7125 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7126 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 7127 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 7128 | /* ... and finally augments (last, so we can augment our data, for instance) */ |
| 7129 | LY_TREE_FOR_SAFE(augs.child, next, child) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7130 | r = fill_yin_augment(trg, NULL, child, &trg->augment[trg->augment_size], 0, unres); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7131 | trg->augment_size++; |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 7132 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 7133 | if (r) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 7134 | goto error; |
| 7135 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 7136 | lyxml_free(ctx, child); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 7137 | } |
| 7138 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7139 | return 0; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7140 | |
| 7141 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7142 | while (root.child) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7143 | lyxml_free(ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7144 | } |
| 7145 | while (grps.child) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7146 | lyxml_free(ctx, grps.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7147 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 7148 | while (augs.child) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7149 | lyxml_free(ctx, augs.child); |
| 7150 | } |
| 7151 | while (revs.child) { |
| 7152 | lyxml_free(ctx, revs.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 7153 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 7154 | while (exts.child) { |
| 7155 | lyxml_free(module->ctx, exts.child); |
| 7156 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7157 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7158 | return ret; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7159 | } |
| 7160 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 7161 | /* logs directly */ |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7162 | struct lys_submodule * |
| 7163 | 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] | 7164 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7165 | struct lyxml_elem *yin; |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7166 | struct lys_submodule *submodule = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7167 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7168 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7169 | assert(module->ctx); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7170 | |
Radek Krejci | e1bacd7 | 2017-03-01 13:18:46 +0100 | [diff] [blame] | 7171 | yin = lyxml_parse_mem(module->ctx, data, LYXML_PARSE_NOMIXEDCONTENT); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7172 | if (!yin) { |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7173 | return NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7174 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7175 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7176 | /* check root element */ |
| 7177 | if (!yin->name || strcmp(yin->name, "submodule")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 7178 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7179 | goto error; |
| 7180 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7181 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7182 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 7183 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7184 | goto error; |
| 7185 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7186 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7187 | submodule = calloc(1, sizeof *submodule); |
| 7188 | if (!submodule) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7189 | LOGMEM; |
| 7190 | goto error; |
| 7191 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7192 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7193 | submodule->ctx = module->ctx; |
| 7194 | submodule->name = lydict_insert(submodule->ctx, value, strlen(value)); |
| 7195 | submodule->type = 1; |
| 7196 | submodule->belongsto = module; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7197 | |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 7198 | /* add into the list of processed modules */ |
| 7199 | if (lyp_check_circmod_add((struct lys_module *)submodule)) { |
| 7200 | goto error; |
| 7201 | } |
| 7202 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7203 | LOGVRB("Reading submodule \"%s\".", submodule->name); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7204 | /* module cannot be changed in this case and 1 cannot be returned */ |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7205 | if (read_sub_module(module, submodule, yin, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7206 | goto error; |
| 7207 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7208 | |
Radek Krejci | 33fc477 | 2017-01-26 16:00:35 +0100 | [diff] [blame] | 7209 | lyp_sort_revisions((struct lys_module *)submodule); |
| 7210 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7211 | /* cleanup */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 7212 | lyxml_free(module->ctx, yin); |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 7213 | lyp_check_circmod_pop(module->ctx); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7214 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7215 | LOGVRB("Submodule \"%s\" successfully parsed.", submodule->name); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7216 | return submodule; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7217 | |
| 7218 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7219 | /* cleanup */ |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7220 | unres_schema_free((struct lys_module *)submodule, &unres); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 7221 | lyxml_free(module->ctx, yin); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 7222 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7223 | if (!submodule) { |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 7224 | LOGERR(ly_errno, "Submodule parsing failed."); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7225 | return NULL; |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 7226 | } |
| 7227 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7228 | LOGERR(ly_errno, "Submodule \"%s\" parsing failed.", submodule->name); |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 7229 | |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 7230 | lyp_check_circmod_pop(module->ctx); |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 7231 | lys_sub_module_remove_devs_augs((struct lys_module *)submodule); |
| 7232 | lys_submodule_module_data_free(submodule); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7233 | lys_submodule_free(submodule, NULL); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 7234 | return NULL; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7235 | } |
| 7236 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 7237 | /* logs directly */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 7238 | struct lys_module * |
Radek Krejci | 37f9ba3 | 2017-02-10 16:50:35 +0100 | [diff] [blame] | 7239 | yin_read_module_(struct ly_ctx *ctx, struct lyxml_elem *yin, const char *revision, int implement) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7240 | { |
Pavol Vican | c99b59e | 2016-03-22 15:46:39 +0100 | [diff] [blame] | 7241 | struct lys_module *module = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7242 | struct unres_schema *unres; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7243 | const char *value; |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7244 | int ret; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7245 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7246 | unres = calloc(1, sizeof *unres); |
| 7247 | if (!unres) { |
| 7248 | LOGMEM; |
| 7249 | return NULL; |
| 7250 | } |
| 7251 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7252 | /* check root element */ |
| 7253 | if (!yin->name || strcmp(yin->name, "module")) { |
Radek Krejci | 9a909bd | 2016-10-24 15:45:51 +0200 | [diff] [blame] | 7254 | if (ly_strequal("submodule", yin->name, 0)) { |
Radek Krejci | 48cfa0f | 2016-11-08 19:18:34 +0100 | [diff] [blame] | 7255 | LOGVAL(LYE_SUBMODULE, LY_VLOG_NONE, NULL); |
| 7256 | } else { |
| 7257 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, yin->name); |
Radek Krejci | 9a909bd | 2016-10-24 15:45:51 +0200 | [diff] [blame] | 7258 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7259 | goto error; |
| 7260 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7261 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7262 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 7263 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7264 | goto error; |
| 7265 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7266 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7267 | module = calloc(1, sizeof *module); |
| 7268 | if (!module) { |
| 7269 | LOGMEM; |
| 7270 | goto error; |
| 7271 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7272 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7273 | module->ctx = ctx; |
| 7274 | module->name = lydict_insert(ctx, value, strlen(value)); |
| 7275 | module->type = 0; |
Michal Vasko | d8aa32d | 2015-07-24 11:50:01 +0200 | [diff] [blame] | 7276 | module->implemented = (implement ? 1 : 0); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7277 | |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 7278 | /* add into the list of processed modules */ |
| 7279 | if (lyp_check_circmod_add(module)) { |
| 7280 | goto error; |
| 7281 | } |
| 7282 | |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 7283 | LOGVRB("Reading module \"%s\".", module->name); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7284 | ret = read_sub_module(module, NULL, yin, unres); |
| 7285 | if (ret == -1) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7286 | goto error; |
| 7287 | } |
| 7288 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7289 | if (ret == 1) { |
| 7290 | assert(!unres->count); |
| 7291 | } else { |
| 7292 | /* resolve rest of unres items */ |
| 7293 | if (unres->count && resolve_unres_schema(module, unres)) { |
| 7294 | goto error; |
| 7295 | } |
| 7296 | |
| 7297 | /* check correctness of includes */ |
| 7298 | if (lyp_check_include_missing(module)) { |
| 7299 | goto error; |
| 7300 | } |
Michal Vasko | 7b460e5 | 2017-02-10 14:50:26 +0100 | [diff] [blame] | 7301 | |
| 7302 | /* remove our submodules from the parsed submodules list */ |
| 7303 | lyp_del_includedup(module); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7304 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7305 | |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 7306 | lyp_sort_revisions(module); |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 7307 | |
| 7308 | if (lyp_rfn_apply_ext(module) || lyp_deviation_apply_ext(module)) { |
| 7309 | goto error; |
| 7310 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 7311 | |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 7312 | if (revision) { |
| 7313 | /* check revision of the parsed model */ |
| 7314 | if (!module->rev_size || strcmp(revision, module->rev[0].date)) { |
Michal Vasko | b24e788 | 2016-03-21 16:13:25 +0100 | [diff] [blame] | 7315 | LOGVRB("Module \"%s\" parsed with the wrong revision (\"%s\" instead \"%s\").", |
| 7316 | module->name, module->rev[0].date, revision); |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 7317 | goto error; |
| 7318 | } |
| 7319 | } |
| 7320 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7321 | /* add into context if not already there */ |
| 7322 | if (!ret) { |
| 7323 | if (module->deviation_size && !module->implemented) { |
| 7324 | LOGVRB("Module \"%s\" includes deviations, changing its conformance to \"implement\".", module->name); |
| 7325 | /* deviations always causes target to be made implemented, |
| 7326 | * but augents and leafrefs not, so we have to apply them now */ |
| 7327 | if (lys_set_implemented(module)) { |
| 7328 | goto error; |
| 7329 | } |
| 7330 | } |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 7331 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7332 | if (lyp_ctx_add_module(module)) { |
Michal Vasko | 2605575 | 2016-05-03 11:36:31 +0200 | [diff] [blame] | 7333 | goto error; |
| 7334 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7335 | } else { |
| 7336 | /* free what was parsed */ |
| 7337 | lys_free(module, NULL, 0); |
| 7338 | |
| 7339 | /* get the model from the context */ |
| 7340 | module = (struct lys_module *)ly_ctx_get_module(ctx, value, revision); |
| 7341 | assert(module); |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 7342 | } |
| 7343 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7344 | unres_schema_free(NULL, &unres); |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 7345 | lyp_check_circmod_pop(ctx); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 7346 | LOGVRB("Module \"%s\" successfully parsed.", module->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7347 | return module; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7348 | |
| 7349 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7350 | /* cleanup */ |
Radek Krejci | b8c07b8 | 2016-02-12 11:11:55 +0100 | [diff] [blame] | 7351 | unres_schema_free(module, &unres); |
| 7352 | |
| 7353 | if (!module) { |
Radek Krejci | 48cfa0f | 2016-11-08 19:18:34 +0100 | [diff] [blame] | 7354 | if (ly_vecode != LYVE_SUBMODULE) { |
| 7355 | LOGERR(ly_errno, "Module parsing failed."); |
| 7356 | } |
Radek Krejci | b8c07b8 | 2016-02-12 11:11:55 +0100 | [diff] [blame] | 7357 | return NULL; |
| 7358 | } |
| 7359 | |
| 7360 | LOGERR(ly_errno, "Module \"%s\" parsing failed.", module->name); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7361 | |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 7362 | lyp_check_circmod_pop(ctx); |
Michal Vasko | cf0489e | 2017-02-13 11:57:45 +0100 | [diff] [blame] | 7363 | lyp_del_includedup(module); |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 7364 | lys_sub_module_remove_devs_augs(module); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 7365 | lys_free(module, NULL, 1); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7366 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7367 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7368 | |
Radek Krejci | 37f9ba3 | 2017-02-10 16:50:35 +0100 | [diff] [blame] | 7369 | /* logs directly */ |
| 7370 | struct lys_module * |
| 7371 | yin_read_module(struct ly_ctx *ctx, const char *data, const char *revision, int implement) |
| 7372 | { |
| 7373 | struct lyxml_elem *yin; |
| 7374 | struct lys_module *result; |
| 7375 | |
Radek Krejci | e1bacd7 | 2017-03-01 13:18:46 +0100 | [diff] [blame] | 7376 | yin = lyxml_parse_mem(ctx, data, LYXML_PARSE_NOMIXEDCONTENT); |
Radek Krejci | 37f9ba3 | 2017-02-10 16:50:35 +0100 | [diff] [blame] | 7377 | if (!yin) { |
| 7378 | LOGERR(ly_errno, "Module parsing failed."); |
| 7379 | return NULL; |
| 7380 | } |
| 7381 | |
| 7382 | result = yin_read_module_(ctx, yin, revision, implement); |
| 7383 | |
| 7384 | lyxml_free(ctx, yin); |
| 7385 | |
| 7386 | return result; |
| 7387 | } |
| 7388 | |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7389 | static int |
| 7390 | yin_parse_extcomplex_bool(struct lys_module *mod, struct lyxml_elem *node, |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7391 | struct lys_ext_instance_complex *ext, LY_STMT stmt, |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7392 | const char *true_val, const char *false_val, struct unres_schema *unres) |
| 7393 | { |
| 7394 | uint8_t *val; |
| 7395 | const char *str; |
| 7396 | struct lyext_substmt *info; |
| 7397 | |
| 7398 | val = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7399 | if (!val) { |
| 7400 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7401 | return EXIT_FAILURE; |
| 7402 | } |
| 7403 | if (*val) { |
| 7404 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7405 | return EXIT_FAILURE; |
| 7406 | } |
| 7407 | |
Radek Krejci | db35f17 | 2017-02-27 11:03:01 +0100 | [diff] [blame] | 7408 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, (LYEXT_SUBSTMT)stmt, 0, unres)) { |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7409 | return EXIT_FAILURE; |
| 7410 | } |
| 7411 | |
| 7412 | str = lyxml_get_attr(node, "value", NULL); |
| 7413 | if (!str) { |
| 7414 | LOGVAL(LYE_MISSARG, LY_VLOG_NONE, NULL, "value", node->name); |
| 7415 | } else if (true_val && !strcmp(true_val, str)) { |
| 7416 | /* true value */ |
| 7417 | *val = 1; |
| 7418 | } else if (false_val && !strcmp(false_val, str)) { |
| 7419 | /* false value */ |
| 7420 | *val = 2; |
| 7421 | } else { |
| 7422 | /* unknown value */ |
| 7423 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, str, node->name); |
| 7424 | return EXIT_FAILURE; |
| 7425 | } |
| 7426 | |
| 7427 | return EXIT_SUCCESS; |
| 7428 | } |
| 7429 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7430 | /* |
| 7431 | * argelem - 1 if the value is stored in a standalone YIN element, 0 if stored as attribute |
| 7432 | * argname - name of the element/attribute where the value is stored |
| 7433 | */ |
| 7434 | static int |
| 7435 | yin_parse_extcomplex_str(struct lys_module *mod, struct lyxml_elem *node, |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7436 | struct lys_ext_instance_complex *ext, LY_STMT stmt, |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7437 | int argelem, const char *argname, struct unres_schema *unres) |
| 7438 | { |
| 7439 | int c; |
PavolVican | 99c7072 | 2017-02-18 17:25:52 +0100 | [diff] [blame] | 7440 | const char **str, ***p = NULL, *value; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7441 | void *reallocated; |
| 7442 | struct lyext_substmt *info; |
| 7443 | |
| 7444 | str = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7445 | if (!str) { |
| 7446 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7447 | return EXIT_FAILURE; |
| 7448 | } |
| 7449 | if (info->cardinality < LY_STMT_CARD_SOME && *str) { |
| 7450 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7451 | return EXIT_FAILURE; |
| 7452 | } |
| 7453 | |
| 7454 | c = 0; |
| 7455 | if (info->cardinality >= LY_STMT_CARD_SOME) { |
| 7456 | /* there can be multiple instances, str is actually const char *** */ |
| 7457 | p = (const char ***)str; |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7458 | if (!p[0]) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7459 | /* allocate initial array */ |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7460 | p[0] = malloc(2 * sizeof(const char *)); |
| 7461 | if (stmt == LY_STMT_BELONGSTO) { |
| 7462 | /* allocate another array for the belongs-to's prefixes */ |
| 7463 | p[1] = malloc(2 * sizeof(const char *)); |
PavolVican | 99c7072 | 2017-02-18 17:25:52 +0100 | [diff] [blame] | 7464 | } else if (stmt == LY_STMT_ARGUMENT) { |
| 7465 | /* allocate another array for the yin element */ |
PavolVican | 4b80d04 | 2017-02-23 14:30:27 +0100 | [diff] [blame] | 7466 | ((uint8_t **)p)[1] = malloc(2 * sizeof(uint8_t)); |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7467 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7468 | } else { |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7469 | /* get the index in the array to add new item */ |
| 7470 | for (c = 0; p[0][c]; c++); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7471 | } |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7472 | str = p[0]; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7473 | } |
Radek Krejci | db35f17 | 2017-02-27 11:03:01 +0100 | [diff] [blame] | 7474 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, (LYEXT_SUBSTMT)stmt, c, unres)) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7475 | return EXIT_FAILURE; |
| 7476 | } |
| 7477 | |
| 7478 | if (argelem) { |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7479 | str[c] = read_yin_subnode(mod->ctx, node, argname); |
| 7480 | if (!str[c]) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7481 | return EXIT_FAILURE; |
| 7482 | } |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7483 | } else { |
| 7484 | str[c] = lyxml_get_attr(node, argname, NULL); |
| 7485 | if (!str[c]) { |
| 7486 | LOGVAL(LYE_MISSARG, LY_VLOG_NONE, NULL, argname, node->name); |
| 7487 | return EXIT_FAILURE; |
| 7488 | } else { |
| 7489 | str[c] = lydict_insert(mod->ctx, str[c], 0); |
| 7490 | } |
| 7491 | |
| 7492 | if (stmt == LY_STMT_BELONGSTO) { |
| 7493 | /* get the belongs-to's mandatory prefix substatement */ |
| 7494 | if (!node->child) { |
| 7495 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", node->name); |
| 7496 | return EXIT_FAILURE; |
| 7497 | } else if (strcmp(node->child->name, "prefix")) { |
| 7498 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->child->name); |
| 7499 | return EXIT_FAILURE; |
| 7500 | } else if (node->child->next) { |
| 7501 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->child->next->name); |
| 7502 | return EXIT_FAILURE; |
| 7503 | } |
| 7504 | /* and now finally get the value */ |
| 7505 | if (p) { |
| 7506 | str = p[1]; |
| 7507 | } else { |
| 7508 | str++; |
| 7509 | } |
| 7510 | str[c] = lyxml_get_attr(node->child, "value", ((void *)0)); |
| 7511 | if (!str[c]) { |
| 7512 | LOGVAL(LYE_MISSARG, LY_VLOG_NONE, NULL, "value", node->child->name); |
| 7513 | return EXIT_FAILURE; |
| 7514 | } |
| 7515 | str[c] = lydict_insert(mod->ctx, str[c], 0); |
| 7516 | |
PavolVican | 6d40087 | 2017-03-01 15:19:18 +0100 | [diff] [blame] | 7517 | if (!str[c] || lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node->child, LYEXT_SUBSTMT_PREFIX, c, unres)) { |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7518 | return EXIT_FAILURE; |
| 7519 | } |
PavolVican | 99c7072 | 2017-02-18 17:25:52 +0100 | [diff] [blame] | 7520 | } else if (stmt == LY_STMT_ARGUMENT) { |
| 7521 | str = (p) ? p[1] : str + 1; |
| 7522 | if (!node->child) { |
| 7523 | /* default value of yin element */ |
| 7524 | ((uint8_t *)str)[c] = 2; |
| 7525 | } else { |
| 7526 | /* get optional yin-element substatement */ |
| 7527 | if (strcmp(node->child->name, "yin-element")) { |
| 7528 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->child->name); |
| 7529 | return EXIT_FAILURE; |
| 7530 | } else if (node->child->next) { |
| 7531 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->child->next->name); |
| 7532 | return EXIT_FAILURE; |
| 7533 | } else { |
| 7534 | /* and now finally get the value */ |
| 7535 | value = lyxml_get_attr(node->child, "value", NULL); |
| 7536 | if (!value) { |
| 7537 | LOGVAL(LYE_MISSARG, LY_VLOG_NONE, NULL, "value", node->child->name); |
| 7538 | return EXIT_FAILURE; |
| 7539 | } |
| 7540 | if (ly_strequal(value, "true", 0)) { |
| 7541 | ((uint8_t *)str)[c] = 1; |
| 7542 | } else if (ly_strequal(value, "false", 0)) { |
| 7543 | ((uint8_t *)str)[c] = 2; |
| 7544 | } else { |
| 7545 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, str, node->name); |
| 7546 | return EXIT_FAILURE; |
| 7547 | } |
| 7548 | |
| 7549 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node->child, LYEXT_SUBSTMT_YINELEM, c, unres)) { |
| 7550 | return EXIT_FAILURE; |
| 7551 | } |
| 7552 | } |
| 7553 | } |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7554 | } |
| 7555 | } |
| 7556 | if (p) { |
| 7557 | /* enlarge the array(s) */ |
| 7558 | reallocated = realloc(p[0], (c + 2) * sizeof(const char *)); |
| 7559 | if (!reallocated) { |
| 7560 | LOGMEM; |
| 7561 | lydict_remove(mod->ctx, p[0][c]); |
| 7562 | p[0][c] = NULL; |
| 7563 | return EXIT_FAILURE; |
| 7564 | } |
| 7565 | p[0] = reallocated; |
| 7566 | p[0][c + 1] = NULL; |
| 7567 | |
| 7568 | if (stmt == LY_STMT_BELONGSTO) { |
| 7569 | /* enlarge the second belongs-to's array with prefixes */ |
| 7570 | reallocated = realloc(p[1], (c + 2) * sizeof(const char *)); |
| 7571 | if (!reallocated) { |
| 7572 | LOGMEM; |
| 7573 | lydict_remove(mod->ctx, p[1][c]); |
| 7574 | p[1][c] = NULL; |
| 7575 | return EXIT_FAILURE; |
| 7576 | } |
| 7577 | p[1] = reallocated; |
| 7578 | p[1][c + 1] = NULL; |
PavolVican | 99c7072 | 2017-02-18 17:25:52 +0100 | [diff] [blame] | 7579 | } else if (stmt == LY_STMT_ARGUMENT){ |
| 7580 | /* enlarge the second argument's array with yin element */ |
| 7581 | reallocated = realloc(p[1], (c + 2) * sizeof(uint8_t)); |
| 7582 | if (!reallocated) { |
| 7583 | LOGMEM; |
| 7584 | ((uint8_t *)p[1])[c] = 0; |
| 7585 | return EXIT_FAILURE; |
| 7586 | } |
| 7587 | p[1] = reallocated; |
| 7588 | ((uint8_t *)p[1])[c + 1] = 0; |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7589 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7590 | } |
| 7591 | |
| 7592 | return EXIT_SUCCESS; |
| 7593 | } |
| 7594 | |
| 7595 | static void * |
| 7596 | yin_getplace_for_extcomplex_flags(struct lyxml_elem *node, struct lys_ext_instance_complex *ext, LY_STMT stmt, |
| 7597 | uint16_t mask) |
| 7598 | { |
| 7599 | void *data; |
| 7600 | struct lyext_substmt *info; |
| 7601 | |
| 7602 | data = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7603 | if (!data) { |
| 7604 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7605 | return NULL; |
| 7606 | } |
| 7607 | if (info->cardinality < LY_STMT_CARD_SOME && ((*(uint16_t *)data) & mask)) { |
| 7608 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7609 | return NULL; |
| 7610 | } |
| 7611 | |
| 7612 | return data; |
| 7613 | } |
| 7614 | |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7615 | static int |
| 7616 | yin_parse_extcomplex_flag(struct lys_module *mod, struct lyxml_elem *node, |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7617 | struct lys_ext_instance_complex *ext, LY_STMT stmt, |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7618 | const char *val1_str, const char *val2_str, uint16_t mask, |
| 7619 | uint16_t val1, uint16_t val2, struct unres_schema *unres) |
| 7620 | { |
| 7621 | uint16_t *val; |
| 7622 | const char *str; |
| 7623 | |
| 7624 | val = yin_getplace_for_extcomplex_flags(node, ext, stmt, mask); |
| 7625 | if (!val) { |
| 7626 | return EXIT_FAILURE; |
| 7627 | } |
| 7628 | |
| 7629 | str = lyxml_get_attr(node, "value", NULL); |
| 7630 | if (!str) { |
| 7631 | LOGVAL(LYE_MISSARG, LY_VLOG_NONE, NULL, "value", node->name); |
| 7632 | } else if (!strcmp(val1_str, str)) { |
| 7633 | *val = *val | val1; |
| 7634 | } else if (!strcmp(val2_str, str)) { |
| 7635 | *val = *val | val2; |
| 7636 | } else { |
| 7637 | /* unknown value */ |
| 7638 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, str, node->name); |
| 7639 | return EXIT_FAILURE; |
| 7640 | } |
Radek Krejci | db35f17 | 2017-02-27 11:03:01 +0100 | [diff] [blame] | 7641 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, (LYEXT_SUBSTMT)stmt, 0, unres)) { |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7642 | return EXIT_FAILURE; |
| 7643 | } |
| 7644 | return EXIT_SUCCESS; |
| 7645 | } |
| 7646 | |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 7647 | static struct lys_node ** |
| 7648 | yin_getplace_for_extcomplex_node(struct lyxml_elem *node, struct lys_ext_instance_complex *ext, LY_STMT stmt) |
| 7649 | { |
| 7650 | struct lyext_substmt *info; |
| 7651 | struct lys_node **snode, *siter; |
| 7652 | |
| 7653 | snode = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7654 | if (!snode) { |
| 7655 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7656 | return NULL; |
| 7657 | } |
| 7658 | if (info->cardinality < LY_STMT_CARD_SOME) { |
| 7659 | LY_TREE_FOR(*snode, siter) { |
| 7660 | if (stmt == lys_snode2stmt(siter->nodetype)) { |
| 7661 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7662 | return NULL; |
| 7663 | } |
| 7664 | } |
| 7665 | } |
| 7666 | |
| 7667 | return snode; |
| 7668 | } |
| 7669 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7670 | static void ** |
| 7671 | yin_getplace_for_extcomplex_struct(struct lyxml_elem *node, struct lys_ext_instance_complex *ext, LY_STMT stmt) |
| 7672 | { |
| 7673 | int c; |
| 7674 | void **data, ***p = NULL; |
| 7675 | void *reallocated; |
| 7676 | struct lyext_substmt *info; |
| 7677 | |
| 7678 | data = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7679 | if (!data) { |
| 7680 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7681 | return NULL; |
| 7682 | } |
| 7683 | if (info->cardinality < LY_STMT_CARD_SOME && *data) { |
| 7684 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7685 | return NULL; |
| 7686 | } |
| 7687 | |
| 7688 | c = 0; |
| 7689 | if (info->cardinality >= LY_STMT_CARD_SOME) { |
| 7690 | /* there can be multiple instances, so instead of pointer to array, |
| 7691 | * we have in data pointer to pointer to array */ |
| 7692 | p = (void ***)data; |
| 7693 | data = *p; |
| 7694 | if (!data) { |
| 7695 | /* allocate initial array */ |
| 7696 | *p = data = malloc(2 * sizeof(void *)); |
| 7697 | } else { |
| 7698 | for (c = 0; *data; data++, c++); |
| 7699 | } |
| 7700 | } |
| 7701 | |
| 7702 | if (p) { |
| 7703 | /* enlarge the array */ |
| 7704 | reallocated = realloc(*p, (c + 2) * sizeof(void *)); |
| 7705 | if (!reallocated) { |
| 7706 | LOGMEM; |
| 7707 | return NULL; |
| 7708 | } |
| 7709 | *p = reallocated; |
| 7710 | data = *p; |
| 7711 | data[c + 1] = NULL; |
| 7712 | } |
| 7713 | |
| 7714 | return &data[c]; |
| 7715 | } |
| 7716 | |
| 7717 | int |
| 7718 | lyp_yin_parse_complex_ext(struct lys_module *mod, struct lys_ext_instance_complex *ext, struct lyxml_elem *yin, |
| 7719 | struct unres_schema *unres) |
| 7720 | { |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7721 | struct lyxml_elem *next, *node, *child; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7722 | struct lys_type **type; |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7723 | void **pp, *p, *reallocated; |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7724 | const char *value, *name; |
| 7725 | char *endptr, modifier; |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7726 | struct lyext_substmt *info; |
| 7727 | long int v; |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7728 | long long int ll; |
| 7729 | unsigned long u; |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 7730 | int i, j; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7731 | |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7732 | #define YIN_EXTCOMPLEX_GETPLACE(STMT, TYPE) \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7733 | p = lys_ext_complex_get_substmt(STMT, ext, &info); \ |
| 7734 | if (!p) { \ |
| 7735 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); \ |
| 7736 | goto error; \ |
| 7737 | } \ |
| 7738 | if (info->cardinality < LY_STMT_CARD_SOME && (*(TYPE*)p)) { \ |
| 7739 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); \ |
| 7740 | goto error; \ |
| 7741 | } \ |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7742 | pp = NULL; i = 0; \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7743 | if (info->cardinality >= LY_STMT_CARD_SOME) { \ |
| 7744 | /* there can be multiple instances */ \ |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7745 | pp = p; \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7746 | if (!(*pp)) { \ |
| 7747 | *pp = malloc(2 * sizeof(TYPE)); /* allocate initial array */ \ |
| 7748 | } else { \ |
| 7749 | for (i = 0; (*(TYPE**)pp)[i]; i++); \ |
| 7750 | } \ |
| 7751 | p = &(*(TYPE**)pp)[i]; \ |
| 7752 | } |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7753 | #define YIN_EXTCOMPLEX_ENLARGE(TYPE) \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7754 | if (pp) { \ |
| 7755 | /* enlarge the array */ \ |
| 7756 | reallocated = realloc(*pp, (i + 2) * sizeof(TYPE*)); \ |
| 7757 | if (!reallocated) { \ |
| 7758 | LOGMEM; \ |
| 7759 | goto error; \ |
| 7760 | } \ |
| 7761 | *pp = reallocated; \ |
| 7762 | (*(TYPE**)pp)[i + 1] = 0; \ |
| 7763 | } |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7764 | #define YIN_EXTCOMPLEX_PARSE_SNODE(STMT, FUNC, ARGS...) \ |
| 7765 | pp = (void**)yin_getplace_for_extcomplex_node(node, ext, STMT); \ |
| 7766 | if (!pp) { goto error; } \ |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7767 | if (!FUNC(mod, (struct lys_node*)ext, node, ##ARGS, LYS_PARSE_OPT_CFG_NOINHERIT, unres)) { goto error; } |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7768 | #define YIN_EXTCOMPLEX_PARSE_RESTR(STMT) \ |
| 7769 | YIN_EXTCOMPLEX_GETPLACE(STMT, struct lys_restr*); \ |
| 7770 | GETVAL(value, node, "value"); \ |
| 7771 | *(struct lys_restr **)p = calloc(1, sizeof(struct lys_restr)); \ |
| 7772 | (*(struct lys_restr **)p)->expr = lydict_insert(mod->ctx, value, 0); \ |
| 7773 | if (read_restr_substmt(mod, *(struct lys_restr **)p, node, unres)) { \ |
| 7774 | goto error; \ |
| 7775 | } \ |
| 7776 | YIN_EXTCOMPLEX_ENLARGE(struct lys_restr*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7777 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7778 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 7779 | if (!node->ns) { |
| 7780 | /* garbage */ |
| 7781 | } else if (node->ns == yin->ns && (ext->flags & LYS_YINELEM) && ly_strequal(node->name, ext->def->argument, 1)) { |
| 7782 | /* we have the extension's argument */ |
| 7783 | if (ext->arg_value) { |
| 7784 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
| 7785 | goto error; |
| 7786 | } |
| 7787 | ext->arg_value = node->content; |
| 7788 | node->content = NULL; |
| 7789 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 7790 | /* extension */ |
| 7791 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 7792 | goto error; |
| 7793 | } |
| 7794 | } else if (!strcmp(node->name, "description")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7795 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_DESCRIPTION, 1, "text", unres)) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7796 | goto error; |
| 7797 | } |
| 7798 | } else if (!strcmp(node->name, "reference")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7799 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_REFERENCE, 1, "text", unres)) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7800 | goto error; |
| 7801 | } |
| 7802 | } else if (!strcmp(node->name, "units")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7803 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_UNITS, 0, "name", unres)) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7804 | goto error; |
| 7805 | } |
| 7806 | } else if (!strcmp(node->name, "type")) { |
| 7807 | type = (struct lys_type **)yin_getplace_for_extcomplex_struct(node, ext, LY_STMT_TYPE); |
| 7808 | if (!type) { |
| 7809 | goto error; |
| 7810 | } |
| 7811 | /* allocate type structure */ |
| 7812 | (*type) = calloc(1, sizeof **type); |
| 7813 | |
| 7814 | /* HACK for unres */ |
Radek Krejci | 63fc096 | 2017-02-15 13:20:18 +0100 | [diff] [blame] | 7815 | lyxml_unlink(mod->ctx, node); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7816 | (*type)->der = (struct lys_tpdf *)node; |
| 7817 | (*type)->parent = (struct lys_tpdf *)ext; |
| 7818 | |
| 7819 | if (unres_schema_add_node(mod, unres, *type, UNRES_TYPE_DER_EXT, NULL) == -1) { |
| 7820 | (*type)->der = NULL; |
| 7821 | goto error; |
| 7822 | } |
| 7823 | continue; /* skip lyxml_free() */ |
Radek Krejci | 63fc096 | 2017-02-15 13:20:18 +0100 | [diff] [blame] | 7824 | } else if (!strcmp(node->name, "typedef")) { |
| 7825 | pp = yin_getplace_for_extcomplex_struct(node, ext, LY_STMT_TYPEDEF); |
| 7826 | if (!pp) { |
| 7827 | goto error; |
| 7828 | } |
| 7829 | /* allocate typedef structure */ |
| 7830 | (*pp) = calloc(1, sizeof(struct lys_tpdf)); |
| 7831 | |
| 7832 | if (fill_yin_typedef(mod, (struct lys_node *)ext, node, *((struct lys_tpdf **)pp), unres)) { |
| 7833 | goto error; |
| 7834 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7835 | } else if (!strcmp(node->name, "if-feature")) { |
| 7836 | pp = yin_getplace_for_extcomplex_struct(node, ext, LY_STMT_IFFEATURE); |
| 7837 | if (!pp) { |
| 7838 | goto error; |
| 7839 | } |
| 7840 | /* allocate iffeature structure */ |
| 7841 | (*pp) = calloc(1, sizeof(struct lys_iffeature)); |
| 7842 | |
| 7843 | if (fill_yin_iffeature((struct lys_node *)ext, 0, node, *((struct lys_iffeature **)pp), unres)) { |
| 7844 | goto error; |
| 7845 | } |
| 7846 | } else if (!strcmp(node->name, "status")) { |
| 7847 | p = yin_getplace_for_extcomplex_flags(node, ext, LY_STMT_STATUS, LYS_STATUS_MASK); |
| 7848 | if (!p) { |
| 7849 | goto error; |
| 7850 | } |
| 7851 | |
| 7852 | GETVAL(value, node, "value"); |
| 7853 | if (!strcmp(value, "current")) { |
| 7854 | *(uint16_t*)p |= LYS_STATUS_CURR; |
| 7855 | } else if (!strcmp(value, "deprecated")) { |
| 7856 | *(uint16_t*)p |= LYS_STATUS_DEPRC; |
| 7857 | } else if (!strcmp(value, "obsolete")) { |
| 7858 | *(uint16_t*)p |= LYS_STATUS_OBSLT; |
| 7859 | } else { |
| 7860 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
| 7861 | goto error; |
| 7862 | } |
| 7863 | |
| 7864 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_STATUS, 0, unres)) { |
| 7865 | goto error; |
| 7866 | } |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7867 | } else if (!strcmp(node->name, "config")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7868 | if (yin_parse_extcomplex_flag(mod, node, ext, LY_STMT_MANDATORY, "true", "false", LYS_CONFIG_MASK, |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7869 | LYS_CONFIG_W | LYS_CONFIG_SET, LYS_CONFIG_R | LYS_CONFIG_SET, unres)) { |
| 7870 | goto error; |
| 7871 | } |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7872 | } else if (!strcmp(node->name, "argument")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7873 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_ARGUMENT, 0, "name", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7874 | goto error; |
| 7875 | } |
| 7876 | } else if (!strcmp(node->name, "default")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7877 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_DEFAULT, 0, "value", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7878 | goto error; |
| 7879 | } |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7880 | } else if (!strcmp(node->name, "mandatory")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7881 | if (yin_parse_extcomplex_flag(mod, node, ext, LY_STMT_MANDATORY, |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7882 | "true", "false", LYS_MAND_MASK, LYS_MAND_TRUE, LYS_MAND_FALSE, unres)) { |
| 7883 | goto error; |
| 7884 | } |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7885 | } else if (!strcmp(node->name, "error-app-tag")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7886 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_ERRTAG, 0, "value", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7887 | goto error; |
| 7888 | } |
| 7889 | } else if (!strcmp(node->name, "error-message")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7890 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_ERRMSG, 1, "value", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7891 | goto error; |
| 7892 | } |
| 7893 | } else if (!strcmp(node->name, "prefix")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7894 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_PREFIX, 0, "value", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7895 | goto error; |
| 7896 | } |
| 7897 | } else if (!strcmp(node->name, "namespace")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7898 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_NAMESPACE, 0, "uri", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7899 | goto error; |
| 7900 | } |
| 7901 | } else if (!strcmp(node->name, "presence")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7902 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_PRESENCE, 0, "value", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7903 | goto error; |
| 7904 | } |
| 7905 | } else if (!strcmp(node->name, "revision-date")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7906 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_REVISIONDATE, 0, "date", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7907 | goto error; |
| 7908 | } |
| 7909 | } else if (!strcmp(node->name, "key")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7910 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_KEY, 0, "value", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7911 | goto error; |
| 7912 | } |
| 7913 | } else if (!strcmp(node->name, "base")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7914 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_BASE, 0, "name", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7915 | goto error; |
| 7916 | } |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7917 | } else if (!strcmp(node->name, "ordered-by")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7918 | if (yin_parse_extcomplex_flag(mod, node, ext, LY_STMT_ORDEREDBY, |
| 7919 | "user", "system", LYS_USERORDERED, LYS_USERORDERED, 0, unres)) { |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7920 | goto error; |
| 7921 | } |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7922 | } else if (!strcmp(node->name, "belongs-to")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7923 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_BELONGSTO, 0, "module", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7924 | goto error; |
| 7925 | } |
| 7926 | } else if (!strcmp(node->name, "contact")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7927 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_CONTACT, 1, "text", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7928 | goto error; |
| 7929 | } |
| 7930 | } else if (!strcmp(node->name, "organization")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7931 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_ORGANIZATION, 1, "text", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7932 | goto error; |
| 7933 | } |
| 7934 | } else if (!strcmp(node->name, "path")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7935 | if (yin_parse_extcomplex_str(mod, node, ext, LY_STMT_PATH, 0, "value", unres)) { |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7936 | goto error; |
| 7937 | } |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7938 | } else if (!strcmp(node->name, "require-instance")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7939 | if (yin_parse_extcomplex_bool(mod, node, ext, LY_STMT_REQINSTANCE, "true", "false", unres)) { |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7940 | goto error; |
| 7941 | } |
| 7942 | } else if (!strcmp(node->name, "modifier")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7943 | if (yin_parse_extcomplex_bool(mod, node, ext, LY_STMT_MODIFIER, "invert-match", NULL, unres)) { |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7944 | goto error; |
| 7945 | } |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7946 | } else if (!strcmp(node->name, "fraction-digits")) { |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7947 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_DIGITS, uint8_t); |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7948 | |
| 7949 | GETVAL(value, node, "value"); |
| 7950 | v = strtol(value, NULL, 10); |
| 7951 | |
| 7952 | /* range check */ |
| 7953 | if (v < 1 || v > 18) { |
| 7954 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
| 7955 | goto error; |
| 7956 | } |
| 7957 | |
| 7958 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_STATUS, i, unres)) { |
| 7959 | goto error; |
| 7960 | } |
| 7961 | |
| 7962 | /* store the value */ |
| 7963 | (*(uint8_t *)p) = (uint8_t)v; |
| 7964 | |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7965 | YIN_EXTCOMPLEX_ENLARGE(uint8_t); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7966 | } else if (!strcmp(node->name, "max-elements")) { |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7967 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_MAX, uint32_t*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7968 | |
| 7969 | GETVAL(value, node, "value"); |
| 7970 | while (isspace(value[0])) { |
| 7971 | value++; |
| 7972 | } |
| 7973 | |
| 7974 | if (!strcmp(value, "unbounded")) { |
| 7975 | u = 0; |
| 7976 | } else { |
| 7977 | /* convert it to uint32_t */ |
| 7978 | errno = 0; endptr = NULL; |
| 7979 | u = strtoul(value, &endptr, 10); |
| 7980 | if (*endptr || value[0] == '-' || errno || u == 0 || u > UINT32_MAX) { |
| 7981 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7982 | goto error; |
| 7983 | } |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7984 | } |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7985 | |
| 7986 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_MAX, i, unres)) { |
| 7987 | goto error; |
| 7988 | } |
| 7989 | |
| 7990 | /* store the value */ |
Radek Krejci | f8d05c2 | 2017-02-10 15:33:35 +0100 | [diff] [blame] | 7991 | *(uint32_t **)p = malloc(sizeof(uint32_t)); |
| 7992 | (**(uint32_t **)p) = (uint32_t)u; |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7993 | |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7994 | YIN_EXTCOMPLEX_ENLARGE(uint32_t*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7995 | } else if (!strcmp(node->name, "min-elements")) { |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7996 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_MIN, uint32_t*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7997 | |
| 7998 | GETVAL(value, node, "value"); |
| 7999 | while (isspace(value[0])) { |
| 8000 | value++; |
| 8001 | } |
| 8002 | |
| 8003 | /* convert it to uint32_t */ |
| 8004 | errno = 0; |
| 8005 | endptr = NULL; |
| 8006 | u = strtoul(value, &endptr, 10); |
| 8007 | if (*endptr || value[0] == '-' || errno || u > UINT32_MAX) { |
| 8008 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
| 8009 | goto error; |
| 8010 | } |
| 8011 | |
| 8012 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_MAX, i, unres)) { |
| 8013 | goto error; |
| 8014 | } |
| 8015 | |
| 8016 | /* store the value */ |
Radek Krejci | f8d05c2 | 2017-02-10 15:33:35 +0100 | [diff] [blame] | 8017 | *(uint32_t **)p = malloc(sizeof(uint32_t)); |
| 8018 | (**(uint32_t **)p) = (uint32_t)u; |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8019 | |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 8020 | YIN_EXTCOMPLEX_ENLARGE(uint32_t*); |
Radek Krejci | 06a9aa0 | 2017-02-17 10:50:24 +0100 | [diff] [blame] | 8021 | } else if (!strcmp(node->name, "value")) { |
PavolVican | 2ed9f4e | 2017-02-16 00:08:45 +0100 | [diff] [blame] | 8022 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_VALUE, int32_t*); |
| 8023 | |
| 8024 | GETVAL(value, node, "value"); |
| 8025 | while (isspace(value[0])) { |
| 8026 | value++; |
| 8027 | } |
| 8028 | |
| 8029 | /* convert it to int32_t */ |
Radek Krejci | 9326fc0 | 2017-02-16 09:57:40 +0100 | [diff] [blame] | 8030 | ll = strtoll(value, NULL, 10); |
PavolVican | 2ed9f4e | 2017-02-16 00:08:45 +0100 | [diff] [blame] | 8031 | |
| 8032 | /* range check */ |
Radek Krejci | 9326fc0 | 2017-02-16 09:57:40 +0100 | [diff] [blame] | 8033 | if (ll < INT32_MIN || ll > INT32_MAX) { |
PavolVican | 2ed9f4e | 2017-02-16 00:08:45 +0100 | [diff] [blame] | 8034 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
| 8035 | goto error; |
| 8036 | } |
| 8037 | |
| 8038 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_VALUE, i, unres)) { |
| 8039 | goto error; |
| 8040 | } |
| 8041 | |
| 8042 | /* store the value */ |
| 8043 | *(int32_t **)p = malloc(sizeof(int32_t)); |
Radek Krejci | 9326fc0 | 2017-02-16 09:57:40 +0100 | [diff] [blame] | 8044 | (**(int32_t **)p) = (int32_t)ll; |
PavolVican | 2ed9f4e | 2017-02-16 00:08:45 +0100 | [diff] [blame] | 8045 | |
| 8046 | YIN_EXTCOMPLEX_ENLARGE(int32_t*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8047 | } else if (!strcmp(node->name, "position")) { |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 8048 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_POSITION, uint32_t*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8049 | |
| 8050 | GETVAL(value, node, "value"); |
| 8051 | ll = strtoll(value, NULL, 10); |
| 8052 | |
| 8053 | /* range check */ |
| 8054 | if (ll < 0 || ll > UINT32_MAX) { |
| 8055 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
| 8056 | goto error; |
| 8057 | } |
| 8058 | |
| 8059 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_POSITION, i, unres)) { |
| 8060 | goto error; |
| 8061 | } |
| 8062 | |
| 8063 | /* store the value */ |
Radek Krejci | f8d05c2 | 2017-02-10 15:33:35 +0100 | [diff] [blame] | 8064 | *(uint32_t **)p = malloc(sizeof(uint32_t)); |
| 8065 | (**(uint32_t **)p) = (uint32_t)ll; |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 8066 | |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 8067 | YIN_EXTCOMPLEX_ENLARGE(uint32_t*); |
Radek Krejci | 37f9ba3 | 2017-02-10 16:50:35 +0100 | [diff] [blame] | 8068 | } else if (!strcmp(node->name, "module")) { |
| 8069 | pp = yin_getplace_for_extcomplex_struct(node, ext, LY_STMT_MODULE); |
| 8070 | if (!pp) { |
| 8071 | goto error; |
| 8072 | } |
| 8073 | |
| 8074 | *(struct lys_module **)pp = yin_read_module_(mod->ctx, node, NULL, mod->implemented); |
| 8075 | if (!(*pp)) { |
| 8076 | goto error; |
| 8077 | } |
Radek Krejci | c5cc530 | 2017-02-16 10:07:46 +0100 | [diff] [blame] | 8078 | } else if (!strcmp(node->name, "when")) { |
| 8079 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_WHEN, struct lys_when*); |
| 8080 | |
| 8081 | *(struct lys_when**)p = read_yin_when(mod, node, unres); |
| 8082 | if (!*(struct lys_when**)p) { |
| 8083 | goto error; |
| 8084 | } |
| 8085 | |
| 8086 | YIN_EXTCOMPLEX_ENLARGE(struct lys_when*); |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 8087 | } else if (!strcmp(node->name, "revision")) { |
| 8088 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_REVISION, struct lys_revision*); |
| 8089 | |
| 8090 | *(struct lys_revision**)p = calloc(1, sizeof(struct lys_revision)); |
| 8091 | if (fill_yin_revision(mod, node, *(struct lys_revision**)p, unres)) { |
| 8092 | goto error; |
| 8093 | } |
| 8094 | |
| 8095 | /* check uniqueness of the revision dates - not required by RFC */ |
| 8096 | if (pp) { |
| 8097 | for (j = 0; j < i; j++) { |
| 8098 | if (!strcmp((*(struct lys_revision***)pp)[j]->date, (*(struct lys_revision**)p)->date)) { |
| 8099 | LOGWRN("Module's revisions are not unique (%s).", (*(struct lys_revision**)p)->date); |
| 8100 | } |
| 8101 | } |
| 8102 | } |
| 8103 | |
| 8104 | YIN_EXTCOMPLEX_ENLARGE(struct lys_revision*); |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 8105 | } else if (!strcmp(node->name, "unique")) { |
| 8106 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_UNIQUE, struct lys_unique*); |
| 8107 | |
| 8108 | *(struct lys_unique**)p = calloc(1, sizeof(struct lys_unique)); |
| 8109 | if (fill_yin_unique(mod, (struct lys_node*)ext, node, *(struct lys_unique**)p, unres)) { |
| 8110 | goto error; |
| 8111 | } |
| 8112 | |
| 8113 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_UNIQUE, i, unres)) { |
| 8114 | goto error; |
| 8115 | } |
| 8116 | YIN_EXTCOMPLEX_ENLARGE(struct lys_unique*); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8117 | } else if (!strcmp(node->name, "action")) { |
| 8118 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_ACTION, read_yin_rpc_action); |
| 8119 | } else if (!strcmp(node->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8120 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_ANYDATA, read_yin_anydata, LYS_ANYDATA); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8121 | } else if (!strcmp(node->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8122 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_ANYXML, read_yin_anydata, LYS_ANYXML); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8123 | } else if (!strcmp(node->name, "case")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8124 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_CASE, read_yin_case); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8125 | } else if (!strcmp(node->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8126 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_CHOICE, read_yin_choice); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8127 | } else if (!strcmp(node->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8128 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_CONTAINER, read_yin_container); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8129 | } else if (!strcmp(node->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8130 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_GROUPING, read_yin_grouping); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8131 | } else if (!strcmp(node->name, "output")) { |
| 8132 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_OUTPUT, read_yin_input_output); |
| 8133 | } else if (!strcmp(node->name, "input")) { |
| 8134 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_INPUT, read_yin_input_output); |
| 8135 | } else if (!strcmp(node->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8136 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_LEAF, read_yin_leaf); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8137 | } else if (!strcmp(node->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8138 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_LEAFLIST, read_yin_leaflist); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8139 | } else if (!strcmp(node->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 8140 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_LIST, read_yin_list); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 8141 | } else if (!strcmp(node->name, "notification")) { |
| 8142 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_NOTIFICATION, read_yin_notif); |
| 8143 | } else if (!strcmp(node->name, "uses")) { |
| 8144 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_USES, read_yin_uses); |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 8145 | } else if (!strcmp(node->name, "length")) { |
| 8146 | YIN_EXTCOMPLEX_PARSE_RESTR(LY_STMT_LENGTH); |
| 8147 | } else if (!strcmp(node->name, "must")) { |
| 8148 | pp = yin_getplace_for_extcomplex_struct(node, ext, LY_STMT_MUST); |
| 8149 | if (!pp) { |
| 8150 | goto error; |
| 8151 | } |
| 8152 | /* allocate structure for must */ |
| 8153 | (*pp) = calloc(1, sizeof(struct lys_restr)); |
| 8154 | |
| 8155 | if (fill_yin_must(mod, node, *((struct lys_restr **)pp), unres)) { |
| 8156 | goto error; |
| 8157 | } |
| 8158 | } else if (!strcmp(node->name, "pattern")) { |
| 8159 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_PATTERN, struct lys_restr*); |
| 8160 | GETVAL(value, node, "value"); |
| 8161 | if (lyp_check_pattern(value, NULL)) { |
| 8162 | goto error; |
| 8163 | } |
| 8164 | |
| 8165 | *(struct lys_restr **)p = calloc(1, sizeof(struct lys_restr)); |
| 8166 | (*(struct lys_restr **)p)->expr = lydict_insert(mod->ctx, value, 0); |
| 8167 | |
| 8168 | modifier = 0x06; /* ACK */ |
| 8169 | if (mod->version >= 2) { |
| 8170 | name = NULL; |
| 8171 | LY_TREE_FOR(node->child, child) { |
| 8172 | if (child->ns && !strcmp(child->ns->value, LY_NSYIN) && !strcmp(child->name, "modifier")) { |
| 8173 | if (name) { |
| 8174 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "modifier", node->name); |
| 8175 | goto error; |
| 8176 | } |
| 8177 | |
| 8178 | GETVAL(name, child, "value"); |
| 8179 | if (!strcmp(name, "invert-match")) { |
| 8180 | modifier = 0x15; /* NACK */ |
| 8181 | } else { |
| 8182 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, name, "modifier"); |
| 8183 | goto error; |
| 8184 | } |
| 8185 | /* get extensions of the modifier */ |
| 8186 | if (lyp_yin_parse_subnode_ext(mod, *(struct lys_restr **)p, LYEXT_PAR_RESTR, child, |
| 8187 | LYEXT_SUBSTMT_MODIFIER, 0, unres)) { |
| 8188 | goto error; |
| 8189 | } |
| 8190 | } |
| 8191 | } |
| 8192 | } |
| 8193 | |
| 8194 | /* store the value: modifier byte + value + terminating NULL byte */ |
| 8195 | (*(struct lys_restr **)p)->expr = malloc((strlen(value) + 2) * sizeof(char)); |
| 8196 | ((char *)(*(struct lys_restr **)p)->expr)[0] = modifier; |
| 8197 | strcpy(&((char *)(*(struct lys_restr **)p)->expr)[1], value); |
| 8198 | lydict_insert_zc(mod->ctx, (char *)(*(struct lys_restr **)p)->expr); |
| 8199 | |
| 8200 | /* get possible sub-statements */ |
| 8201 | if (read_restr_substmt(mod, *(struct lys_restr **)p, node, unres)) { |
| 8202 | goto error; |
| 8203 | } |
| 8204 | |
| 8205 | YIN_EXTCOMPLEX_ENLARGE(struct lys_restr*); |
| 8206 | } else if (!strcmp(node->name, "range")) { |
| 8207 | YIN_EXTCOMPLEX_PARSE_RESTR(LY_STMT_RANGE); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 8208 | } else { |
Radek Krejci | 06a9aa0 | 2017-02-17 10:50:24 +0100 | [diff] [blame] | 8209 | LOGERR(LY_SUCCESS, "Extension's substatement \"%s\" not supported.", node->name); |
| 8210 | //LOGERR(LY_EINT, "Extension's substatement \"%s\" not supported.", node->name); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 8211 | //return EXIT_FAILURE; |
| 8212 | } |
| 8213 | lyxml_free(mod->ctx, node); |
| 8214 | } |
| 8215 | |
PavolVican | c4b798e | 2017-02-20 23:15:27 +0100 | [diff] [blame] | 8216 | if (ext->substmt && lyp_mand_check_ext(ext, yin->name)) { |
| 8217 | return EXIT_FAILURE; |
Radek Krejci | 06a9aa0 | 2017-02-17 10:50:24 +0100 | [diff] [blame] | 8218 | } |
| 8219 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 8220 | return EXIT_SUCCESS; |
| 8221 | |
| 8222 | error: |
| 8223 | return EXIT_FAILURE; |
| 8224 | } |