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); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 86 | LY_CHECK_ERR_RETURN(!info, LOGMEM, EXIT_FAILURE); |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 87 | lyxml_unlink(module->ctx, yin); |
| 88 | info->data.yin = yin; |
| 89 | info->datatype = LYS_IN_YIN; |
| 90 | info->parent = parent; |
Radek Krejci | a7db970 | 2017-01-20 12:55:14 +0100 | [diff] [blame] | 91 | info->mod = module; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 92 | info->parent_type = parent_type; |
| 93 | info->substmt = substmt; |
| 94 | info->substmt_index = substmt_index; |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 95 | info->ext_index = ext_index; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 96 | |
| 97 | if (unres_schema_add_node(module, unres, ext, UNRES_EXT, (struct lys_node *)info) == -1) { |
| 98 | return EXIT_FAILURE; |
| 99 | } |
| 100 | |
| 101 | return EXIT_SUCCESS; |
| 102 | } |
| 103 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 104 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 105 | static const char * |
| 106 | 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] | 107 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 108 | int len; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 109 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 110 | /* there should be <text> child */ |
| 111 | if (!node->child || !node->child->name || strcmp(node->child->name, name)) { |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 112 | LOGERR(LY_EVALID, "Expected \"%s\" element in \"%s\" element.", name, node->name); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 113 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, name, node->name); |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 114 | return NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 115 | } else if (node->child->content) { |
| 116 | len = strlen(node->child->content); |
| 117 | return lydict_insert(ctx, node->child->content, len); |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 118 | } else { |
| 119 | return lydict_insert(ctx, "", 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 120 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 121 | } |
| 122 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 123 | int |
| 124 | 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] | 125 | 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] | 126 | { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 127 | void *reallocated; |
| 128 | struct lyxml_elem *next, *child; |
| 129 | int r; |
| 130 | struct lys_ext_instance ***ext; |
| 131 | uint8_t *ext_size; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 132 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 133 | switch (elem_type) { |
| 134 | case LYEXT_PAR_MODULE: |
| 135 | ext_size = &((struct lys_module *)elem)->ext_size; |
| 136 | ext = &((struct lys_module *)elem)->ext; |
| 137 | break; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 138 | case LYEXT_PAR_IMPORT: |
| 139 | ext_size = &((struct lys_import *)elem)->ext_size; |
| 140 | ext = &((struct lys_import *)elem)->ext; |
| 141 | break; |
| 142 | case LYEXT_PAR_INCLUDE: |
| 143 | ext_size = &((struct lys_include *)elem)->ext_size; |
| 144 | ext = &((struct lys_include *)elem)->ext; |
| 145 | break; |
| 146 | case LYEXT_PAR_REVISION: |
| 147 | ext_size = &((struct lys_revision *)elem)->ext_size; |
| 148 | ext = &((struct lys_revision *)elem)->ext; |
| 149 | break; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 150 | case LYEXT_PAR_NODE: |
| 151 | ext_size = &((struct lys_node *)elem)->ext_size; |
| 152 | ext = &((struct lys_node *)elem)->ext; |
| 153 | break; |
| 154 | case LYEXT_PAR_IDENT: |
| 155 | ext_size = &((struct lys_ident *)elem)->ext_size; |
| 156 | ext = &((struct lys_ident *)elem)->ext; |
| 157 | break; |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 158 | case LYEXT_PAR_TYPE: |
| 159 | ext_size = &((struct lys_type *)elem)->ext_size; |
| 160 | ext = &((struct lys_type *)elem)->ext; |
| 161 | break; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 162 | case LYEXT_PAR_TYPE_BIT: |
| 163 | ext_size = &((struct lys_type_bit *)elem)->ext_size; |
| 164 | ext = &((struct lys_type_bit *)elem)->ext; |
| 165 | break; |
| 166 | case LYEXT_PAR_TYPE_ENUM: |
| 167 | ext_size = &((struct lys_type_enum *)elem)->ext_size; |
| 168 | ext = &((struct lys_type_enum *)elem)->ext; |
| 169 | break; |
| 170 | case LYEXT_PAR_TPDF: |
| 171 | ext_size = &((struct lys_tpdf *)elem)->ext_size; |
| 172 | ext = &((struct lys_tpdf *)elem)->ext; |
| 173 | break; |
| 174 | case LYEXT_PAR_EXT: |
| 175 | ext_size = &((struct lys_ext *)elem)->ext_size; |
| 176 | ext = &((struct lys_ext *)elem)->ext; |
| 177 | break; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 178 | case LYEXT_PAR_EXTINST: |
| 179 | ext_size = &((struct lys_ext_instance *)elem)->ext_size; |
| 180 | ext = &((struct lys_ext_instance *)elem)->ext; |
| 181 | break; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 182 | case LYEXT_PAR_FEATURE: |
| 183 | ext_size = &((struct lys_feature *)elem)->ext_size; |
| 184 | ext = &((struct lys_feature *)elem)->ext; |
| 185 | break; |
| 186 | case LYEXT_PAR_REFINE: |
| 187 | ext_size = &((struct lys_refine *)elem)->ext_size; |
| 188 | ext = &((struct lys_refine *)elem)->ext; |
| 189 | break; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 190 | case LYEXT_PAR_RESTR: |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 191 | ext_size = &((struct lys_restr *)elem)->ext_size; |
| 192 | ext = &((struct lys_restr *)elem)->ext; |
| 193 | break; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 194 | case LYEXT_PAR_WHEN: |
| 195 | ext_size = &((struct lys_when *)elem)->ext_size; |
| 196 | ext = &((struct lys_when *)elem)->ext; |
| 197 | break; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 198 | case LYEXT_PAR_DEVIATE: |
| 199 | ext_size = &((struct lys_deviate *)elem)->ext_size; |
| 200 | ext = &((struct lys_deviate *)elem)->ext; |
| 201 | break; |
| 202 | case LYEXT_PAR_DEVIATION: |
| 203 | ext_size = &((struct lys_deviation *)elem)->ext_size; |
| 204 | ext = &((struct lys_deviation *)elem)->ext; |
| 205 | break; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 206 | default: |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 207 | LOGERR(LY_EINT, "parent type %d", elem_type); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 208 | return EXIT_FAILURE; |
| 209 | } |
| 210 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 211 | if (type == LYEXT_SUBSTMT_SELF) { |
| 212 | /* parse for the statement self, not for the substatement */ |
| 213 | child = yin; |
| 214 | next = NULL; |
| 215 | goto parseext; |
| 216 | } |
| 217 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 218 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 219 | if (!strcmp(child->ns->value, LY_NSYIN)) { |
| 220 | /* skip the regular YIN nodes */ |
| 221 | continue; |
| 222 | } |
| 223 | |
| 224 | /* parse it as extension */ |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 225 | parseext: |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 226 | |
| 227 | /* first, allocate a space for the extension instance in the parent elem */ |
| 228 | reallocated = realloc(*ext, (1 + (*ext_size)) * sizeof **ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 229 | LY_CHECK_ERR_RETURN(!reallocated, LOGMEM, EXIT_FAILURE); |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 230 | (*ext) = reallocated; |
| 231 | |
| 232 | /* init memory */ |
| 233 | (*ext)[(*ext_size)] = NULL; |
| 234 | |
| 235 | /* parse YIN data */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 236 | 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] | 237 | (*ext_size)++; |
| 238 | if (r) { |
| 239 | return EXIT_FAILURE; |
| 240 | } |
| 241 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 242 | /* 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] | 243 | } |
| 244 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 245 | return EXIT_SUCCESS; |
| 246 | } |
| 247 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 248 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 249 | static int |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 250 | fill_yin_iffeature(struct lys_node *parent, int parent_is_feature, struct lyxml_elem *yin, struct lys_iffeature *iffeat, |
| 251 | struct unres_schema *unres) |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 252 | { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 253 | int r, c_ext = 0; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 254 | const char *value; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 255 | struct lyxml_elem *node, *next; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 256 | |
| 257 | GETVAL(value, yin, "name"); |
Michal Vasko | 97b32be | 2016-07-25 10:59:53 +0200 | [diff] [blame] | 258 | |
| 259 | if ((lys_node_module(parent)->version != 2) && ((value[0] == '(') || strchr(value, ' '))) { |
| 260 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "if-feature"); |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 261 | error: |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 262 | return EXIT_FAILURE; |
| 263 | } |
| 264 | |
Michal Vasko | 56d082c | 2016-10-25 14:00:42 +0200 | [diff] [blame] | 265 | if (!(value = transform_iffeat_schema2json(parent->module, value))) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 266 | return EXIT_FAILURE; |
| 267 | } |
| 268 | |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 269 | r = resolve_iffeature_compile(iffeat, value, parent, parent_is_feature, unres); |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 270 | lydict_remove(parent->module->ctx, value); |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 271 | if (r) { |
| 272 | return EXIT_FAILURE; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 273 | } |
| 274 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 275 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 276 | if (!node->ns) { |
| 277 | /* garbage */ |
| 278 | lyxml_free(parent->module->ctx, node); |
| 279 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 280 | /* extension */ |
| 281 | c_ext++; |
| 282 | } else { |
| 283 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name, "if-feature"); |
| 284 | return EXIT_FAILURE; |
| 285 | } |
| 286 | } |
| 287 | if (c_ext) { |
| 288 | iffeat->ext = calloc(c_ext, sizeof *iffeat->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 289 | LY_CHECK_ERR_RETURN(!iffeat->ext, LOGMEM, EXIT_FAILURE); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 290 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 291 | /* extensions */ |
| 292 | 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] | 293 | &iffeat->ext, iffeat->ext_size, unres); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 294 | iffeat->ext_size++; |
| 295 | if (r) { |
| 296 | return EXIT_FAILURE; |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 301 | return EXIT_SUCCESS; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | /* logs directly */ |
| 305 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 306 | 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] | 307 | { |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 308 | struct lyxml_elem *node, *next; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 309 | const char *value; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 310 | int rc; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 311 | int c_ftrs = 0, c_base = 0, c_ext = 0; |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 312 | void *reallocated; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 313 | |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 314 | GETVAL(value, yin, "name"); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 315 | ident->name = value; |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 316 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 317 | 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] | 318 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 319 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 320 | |
Pavol Vican | d6cda45 | 2016-07-13 15:08:29 +0200 | [diff] [blame] | 321 | if (dup_identities_check(ident->name, module)) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 322 | goto error; |
Pavol Vican | d6cda45 | 2016-07-13 15:08:29 +0200 | [diff] [blame] | 323 | } |
| 324 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 325 | LY_TREE_FOR(yin->child, node) { |
| 326 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 327 | /* extension */ |
| 328 | c_ext++; |
| 329 | } else if (!strcmp(node->name, "base")) { |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 330 | if (c_base && (module->version < 2)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 331 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "base", "identity"); |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 332 | goto error; |
| 333 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 334 | 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] | 335 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 336 | } |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 337 | c_base++; |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 338 | |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 339 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
| 340 | c_ftrs++; |
| 341 | |
| 342 | } else { |
| 343 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name, "identity"); |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 344 | goto error; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 345 | } |
| 346 | } |
| 347 | |
| 348 | if (c_base) { |
| 349 | ident->base_size = 0; |
| 350 | ident->base = calloc(c_base, sizeof *ident->base); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 351 | LY_CHECK_ERR_GOTO(!ident->base, LOGMEM, error); |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 352 | } |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 353 | if (c_ftrs) { |
| 354 | ident->iffeature = calloc(c_ftrs, sizeof *ident->iffeature); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 355 | LY_CHECK_ERR_GOTO(!ident->iffeature, LOGMEM, error); |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 356 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 357 | if (c_ext) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 358 | /* some extensions may be already present from the substatements */ |
| 359 | reallocated = realloc(ident->ext, (c_ext + ident->ext_size) * sizeof *ident->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 360 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 361 | ident->ext = reallocated; |
| 362 | |
| 363 | /* init memory */ |
| 364 | memset(&ident->ext[ident->ext_size], 0, c_ext * sizeof *ident->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 365 | } |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 366 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 367 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 368 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 369 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 370 | 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] | 371 | ident->ext_size++; |
| 372 | if (rc) { |
| 373 | goto error; |
| 374 | } |
| 375 | } else if (!strcmp(node->name, "base")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 376 | GETVAL(value, node, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 377 | value = transform_schema2json(module, value); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 378 | if (!value) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 379 | goto error; |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 380 | } |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 381 | |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 382 | if (unres_schema_add_str(module, unres, ident, UNRES_IDENT, value) == -1) { |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 383 | lydict_remove(module->ctx, value); |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 384 | goto error; |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 385 | } |
| 386 | lydict_remove(module->ctx, value); |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 387 | } else if (!strcmp(node->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 388 | 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] | 389 | ident->iffeature_size++; |
| 390 | if (rc) { |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 391 | goto error; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 392 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 393 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 394 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 395 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 396 | return EXIT_SUCCESS; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 397 | |
| 398 | error: |
| 399 | return EXIT_FAILURE; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 400 | } |
| 401 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 402 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 403 | static int |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 404 | 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] | 405 | struct unres_schema *unres) |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 406 | { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 407 | struct lyxml_elem *child, *next; |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 408 | const char *value; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 409 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 410 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 411 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 412 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 413 | continue; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 414 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 415 | /* extension */ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 416 | 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] | 417 | return EXIT_FAILURE; |
| 418 | } |
| 419 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 420 | if (restr->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 421 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 422 | return EXIT_FAILURE; |
| 423 | } |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 424 | 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] | 425 | return EXIT_FAILURE; |
| 426 | } |
| 427 | restr->dsc = read_yin_subnode(module->ctx, child, "text"); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 428 | if (!restr->dsc) { |
| 429 | return EXIT_FAILURE; |
| 430 | } |
| 431 | } else if (!strcmp(child->name, "reference")) { |
| 432 | if (restr->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 433 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 434 | return EXIT_FAILURE; |
| 435 | } |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 436 | 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] | 437 | return EXIT_FAILURE; |
| 438 | } |
| 439 | restr->ref = read_yin_subnode(module->ctx, child, "text"); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 440 | if (!restr->ref) { |
| 441 | return EXIT_FAILURE; |
| 442 | } |
| 443 | } else if (!strcmp(child->name, "error-app-tag")) { |
| 444 | if (restr->eapptag) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 445 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 446 | return EXIT_FAILURE; |
| 447 | } |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 448 | 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] | 449 | return EXIT_FAILURE; |
| 450 | } |
Michal Vasko | 54e426f | 2015-07-07 15:38:02 +0200 | [diff] [blame] | 451 | GETVAL(value, child, "value"); |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 452 | restr->eapptag = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 453 | } else if (!strcmp(child->name, "error-message")) { |
| 454 | if (restr->emsg) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 455 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 456 | return EXIT_FAILURE; |
| 457 | } |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 458 | 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] | 459 | return EXIT_FAILURE; |
| 460 | } |
| 461 | restr->emsg = read_yin_subnode(module->ctx, child, "value"); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 462 | if (!restr->emsg) { |
| 463 | return EXIT_FAILURE; |
| 464 | } |
| 465 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 466 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 467 | return EXIT_FAILURE; |
| 468 | } |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 469 | } |
| 470 | |
| 471 | return EXIT_SUCCESS; |
Michal Vasko | c8ef47f | 2015-06-29 14:56:19 +0200 | [diff] [blame] | 472 | |
| 473 | error: |
| 474 | return EXIT_FAILURE; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 475 | } |
| 476 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 477 | /* logs directly, returns EXIT_SUCCESS, EXIT_FAILURE, -1 */ |
| 478 | int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 479 | 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] | 480 | int parenttype, struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 481 | { |
Michal Vasko | 0aee5c1 | 2016-06-17 14:27:26 +0200 | [diff] [blame] | 482 | const char *value, *name; |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 483 | struct lys_node *siter; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 484 | struct lyxml_elem *next, *next2, *node, *child, exts; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 485 | struct lys_restr **restrs, *restr; |
Radek Krejci | 1c5890d | 2016-08-02 13:15:42 +0200 | [diff] [blame] | 486 | struct lys_type_bit bit, *bits_sc = NULL; |
| 487 | struct lys_type_enum *enms_sc = NULL; /* shortcut */ |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 488 | struct lys_type *dertype; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 489 | int i, j, rc, val_set, c_ftrs, c_ext = 0; |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 490 | int ret = -1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 491 | int64_t v, v_; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 492 | int64_t p, p_; |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 493 | size_t len; |
Radek Krejci | b53154b | 2017-07-19 09:14:13 +0200 | [diff] [blame] | 494 | int in_grp = 0; |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 495 | char *buf, modifier; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 496 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 497 | /* init */ |
| 498 | memset(&exts, 0, sizeof exts); |
| 499 | |
Radek Krejci | 8de7b0f | 2015-07-02 11:43:42 +0200 | [diff] [blame] | 500 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 501 | value = transform_schema2json(module, value); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 502 | if (!value) { |
| 503 | goto error; |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 504 | } |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 505 | |
| 506 | i = parse_identifier(value); |
| 507 | if (i < 1) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 508 | LOGVAL(LYE_INCHAR, LY_VLOG_NONE, NULL, value[-i], &value[-i]); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 509 | lydict_remove(module->ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 510 | goto error; |
| 511 | } |
| 512 | /* module name */ |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 513 | name = value; |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 514 | if (value[i]) { |
| 515 | type->module_name = lydict_insert(module->ctx, value, i); |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 516 | name += i; |
| 517 | if ((name[0] != ':') || (parse_identifier(name + 1) < 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 518 | LOGVAL(LYE_INCHAR, LY_VLOG_NONE, NULL, name[0], name); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 519 | lydict_remove(module->ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 520 | goto error; |
| 521 | } |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 522 | /* name is in dictionary, but moved */ |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 523 | ++name; |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 524 | } |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 525 | |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 526 | rc = resolve_superior_type(name, type->module_name, module, parent, &type->der); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 527 | if (rc == -1) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 528 | LOGVAL(LYE_INMOD, LY_VLOG_NONE, NULL, type->module_name); |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 529 | lydict_remove(module->ctx, value); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 530 | goto error; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 531 | |
| 532 | /* 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] | 533 | } else if (rc == EXIT_FAILURE) { |
Michal Vasko | 01c6fd2 | 2016-05-20 11:43:05 +0200 | [diff] [blame] | 534 | LOGVAL(LYE_NORESOLV, LY_VLOG_NONE, NULL, "type", name); |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 535 | lydict_remove(module->ctx, value); |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 536 | ret = EXIT_FAILURE; |
| 537 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 538 | } |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 539 | lydict_remove(module->ctx, value); |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 540 | |
Radek Krejci | 9b6aad2 | 2016-09-20 15:55:51 +0200 | [diff] [blame] | 541 | if (type->base == LY_TYPE_ERR) { |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 542 | /* 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] | 543 | * 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] | 544 | for (siter = parent; siter && (siter->nodetype != LYS_GROUPING); siter = lys_parent(siter)); |
| 545 | if (siter) { |
Radek Krejci | 93def38 | 2017-05-24 15:33:48 +0200 | [diff] [blame] | 546 | assert(((struct lys_node_grp *)siter)->unres_count); |
| 547 | ((struct lys_node_grp *)siter)->unres_count--; |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 548 | } else { |
| 549 | LOGINT; |
| 550 | goto error; |
| 551 | } |
| 552 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 553 | type->base = type->der->type.base; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 554 | |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 555 | /* check status */ |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 556 | 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] | 557 | type->der->flags, type->der->module, type->der->name, parent)) { |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 558 | return -1; |
| 559 | } |
| 560 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 561 | /* parse extension instances */ |
| 562 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 563 | if (!node->ns) { |
| 564 | /* garbage */ |
| 565 | lyxml_free(module->ctx, node); |
| 566 | continue; |
| 567 | } else if (!strcmp(node->ns->value, LY_NSYIN)) { |
| 568 | /* YANG (YIN) statements - process later */ |
| 569 | continue; |
| 570 | } |
| 571 | |
| 572 | lyxml_unlink_elem(module->ctx, node, 2); |
| 573 | lyxml_add_child(module->ctx, &exts, node); |
| 574 | c_ext++; |
| 575 | } |
| 576 | if (c_ext) { |
| 577 | type->ext = calloc(c_ext, sizeof *type->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 578 | LY_CHECK_ERR_GOTO(!type->ext, LOGMEM, error); |
| 579 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 580 | LY_TREE_FOR_SAFE(exts.child, next, node) { |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 581 | 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] | 582 | type->ext_size++; |
| 583 | if (rc) { |
| 584 | goto error; |
| 585 | } |
| 586 | } |
| 587 | } |
| 588 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 589 | switch (type->base) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 590 | case LY_TYPE_BITS: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 591 | /* RFC 6020 9.7.4 - bit */ |
| 592 | |
| 593 | /* get bit specifications, at least one must be present */ |
| 594 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 595 | if (!strcmp(node->name, "bit")) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 596 | type->info.bits.count++; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 597 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 598 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 599 | type->info.bits.count = 0; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 600 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 601 | } |
| 602 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 603 | dertype = &type->der->type; |
| 604 | if (!dertype->der) { |
| 605 | if (!type->info.bits.count) { |
| 606 | /* type is derived directly from buit-in bits type and bit statement is required */ |
| 607 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "bit", "type"); |
| 608 | goto error; |
| 609 | } |
| 610 | } else { |
| 611 | for (; !dertype->info.enums.count; dertype = &dertype->der->type); |
| 612 | if (module->version < 2 && type->info.bits.count) { |
| 613 | /* type is not directly derived from buit-in bits type and bit statement is prohibited, |
| 614 | * since YANG 1.1 the bit statements can be used to restrict the base bits type */ |
| 615 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "bit"); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 616 | type->info.bits.count = 0; |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 617 | goto error; |
| 618 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 619 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 620 | |
| 621 | type->info.bits.bit = calloc(type->info.bits.count, sizeof *type->info.bits.bit); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 622 | LY_CHECK_ERR_GOTO(!type->info.bits.bit, LOGMEM, error); |
| 623 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 624 | p = 0; |
| 625 | i = -1; |
| 626 | LY_TREE_FOR(yin->child, next) { |
| 627 | i++; |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 628 | c_ftrs = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 629 | |
| 630 | GETVAL(value, next, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 631 | if (lyp_check_identifier(value, LY_IDENT_SIMPLE, NULL, NULL)) { |
Michal Vasko | 2d26a02 | 2015-12-07 09:27:21 +0100 | [diff] [blame] | 632 | goto error; |
| 633 | } |
| 634 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 635 | 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] | 636 | 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] | 637 | type->info.bits.count = i + 1; |
| 638 | goto error; |
| 639 | } |
| 640 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 641 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 642 | /* check the name uniqueness */ |
| 643 | for (j = 0; j < i; j++) { |
| 644 | if (!strcmp(type->info.bits.bit[j].name, type->info.bits.bit[i].name)) { |
| 645 | LOGVAL(LYE_BITS_DUPNAME, LY_VLOG_NONE, NULL, type->info.bits.bit[i].name); |
| 646 | type->info.bits.count = i + 1; |
| 647 | goto error; |
| 648 | } |
| 649 | } |
| 650 | } else { |
| 651 | /* restricted bits type - the name MUST be used in the base type */ |
| 652 | bits_sc = dertype->info.bits.bit; |
| 653 | for (j = 0; j < dertype->info.bits.count; j++) { |
| 654 | if (ly_strequal(bits_sc[j].name, value, 1)) { |
| 655 | break; |
| 656 | } |
| 657 | } |
| 658 | if (j == dertype->info.bits.count) { |
| 659 | LOGVAL(LYE_BITS_INNAME, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 660 | type->info.bits.count = i + 1; |
| 661 | goto error; |
| 662 | } |
| 663 | } |
| 664 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 665 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 666 | p_ = -1; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 667 | LY_TREE_FOR_SAFE(next->child, next2, node) { |
| 668 | if (!node->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 669 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 670 | continue; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 671 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 672 | /* extension */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 673 | 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] | 674 | LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 675 | goto error; |
| 676 | } |
| 677 | } else if (!strcmp(node->name, "position")) { |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 678 | if (p_ != -1) { |
| 679 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, next->name); |
| 680 | type->info.bits.count = i + 1; |
| 681 | goto error; |
| 682 | } |
| 683 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 684 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 685 | p_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 686 | |
| 687 | /* range check */ |
Radek Krejci | b8ca108 | 2015-07-10 11:24:11 +0200 | [diff] [blame] | 688 | if (p_ < 0 || p_ > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 689 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "bit/position"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 690 | type->info.bits.count = i + 1; |
| 691 | goto error; |
| 692 | } |
| 693 | type->info.bits.bit[i].pos = (uint32_t)p_; |
| 694 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 695 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 696 | /* keep the highest enum value for automatic increment */ |
| 697 | if (type->info.bits.bit[i].pos >= p) { |
| 698 | p = type->info.bits.bit[i].pos; |
| 699 | p++; |
| 700 | } else { |
| 701 | /* check that the value is unique */ |
| 702 | for (j = 0; j < i; j++) { |
| 703 | if (type->info.bits.bit[j].pos == type->info.bits.bit[i].pos) { |
| 704 | LOGVAL(LYE_BITS_DUPVAL, LY_VLOG_NONE, NULL, |
| 705 | type->info.bits.bit[i].pos, type->info.bits.bit[i].name, |
| 706 | type->info.bits.bit[j].name); |
| 707 | type->info.bits.count = i + 1; |
| 708 | goto error; |
| 709 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 710 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 711 | } |
| 712 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 713 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 714 | 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] | 715 | LYEXT_SUBSTMT_POSITION, 0, unres)) { |
| 716 | goto error; |
| 717 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 718 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
| 719 | c_ftrs++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 720 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 721 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 722 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 723 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 724 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 725 | |
| 726 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 727 | if (p_ == -1) { |
| 728 | /* assign value automatically */ |
| 729 | if (p > UINT32_MAX) { |
| 730 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "4294967295", "bit/position"); |
| 731 | type->info.bits.count = i + 1; |
| 732 | goto error; |
| 733 | } |
| 734 | type->info.bits.bit[i].pos = (uint32_t)p; |
| 735 | type->info.bits.bit[i].flags |= LYS_AUTOASSIGNED; |
| 736 | p++; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 737 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 738 | } else { /* restricted bits type */ |
| 739 | if (p_ == -1) { |
| 740 | /* automatically assign position from base type */ |
| 741 | type->info.bits.bit[i].pos = bits_sc[j].pos; |
| 742 | type->info.bits.bit[i].flags |= LYS_AUTOASSIGNED; |
| 743 | } else { |
| 744 | /* check that the assigned position corresponds to the original |
| 745 | * position of the bit in the base type */ |
| 746 | if (p_ != bits_sc[j].pos) { |
| 747 | /* p_ - assigned position in restricted bits |
| 748 | * bits_sc[j].pos - position assigned to the corresponding bit (detected above) in base type */ |
| 749 | 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] | 750 | type->info.bits.bit[i].name, bits_sc[j].pos); |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 751 | type->info.bits.count = i + 1; |
| 752 | goto error; |
| 753 | } |
| 754 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 755 | } |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 756 | |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 757 | /* if-features */ |
| 758 | if (c_ftrs) { |
| 759 | bits_sc = &type->info.bits.bit[i]; |
| 760 | bits_sc->iffeature = calloc(c_ftrs, sizeof *bits_sc->iffeature); |
| 761 | if (!bits_sc->iffeature) { |
| 762 | LOGMEM; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 763 | type->info.bits.count = i + 1; |
| 764 | goto error; |
| 765 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 766 | |
| 767 | LY_TREE_FOR(next->child, node) { |
| 768 | if (!strcmp(node->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 769 | rc = fill_yin_iffeature((struct lys_node *)type->parent, 0, node, |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 770 | &bits_sc->iffeature[bits_sc->iffeature_size], unres); |
| 771 | bits_sc->iffeature_size++; |
| 772 | if (rc) { |
| 773 | type->info.bits.count = i + 1; |
| 774 | goto error; |
| 775 | } |
| 776 | } |
| 777 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 778 | } |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 779 | |
| 780 | /* keep them ordered by position */ |
| 781 | j = i; |
| 782 | while (j && type->info.bits.bit[j - 1].pos > type->info.bits.bit[j].pos) { |
| 783 | /* switch them */ |
| 784 | memcpy(&bit, &type->info.bits.bit[j], sizeof bit); |
| 785 | memcpy(&type->info.bits.bit[j], &type->info.bits.bit[j - 1], sizeof bit); |
| 786 | memcpy(&type->info.bits.bit[j - 1], &bit, sizeof bit); |
| 787 | j--; |
| 788 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 789 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 790 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 791 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 792 | case LY_TYPE_DEC64: |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 793 | /* RFC 6020 9.2.4 - range and 9.3.4 - fraction-digits */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 794 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 795 | |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 796 | if (!strcmp(node->name, "range")) { |
| 797 | if (type->info.dec64.range) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 798 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 799 | goto error; |
| 800 | } |
| 801 | |
| 802 | GETVAL(value, node, "value"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 803 | type->info.dec64.range = calloc(1, sizeof *type->info.dec64.range); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 804 | LY_CHECK_ERR_GOTO(!type->info.dec64.range, LOGMEM, error); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 805 | type->info.dec64.range->expr = lydict_insert(module->ctx, value, 0); |
| 806 | |
| 807 | /* get possible substatements */ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 808 | if (read_restr_substmt(module, type->info.dec64.range, node, unres)) { |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 809 | goto error; |
| 810 | } |
| 811 | } else if (!strcmp(node->name, "fraction-digits")) { |
| 812 | if (type->info.dec64.dig) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 813 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 814 | goto error; |
| 815 | } |
| 816 | GETVAL(value, node, "value"); |
| 817 | v = strtol(value, NULL, 10); |
| 818 | |
| 819 | /* range check */ |
| 820 | if (v < 1 || v > 18) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 821 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 822 | goto error; |
| 823 | } |
| 824 | type->info.dec64.dig = (uint8_t)v; |
Radek Krejci | 8c3b4b6 | 2016-06-17 14:32:12 +0200 | [diff] [blame] | 825 | type->info.dec64.div = 10; |
| 826 | for (i = 1; i < v; i++) { |
| 827 | type->info.dec64.div *= 10; |
| 828 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 829 | |
| 830 | /* extensions */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 831 | 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] | 832 | goto error; |
| 833 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 834 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 835 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 836 | goto error; |
| 837 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | /* mandatory sub-statement(s) check */ |
| 841 | if (!type->info.dec64.dig && !type->der->type.der) { |
| 842 | /* decimal64 type directly derived from built-in type requires fraction-digits */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 843 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "fraction-digits", "type"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 844 | goto error; |
| 845 | } |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 846 | if (type->info.dec64.dig && type->der->type.der) { |
| 847 | /* 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] | 848 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "fraction-digits"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 849 | goto error; |
| 850 | } |
Radek Krejci | 4800f65 | 2016-09-08 14:02:52 +0200 | [diff] [blame] | 851 | |
| 852 | /* copy fraction-digits specification from parent type for easier internal use */ |
| 853 | if (type->der->type.der) { |
| 854 | type->info.dec64.dig = type->der->type.info.dec64.dig; |
| 855 | type->info.dec64.div = type->der->type.info.dec64.div; |
| 856 | } |
| 857 | |
Pavol Vican | 3c8ee2b | 2016-09-29 13:18:13 +0200 | [diff] [blame] | 858 | if (type->info.dec64.range && lyp_check_length_range(type->info.dec64.range->expr, type)) { |
| 859 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "range"); |
| 860 | goto error; |
| 861 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 862 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 863 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 864 | case LY_TYPE_ENUM: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 865 | /* RFC 6020 9.6 - enum */ |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 866 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 867 | /* get enum specifications, at least one must be present */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 868 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 869 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 870 | if (!strcmp(node->name, "enum")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 871 | type->info.enums.count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 872 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 873 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 874 | type->info.enums.count = 0; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 875 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 876 | } |
| 877 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 878 | dertype = &type->der->type; |
| 879 | if (!dertype->der) { |
| 880 | if (!type->info.enums.count) { |
| 881 | /* type is derived directly from buit-in enumeartion type and enum statement is required */ |
| 882 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "enum", "type"); |
| 883 | goto error; |
| 884 | } |
| 885 | } else { |
| 886 | for (; !dertype->info.enums.count; dertype = &dertype->der->type); |
| 887 | if (module->version < 2 && type->info.enums.count) { |
| 888 | /* type is not directly derived from built-in enumeration type and enum statement is prohibited |
| 889 | * in YANG 1.0, since YANG 1.1 enum statements can be used to restrict the base enumeration type */ |
| 890 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "enum"); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 891 | type->info.enums.count = 0; |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 892 | goto error; |
| 893 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 894 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 895 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 896 | type->info.enums.enm = calloc(type->info.enums.count, sizeof *type->info.enums.enm); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 897 | LY_CHECK_ERR_GOTO(!type->info.enums.enm, LOGMEM, error); |
Radek Krejci | fc8d832 | 2016-06-24 11:23:23 +0200 | [diff] [blame] | 898 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 899 | v = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 900 | i = -1; |
| 901 | LY_TREE_FOR(yin->child, next) { |
| 902 | i++; |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 903 | c_ftrs = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 904 | |
| 905 | GETVAL(value, next, "name"); |
Michal Vasko | 0fb58e9 | 2015-12-07 09:27:44 +0100 | [diff] [blame] | 906 | if (!value[0]) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 907 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "enum name"); |
| 908 | 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] | 909 | goto error; |
| 910 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 911 | 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] | 912 | 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] | 913 | type->info.enums.count = i + 1; |
| 914 | goto error; |
| 915 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 916 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 917 | /* the assigned name MUST NOT have any leading or trailing whitespace characters */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 918 | value = type->info.enums.enm[i].name; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 919 | if (isspace(value[0]) || isspace(value[strlen(value) - 1])) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 920 | LOGVAL(LYE_ENUM_WS, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 921 | type->info.enums.count = i + 1; |
| 922 | goto error; |
| 923 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 924 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 925 | if (!dertype->der) { /* directly derived type from enumeration built-in type */ |
| 926 | /* check the name uniqueness */ |
| 927 | for (j = 0; j < i; j++) { |
| 928 | if (ly_strequal(type->info.enums.enm[j].name, value, 1)) { |
| 929 | LOGVAL(LYE_ENUM_DUPNAME, LY_VLOG_NONE, NULL, value); |
| 930 | type->info.enums.count = i + 1; |
| 931 | goto error; |
| 932 | } |
| 933 | } |
| 934 | } else { |
| 935 | /* restricted enumeration type - the name MUST be used in the base type */ |
| 936 | enms_sc = dertype->info.enums.enm; |
| 937 | for (j = 0; j < dertype->info.enums.count; j++) { |
| 938 | if (ly_strequal(enms_sc[j].name, value, 1)) { |
| 939 | break; |
| 940 | } |
| 941 | } |
| 942 | if (j == dertype->info.enums.count) { |
| 943 | LOGVAL(LYE_ENUM_INNAME, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 944 | type->info.enums.count = i + 1; |
| 945 | goto error; |
| 946 | } |
| 947 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 948 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 949 | val_set = 0; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 950 | LY_TREE_FOR_SAFE(next->child, next2, node) { |
| 951 | if (!node->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 952 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 953 | continue; |
Radek Krejci | 9b15fea | 2017-01-23 11:31:43 +0100 | [diff] [blame] | 954 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 955 | /* extensions */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 956 | 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] | 957 | LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 958 | goto error; |
| 959 | } |
| 960 | } else if (!strcmp(node->name, "value")) { |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 961 | if (val_set) { |
| 962 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, next->name); |
| 963 | type->info.enums.count = i + 1; |
| 964 | goto error; |
| 965 | } |
| 966 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 967 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 968 | v_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 969 | |
| 970 | /* range check */ |
| 971 | if (v_ < INT32_MIN || v_ > INT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 972 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "enum/value"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 973 | type->info.enums.count = i + 1; |
| 974 | goto error; |
| 975 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 976 | type->info.enums.enm[i].value = v_; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 977 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 978 | if (!dertype->der) { /* directly derived type from enumeration built-in type */ |
Pavol Vican | 5de389c | 2016-08-30 08:55:15 +0200 | [diff] [blame] | 979 | if (!i) { |
| 980 | /* change value, which is assigned automatically, if first enum has value. */ |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 981 | v = type->info.enums.enm[i].value; |
| 982 | v++; |
| 983 | } else { |
Pavol Vican | 5de389c | 2016-08-30 08:55:15 +0200 | [diff] [blame] | 984 | /* keep the highest enum value for automatic increment */ |
| 985 | if (type->info.enums.enm[i].value >= v) { |
| 986 | v = type->info.enums.enm[i].value; |
| 987 | v++; |
| 988 | } else { |
| 989 | /* check that the value is unique */ |
| 990 | for (j = 0; j < i; j++) { |
| 991 | if (type->info.enums.enm[j].value == type->info.enums.enm[i].value) { |
| 992 | LOGVAL(LYE_ENUM_DUPVAL, LY_VLOG_NONE, NULL, |
| 993 | type->info.enums.enm[i].value, type->info.enums.enm[i].name, |
| 994 | type->info.enums.enm[j].name); |
| 995 | type->info.enums.count = i + 1; |
| 996 | goto error; |
| 997 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 998 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 999 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1000 | } |
| 1001 | } |
Radek Krejci | fc8d832 | 2016-06-24 11:23:23 +0200 | [diff] [blame] | 1002 | val_set = 1; |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1003 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1004 | 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] | 1005 | LYEXT_SUBSTMT_VALUE, 0, unres)) { |
| 1006 | goto error; |
| 1007 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1008 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
| 1009 | c_ftrs++; |
| 1010 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1011 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1012 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1013 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1014 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1015 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1016 | |
| 1017 | if (!dertype->der) { /* directly derived type from enumeration */ |
| 1018 | if (!val_set) { |
| 1019 | /* assign value automatically */ |
| 1020 | if (v > INT32_MAX) { |
| 1021 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "2147483648", "enum/value"); |
| 1022 | type->info.enums.count = i + 1; |
| 1023 | goto error; |
| 1024 | } |
| 1025 | type->info.enums.enm[i].value = v; |
| 1026 | type->info.enums.enm[i].flags |= LYS_AUTOASSIGNED; |
| 1027 | v++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1028 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1029 | } else { /* restricted enum type */ |
| 1030 | if (!val_set) { |
| 1031 | /* automatically assign value from base type */ |
| 1032 | type->info.enums.enm[i].value = enms_sc[j].value; |
| 1033 | type->info.enums.enm[i].flags |= LYS_AUTOASSIGNED; |
| 1034 | } else { |
| 1035 | /* check that the assigned value corresponds to the original |
| 1036 | * value of the enum in the base type */ |
| 1037 | if (v_ != enms_sc[j].value) { |
| 1038 | /* v_ - assigned value in restricted enum |
| 1039 | * enms_sc[j].value - value assigned to the corresponding enum (detected above) in base type */ |
| 1040 | LOGVAL(LYE_ENUM_INVAL, LY_VLOG_NONE, NULL, |
Radek Krejci | 541a45d | 2016-08-02 13:12:07 +0200 | [diff] [blame] | 1041 | 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] | 1042 | type->info.enums.count = i + 1; |
| 1043 | goto error; |
| 1044 | } |
| 1045 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1046 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1047 | |
| 1048 | /* if-features */ |
| 1049 | if (c_ftrs) { |
| 1050 | enms_sc = &type->info.enums.enm[i]; |
| 1051 | enms_sc->iffeature = calloc(c_ftrs, sizeof *enms_sc->iffeature); |
| 1052 | if (!enms_sc->iffeature) { |
| 1053 | LOGMEM; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1054 | type->info.enums.count = i + 1; |
| 1055 | goto error; |
| 1056 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1057 | |
| 1058 | LY_TREE_FOR(next->child, node) { |
| 1059 | if (!strcmp(node->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 1060 | rc = fill_yin_iffeature((struct lys_node *)type->parent, 0, node, |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1061 | &enms_sc->iffeature[enms_sc->iffeature_size], unres); |
| 1062 | enms_sc->iffeature_size++; |
| 1063 | if (rc) { |
| 1064 | type->info.enums.count = i + 1; |
| 1065 | goto error; |
| 1066 | } |
| 1067 | } |
| 1068 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1069 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 1070 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1071 | } |
| 1072 | break; |
| 1073 | |
| 1074 | case LY_TYPE_IDENT: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 1075 | /* RFC 6020 9.10 - base */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1076 | |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1077 | /* get base specification, at least one must be present */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1078 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1079 | |
Michal Vasko | e29c662 | 2015-11-27 15:02:31 +0100 | [diff] [blame] | 1080 | if (strcmp(node->name, "base")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1081 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1082 | goto error; |
| 1083 | } |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1084 | |
| 1085 | GETVAL(value, yin->child, "name"); |
| 1086 | /* store in the JSON format */ |
| 1087 | value = transform_schema2json(module, value); |
| 1088 | if (!value) { |
| 1089 | goto error; |
| 1090 | } |
| 1091 | rc = unres_schema_add_str(module, unres, type, UNRES_TYPE_IDENTREF, value); |
| 1092 | lydict_remove(module->ctx, value); |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1093 | if (rc == -1) { |
| 1094 | goto error; |
| 1095 | } |
Radek Krejci | 18a4488 | 2017-01-23 13:47:29 +0100 | [diff] [blame] | 1096 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1097 | 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] | 1098 | goto error; |
| 1099 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1100 | } |
| 1101 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1102 | if (!yin->child) { |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 1103 | if (type->der->type.der) { |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 1104 | /* this is just a derived type with no base required */ |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 1105 | break; |
| 1106 | } |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1107 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "base", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1108 | goto error; |
Pavol Vican | f0046f4 | 2016-09-07 15:11:09 +0200 | [diff] [blame] | 1109 | } else { |
| 1110 | if (type->der->type.der) { |
| 1111 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "base"); |
| 1112 | goto error; |
| 1113 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1114 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1115 | if (yin->child->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1116 | 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] | 1117 | goto error; |
| 1118 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1119 | break; |
| 1120 | |
| 1121 | case LY_TYPE_INST: |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1122 | /* RFC 6020 9.13.2 - require-instance */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1123 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1124 | |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1125 | if (!strcmp(node->name, "require-instance")) { |
| 1126 | if (type->info.inst.req) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1127 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1128 | goto error; |
| 1129 | } |
| 1130 | GETVAL(value, node, "value"); |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 1131 | if (!strcmp(value, "true")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1132 | type->info.inst.req = 1; |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 1133 | } else if (!strcmp(value, "false")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1134 | type->info.inst.req = -1; |
| 1135 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1136 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1137 | goto error; |
| 1138 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1139 | |
| 1140 | /* extensions */ |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 1141 | 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] | 1142 | goto error; |
| 1143 | } |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1144 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1145 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1146 | goto error; |
| 1147 | } |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 1148 | } |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 1149 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1150 | break; |
| 1151 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1152 | case LY_TYPE_BINARY: |
| 1153 | /* 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] | 1154 | case LY_TYPE_INT8: |
| 1155 | case LY_TYPE_INT16: |
| 1156 | case LY_TYPE_INT32: |
| 1157 | case LY_TYPE_INT64: |
| 1158 | case LY_TYPE_UINT8: |
| 1159 | case LY_TYPE_UINT16: |
| 1160 | case LY_TYPE_UINT32: |
| 1161 | case LY_TYPE_UINT64: |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1162 | /* RFC 6020 9.2.4 - range */ |
| 1163 | |
| 1164 | /* length and range are actually the same restriction, so process |
| 1165 | * them by this common code, we just need to differ the name and |
| 1166 | * structure where the information will be stored |
| 1167 | */ |
| 1168 | if (type->base == LY_TYPE_BINARY) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1169 | restrs = &type->info.binary.length; |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1170 | name = "length"; |
| 1171 | } else { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1172 | restrs = &type->info.num.range; |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1173 | name = "range"; |
| 1174 | } |
| 1175 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1176 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1177 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1178 | if (!strcmp(node->name, name)) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1179 | if (*restrs) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1180 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1181 | goto error; |
| 1182 | } |
| 1183 | |
| 1184 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 1185 | if (lyp_check_length_range(value, type)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1186 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1187 | goto error; |
| 1188 | } |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1189 | *restrs = calloc(1, sizeof **restrs); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 1190 | LY_CHECK_ERR_GOTO(!(*restrs), LOGMEM, error); |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1191 | (*restrs)->expr = lydict_insert(module->ctx, value, 0); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1192 | |
| 1193 | /* get possible substatements */ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 1194 | if (read_restr_substmt(module, *restrs, node, unres)) { |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1195 | goto error; |
| 1196 | } |
| 1197 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1198 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1199 | goto error; |
| 1200 | } |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1201 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1202 | break; |
| 1203 | |
| 1204 | case LY_TYPE_LEAFREF: |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1205 | /* flag resolving for later use */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1206 | if (!parenttype) { |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1207 | for (siter = parent; siter && siter->nodetype != LYS_GROUPING; siter = lys_parent(siter)); |
| 1208 | if (siter) { |
| 1209 | /* just a flag - do not resolve */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1210 | parenttype = 1; |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1211 | } |
| 1212 | } |
| 1213 | |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1214 | /* RFC 6020 9.9.2 - path */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1215 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1216 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1217 | if (!strcmp(node->name, "path") && !type->der->type.der) { |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1218 | if (type->info.lref.path) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1219 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1220 | goto error; |
| 1221 | } |
| 1222 | |
| 1223 | GETVAL(value, node, "value"); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 1224 | /* store in the JSON format */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1225 | type->info.lref.path = transform_schema2json(module, value); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 1226 | if (!type->info.lref.path) { |
| 1227 | goto error; |
| 1228 | } |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1229 | |
| 1230 | /* try to resolve leafref path only when this is instantiated |
| 1231 | * leaf, so it is not: |
| 1232 | * - typedef's type, |
| 1233 | * - in grouping definition, |
| 1234 | * - just instantiated in a grouping definition, |
| 1235 | * because in those cases the nodes referenced in path might not be present |
| 1236 | * and it is not a bug. */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1237 | 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] | 1238 | goto error; |
| 1239 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1240 | |
| 1241 | /* extensions */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1242 | 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] | 1243 | goto error; |
| 1244 | } |
Radek Krejci | d6353ed | 2016-09-15 13:30:45 +0200 | [diff] [blame] | 1245 | } else if (module->version >= 2 && !strcmp(node->name, "require-instance")) { |
Michal Vasko | 08ae53e | 2016-09-02 12:40:04 +0200 | [diff] [blame] | 1246 | if (type->info.lref.req) { |
| 1247 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
| 1248 | goto error; |
| 1249 | } |
| 1250 | GETVAL(value, node, "value"); |
| 1251 | if (!strcmp(value, "true")) { |
| 1252 | type->info.lref.req = 1; |
| 1253 | } else if (!strcmp(value, "false")) { |
| 1254 | type->info.lref.req = -1; |
| 1255 | } else { |
| 1256 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
| 1257 | goto error; |
| 1258 | } |
Radek Krejci | 47f7ea5 | 2017-01-23 13:14:09 +0100 | [diff] [blame] | 1259 | |
| 1260 | /* extensions */ |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 1261 | 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] | 1262 | goto error; |
| 1263 | } |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1264 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1265 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1266 | goto error; |
| 1267 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1268 | } |
| 1269 | |
Radek Krejci | 742be35 | 2016-07-17 12:18:54 +0200 | [diff] [blame] | 1270 | if (!type->info.lref.path) { |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1271 | if (!type->der->type.der) { |
| 1272 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "path", "type"); |
| 1273 | goto error; |
| 1274 | } else { |
| 1275 | /* copy leafref definition into the derived type */ |
| 1276 | type->info.lref.path = lydict_insert(module->ctx, type->der->type.info.lref.path, 0); |
| 1277 | /* 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] | 1278 | 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] | 1279 | goto error; |
| 1280 | } |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1281 | } |
Radek Krejci | 742be35 | 2016-07-17 12:18:54 +0200 | [diff] [blame] | 1282 | } |
| 1283 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1284 | break; |
| 1285 | |
| 1286 | case LY_TYPE_STRING: |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1287 | /* RFC 6020 9.4.4 - length */ |
| 1288 | /* RFC 6020 9.4.6 - pattern */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1289 | i = 0; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1290 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1291 | |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1292 | if (!strcmp(node->name, "length")) { |
| 1293 | if (type->info.str.length) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1294 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1295 | goto error; |
| 1296 | } |
| 1297 | |
| 1298 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 1299 | if (lyp_check_length_range(value, type)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1300 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "length"); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1301 | goto error; |
| 1302 | } |
| 1303 | type->info.str.length = calloc(1, sizeof *type->info.str.length); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 1304 | LY_CHECK_ERR_GOTO(!type->info.str.length, LOGMEM, error); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1305 | type->info.str.length->expr = lydict_insert(module->ctx, value, 0); |
| 1306 | |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1307 | /* get possible sub-statements */ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 1308 | if (read_restr_substmt(module, type->info.str.length, node, unres)) { |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1309 | goto error; |
| 1310 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1311 | lyxml_free(module->ctx, node); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1312 | } else if (!strcmp(node->name, "pattern")) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1313 | i++; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1314 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1315 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1316 | goto error; |
| 1317 | } |
| 1318 | } |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1319 | /* store patterns in array */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1320 | if (i) { |
Radek Krejci | f15cc7c | 2017-07-19 12:00:02 +0200 | [diff] [blame] | 1321 | if (!parenttype && parent && lys_ingrouping(parent)) { |
Radek Krejci | b53154b | 2017-07-19 09:14:13 +0200 | [diff] [blame] | 1322 | in_grp = 1; |
| 1323 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1324 | type->info.str.patterns = calloc(i, sizeof *type->info.str.patterns); |
Michal Vasko | fcd974b | 2017-08-22 10:17:49 +0200 | [diff] [blame] | 1325 | LY_CHECK_ERR_GOTO(!type->info.str.patterns, LOGMEM, error); |
| 1326 | #ifdef LY_ENABLED_CACHE |
Radek Krejci | b53154b | 2017-07-19 09:14:13 +0200 | [diff] [blame] | 1327 | if (!in_grp) { |
| 1328 | /* do not compile patterns in groupings */ |
| 1329 | type->info.str.patterns_pcre = malloc(2 * i * sizeof *type->info.str.patterns_pcre); |
Michal Vasko | fcd974b | 2017-08-22 10:17:49 +0200 | [diff] [blame] | 1330 | LY_CHECK_ERR_GOTO(!type->info.str.patterns_pcre, LOGMEM, error); |
Radek Krejci | b53154b | 2017-07-19 09:14:13 +0200 | [diff] [blame] | 1331 | } |
Michal Vasko | fcd974b | 2017-08-22 10:17:49 +0200 | [diff] [blame] | 1332 | #endif |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1333 | LY_TREE_FOR(yin->child, node) { |
Michal Vasko | 5b64da2 | 2015-11-23 15:22:30 +0100 | [diff] [blame] | 1334 | GETVAL(value, node, "value"); |
Radek Krejci | b53154b | 2017-07-19 09:14:13 +0200 | [diff] [blame] | 1335 | |
Michal Vasko | fcd974b | 2017-08-22 10:17:49 +0200 | [diff] [blame] | 1336 | if (!(module->ctx->models.flags & LY_CTX_TRUSTED)) { |
| 1337 | if (in_grp) { |
| 1338 | /* in grouping, just check the pattern syntax */ |
| 1339 | if (lyp_check_pattern(value, NULL)) { |
| 1340 | goto error; |
| 1341 | } |
Radek Krejci | b53154b | 2017-07-19 09:14:13 +0200 | [diff] [blame] | 1342 | } |
Michal Vasko | fcd974b | 2017-08-22 10:17:49 +0200 | [diff] [blame] | 1343 | #ifdef LY_ENABLED_CACHE |
| 1344 | else { |
| 1345 | /* outside grouping, check syntax and precompile pattern for later use by libpcre */ |
| 1346 | if (lyp_precompile_pattern(value, |
| 1347 | (pcre**)&type->info.str.patterns_pcre[type->info.str.pat_count * 2], |
| 1348 | (pcre_extra**)&type->info.str.patterns_pcre[type->info.str.pat_count * 2 + 1])) { |
| 1349 | goto error; |
| 1350 | } |
Radek Krejci | b53154b | 2017-07-19 09:14:13 +0200 | [diff] [blame] | 1351 | } |
Michal Vasko | fcd974b | 2017-08-22 10:17:49 +0200 | [diff] [blame] | 1352 | #endif |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1353 | } |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1354 | restr = &type->info.str.patterns[type->info.str.pat_count]; /* shortcut */ |
Radek Krejci | b53154b | 2017-07-19 09:14:13 +0200 | [diff] [blame] | 1355 | type->info.str.pat_count++; |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1356 | |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1357 | modifier = 0x06; /* ACK */ |
| 1358 | name = NULL; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1359 | if (module->version >= 2) { |
| 1360 | LY_TREE_FOR_SAFE(node->child, next2, child) { |
| 1361 | if (child->ns && !strcmp(child->ns->value, LY_NSYIN) && !strcmp(child->name, "modifier")) { |
| 1362 | if (name) { |
| 1363 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "modifier", node->name); |
| 1364 | goto error; |
| 1365 | } |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1366 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1367 | GETVAL(name, child, "value"); |
| 1368 | if (!strcmp(name, "invert-match")) { |
| 1369 | modifier = 0x15; /* NACK */ |
| 1370 | } else { |
| 1371 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, name, "modifier"); |
| 1372 | goto error; |
| 1373 | } |
| 1374 | /* get extensions of the modifier */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1375 | if (lyp_yin_parse_subnode_ext(module, restr, LYEXT_PAR_RESTR, child, |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 1376 | LYEXT_SUBSTMT_MODIFIER, 0, unres)) { |
| 1377 | goto error; |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1378 | } |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1379 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1380 | lyxml_free(module->ctx, child); |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1381 | } |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1382 | } |
| 1383 | } |
| 1384 | |
| 1385 | len = strlen(value); |
| 1386 | buf = malloc((len + 2) * sizeof *buf); /* modifier byte + value + terminating NULL byte */ |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 1387 | LY_CHECK_ERR_GOTO(!buf, LOGMEM, error); |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1388 | buf[0] = modifier; |
| 1389 | strcpy(&buf[1], value); |
| 1390 | |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1391 | restr->expr = lydict_insert_zc(module->ctx, buf); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1392 | |
| 1393 | /* get possible sub-statements */ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 1394 | if (read_restr_substmt(module, restr, node, unres)) { |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1395 | goto error; |
| 1396 | } |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1397 | } |
| 1398 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1399 | break; |
| 1400 | |
| 1401 | case LY_TYPE_UNION: |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1402 | /* RFC 6020 7.4 - type */ |
| 1403 | /* count number of types in union */ |
| 1404 | i = 0; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1405 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1406 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1407 | if (!strcmp(node->name, "type")) { |
Radek Krejci | 038d5d9 | 2016-09-12 15:07:15 +0200 | [diff] [blame] | 1408 | if (type->der->type.der) { |
| 1409 | /* type can be a substatement only in "union" type, not in derived types */ |
| 1410 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "derived type"); |
| 1411 | goto error; |
| 1412 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1413 | i++; |
| 1414 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1415 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1416 | goto error; |
| 1417 | } |
| 1418 | } |
| 1419 | |
Radek Krejci | 038d5d9 | 2016-09-12 15:07:15 +0200 | [diff] [blame] | 1420 | if (!i && !type->der->type.der) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1421 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", "(union) type"); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1422 | goto error; |
| 1423 | } |
| 1424 | |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1425 | /* inherit instid presence information */ |
| 1426 | if ((type->der->type.base == LY_TYPE_UNION) && type->der->type.info.uni.has_ptr_type) { |
| 1427 | type->info.uni.has_ptr_type = 1; |
| 1428 | } |
| 1429 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1430 | /* allocate array for union's types ... */ |
Michal Vasko | adeddfc | 2017-06-30 13:12:42 +0200 | [diff] [blame] | 1431 | if (i) { |
| 1432 | type->info.uni.types = calloc(i, sizeof *type->info.uni.types); |
| 1433 | LY_CHECK_ERR_GOTO(!type->info.uni.types, LOGMEM, error); |
| 1434 | } |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 1435 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1436 | /* ... and fill the structures */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1437 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 1438 | type->info.uni.types[type->info.uni.count].parent = type->parent; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1439 | 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] | 1440 | if (!rc) { |
| 1441 | type->info.uni.count++; |
| 1442 | |
Radek Krejci | 7de36cf | 2016-09-12 16:18:50 +0200 | [diff] [blame] | 1443 | if (module->version < 2) { |
| 1444 | /* union's type cannot be empty or leafref */ |
| 1445 | if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_EMPTY) { |
| 1446 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "empty", node->name); |
| 1447 | rc = -1; |
| 1448 | } else if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_LEAFREF) { |
| 1449 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "leafref", node->name); |
| 1450 | rc = -1; |
| 1451 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1452 | } |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1453 | |
| 1454 | if ((type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_INST) |
| 1455 | || (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_LEAFREF)) { |
| 1456 | type->info.uni.has_ptr_type = 1; |
| 1457 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1458 | } |
| 1459 | if (rc) { |
| 1460 | /* even if we got EXIT_FAILURE, throw it all away, too much trouble doing something else */ |
| 1461 | for (i = 0; i < type->info.uni.count; ++i) { |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 1462 | lys_type_free(module->ctx, &type->info.uni.types[i], NULL); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1463 | } |
| 1464 | free(type->info.uni.types); |
| 1465 | type->info.uni.types = NULL; |
| 1466 | type->info.uni.count = 0; |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1467 | type->info.uni.has_ptr_type = 0; |
Michal Vasko | eac0818 | 2016-07-21 12:16:32 +0200 | [diff] [blame] | 1468 | type->der = NULL; |
| 1469 | type->base = LY_TYPE_DER; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1470 | |
| 1471 | if (rc == EXIT_FAILURE) { |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 1472 | ret = EXIT_FAILURE; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1473 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1474 | goto error; |
| 1475 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1476 | } |
| 1477 | break; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1478 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1479 | case LY_TYPE_BOOL: |
| 1480 | case LY_TYPE_EMPTY: |
| 1481 | /* no sub-statement allowed */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1482 | if (yin->child) { |
| 1483 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, yin->child->name); |
| 1484 | goto error; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1485 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1486 | break; |
| 1487 | |
| 1488 | default: |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1489 | LOGINT; |
| 1490 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1491 | } |
| 1492 | |
| 1493 | return EXIT_SUCCESS; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 1494 | |
| 1495 | error: |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 1496 | if (type->module_name) { |
| 1497 | lydict_remove(module->ctx, type->module_name); |
| 1498 | type->module_name = NULL; |
| 1499 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1500 | lyxml_free_withsiblings(module->ctx, exts.child); |
| 1501 | |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 1502 | return ret; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1503 | } |
| 1504 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1505 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1506 | static int |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1507 | fill_yin_typedef(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_tpdf *tpdf, |
| 1508 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1509 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1510 | const char *value; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1511 | struct lyxml_elem *node, *next; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1512 | int rc, has_type = 0, c_ext = 0; |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1513 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1514 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1515 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1516 | if (lyp_check_identifier(value, LY_IDENT_TYPE, module, parent)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1517 | goto error; |
| 1518 | } |
| 1519 | tpdf->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1520 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1521 | /* generic part - status, description, reference */ |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1522 | 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] | 1523 | goto error; |
| 1524 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1525 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1526 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1527 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 1528 | /* extension */ |
| 1529 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1530 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1531 | } else if (!strcmp(node->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 1532 | if (has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1533 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1534 | goto error; |
| 1535 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1536 | /* HACK for unres */ |
| 1537 | tpdf->type.der = (struct lys_tpdf *)node; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 1538 | tpdf->type.parent = tpdf; |
Michal Vasko | 5d63140 | 2016-07-21 13:15:15 +0200 | [diff] [blame] | 1539 | 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] | 1540 | goto error; |
| 1541 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1542 | has_type = 1; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1543 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1544 | /* 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] | 1545 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1546 | } else if (!strcmp(node->name, "default")) { |
| 1547 | if (tpdf->dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1548 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1549 | goto error; |
| 1550 | } |
| 1551 | GETVAL(value, node, "value"); |
| 1552 | tpdf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1553 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1554 | 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] | 1555 | goto error; |
| 1556 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1557 | } else if (!strcmp(node->name, "units")) { |
| 1558 | if (tpdf->units) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1559 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1560 | goto error; |
| 1561 | } |
| 1562 | GETVAL(value, node, "name"); |
| 1563 | tpdf->units = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1564 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1565 | 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] | 1566 | goto error; |
| 1567 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1568 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1569 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1570 | goto error; |
| 1571 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1572 | |
| 1573 | lyxml_free(module->ctx, node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1574 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 1575 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1576 | /* check mandatory value */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1577 | if (!has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1578 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1579 | goto error; |
| 1580 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1581 | |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 1582 | /* check default value (if not defined, there still could be some restrictions |
| 1583 | * 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] | 1584 | 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] | 1585 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1586 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1587 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1588 | /* finish extensions parsing */ |
| 1589 | if (c_ext) { |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1590 | /* some extensions may be already present from the substatements */ |
| 1591 | reallocated = realloc(tpdf->ext, (c_ext + tpdf->ext_size) * sizeof *tpdf->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 1592 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | 59a349f | 2017-01-24 10:14:31 +0100 | [diff] [blame] | 1593 | tpdf->ext = reallocated; |
| 1594 | |
| 1595 | /* init memory */ |
| 1596 | memset(&tpdf->ext[tpdf->ext_size], 0, c_ext * sizeof *tpdf->ext); |
| 1597 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1598 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 1599 | 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] | 1600 | tpdf->ext_size++; |
| 1601 | if (rc) { |
| 1602 | goto error; |
| 1603 | } |
| 1604 | } |
| 1605 | } |
| 1606 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1607 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1608 | |
| 1609 | error: |
| 1610 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1611 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1612 | } |
| 1613 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1614 | static int |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1615 | 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] | 1616 | { |
| 1617 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1618 | struct lyxml_elem *child, *node, *next, *next2; |
| 1619 | int c_ext = 0, rc; |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1620 | void *reallocated; |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1621 | |
| 1622 | GETVAL(value, yin, "name"); |
| 1623 | |
| 1624 | if (lyp_check_identifier(value, LY_IDENT_EXTENSION, module, NULL)) { |
| 1625 | goto error; |
| 1626 | } |
| 1627 | ext->name = lydict_insert(module->ctx, value, strlen(value)); |
| 1628 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1629 | 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] | 1630 | goto error; |
| 1631 | } |
| 1632 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1633 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 1634 | if (strcmp(node->ns->value, LY_NSYIN)) { |
| 1635 | /* possible extension instance */ |
| 1636 | c_ext++; |
| 1637 | } else if (!strcmp(node->name, "argument")) { |
| 1638 | /* argument */ |
| 1639 | GETVAL(value, node, "name"); |
| 1640 | ext->argument = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1641 | 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] | 1642 | goto error; |
| 1643 | } |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1644 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1645 | /* yin-element */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1646 | LY_TREE_FOR_SAFE(node->child, next2, child) { |
| 1647 | if (child->ns == node->ns && !strcmp(child->name, "yin-element")) { |
| 1648 | GETVAL(value, child, "value"); |
| 1649 | if (ly_strequal(value, "true", 0)) { |
| 1650 | ext->flags |= LYS_YINELEM; |
| 1651 | } |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1652 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 1653 | 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] | 1654 | goto error; |
| 1655 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1656 | } else if (child->ns) { |
| 1657 | /* unexpected YANG statement */ |
| 1658 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->name); |
| 1659 | goto error; |
| 1660 | } /* else garbage, but save resource needed for unlinking */ |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1661 | } |
| 1662 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1663 | lyxml_free(module->ctx, node); |
| 1664 | } else { |
| 1665 | /* unexpected YANG statement */ |
| 1666 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->name); |
| 1667 | goto error; |
| 1668 | } |
| 1669 | } |
| 1670 | |
| 1671 | if (c_ext) { |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1672 | /* some extensions may be already present from the substatements */ |
| 1673 | reallocated = realloc(ext->ext, (c_ext + ext->ext_size) * sizeof *ext->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 1674 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | 1fb0218 | 2017-01-24 11:20:55 +0100 | [diff] [blame] | 1675 | ext->ext = reallocated; |
| 1676 | |
| 1677 | /* init memory */ |
| 1678 | memset(&ext->ext[ext->ext_size], 0, c_ext * sizeof *ext->ext); |
| 1679 | |
| 1680 | /* process the extension instances of the extension itself */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1681 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 1682 | 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] | 1683 | ext->ext_size++; |
| 1684 | if (rc) { |
| 1685 | goto error; |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 1686 | } |
| 1687 | } |
| 1688 | } |
| 1689 | |
Radek Krejci | 0a498f8 | 2017-01-04 16:24:15 +0100 | [diff] [blame] | 1690 | /* search for plugin */ |
| 1691 | 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] | 1692 | |
| 1693 | return EXIT_SUCCESS; |
| 1694 | |
| 1695 | error: |
| 1696 | return EXIT_FAILURE; |
| 1697 | } |
| 1698 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1699 | /* logs directly */ |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1700 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 1701 | 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] | 1702 | { |
| 1703 | const char *value; |
| 1704 | struct lyxml_elem *child, *next; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1705 | int c_ftrs = 0, c_ext = 0, ret; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 1706 | void *reallocated; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1707 | |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1708 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1709 | if (lyp_check_identifier(value, LY_IDENT_FEATURE, module, NULL)) { |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1710 | goto error; |
| 1711 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1712 | f->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 1713 | f->module = module; |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1714 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 1715 | 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] | 1716 | goto error; |
| 1717 | } |
| 1718 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1719 | LY_TREE_FOR(yin->child, child) { |
| 1720 | if (strcmp(child->ns->value, LY_NSYIN)) { |
| 1721 | /* extension */ |
| 1722 | c_ext++; |
| 1723 | } else if (!strcmp(child->name, "if-feature")) { |
| 1724 | c_ftrs++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1725 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1726 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1727 | goto error; |
| 1728 | } |
| 1729 | } |
| 1730 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1731 | if (c_ftrs) { |
| 1732 | f->iffeature = calloc(c_ftrs, sizeof *f->iffeature); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 1733 | LY_CHECK_ERR_GOTO(!f->iffeature, LOGMEM, error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1734 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1735 | if (c_ext) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 1736 | /* some extensions may be already present from the substatements */ |
| 1737 | reallocated = realloc(f->ext, (c_ext + f->ext_size) * sizeof *f->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 1738 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 1739 | f->ext = reallocated; |
| 1740 | |
| 1741 | /* init memory */ |
| 1742 | memset(&f->ext[f->ext_size], 0, c_ext * sizeof *f->ext); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1743 | } |
| 1744 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 1745 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 1746 | if (strcmp(child->ns->value, LY_NSYIN)) { |
| 1747 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 1748 | 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] | 1749 | f->ext_size++; |
| 1750 | if (ret) { |
| 1751 | goto error; |
| 1752 | } |
| 1753 | } else { /* if-feature */ |
| 1754 | ret = fill_yin_iffeature((struct lys_node *)f, 1, child, &f->iffeature[f->iffeature_size], unres); |
| 1755 | f->iffeature_size++; |
| 1756 | if (ret) { |
| 1757 | goto error; |
| 1758 | } |
| 1759 | } |
| 1760 | } |
| 1761 | |
Radek Krejci | c79c6b1 | 2016-07-26 15:11:49 +0200 | [diff] [blame] | 1762 | /* check for circular dependencies */ |
| 1763 | if (f->iffeature_size) { |
| 1764 | if (unres_schema_add_node(module, unres, f, UNRES_FEATURE, NULL) == -1) { |
| 1765 | goto error; |
| 1766 | } |
| 1767 | } |
| 1768 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1769 | return EXIT_SUCCESS; |
| 1770 | |
| 1771 | error: |
| 1772 | |
| 1773 | return EXIT_FAILURE; |
| 1774 | } |
| 1775 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1776 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1777 | static int |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 1778 | 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] | 1779 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1780 | const char *value; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1781 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1782 | GETVAL(value, yin, "condition"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1783 | must->expr = transform_schema2json(module, value); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 1784 | if (!must->expr) { |
| 1785 | goto error; |
| 1786 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1787 | |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 1788 | return read_restr_substmt(module, must, yin, unres); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1789 | |
Michal Vasko | 77dc565 | 2016-02-15 12:32:42 +0100 | [diff] [blame] | 1790 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1791 | return EXIT_FAILURE; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1792 | } |
| 1793 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1794 | static int |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 1795 | fill_yin_revision(struct lys_module *module, struct lyxml_elem *yin, struct lys_revision *rev, |
| 1796 | struct unres_schema *unres) |
| 1797 | { |
| 1798 | struct lyxml_elem *next, *child; |
| 1799 | const char *value; |
| 1800 | |
| 1801 | GETVAL(value, yin, "date"); |
| 1802 | if (lyp_check_date(value)) { |
| 1803 | goto error; |
| 1804 | } |
| 1805 | memcpy(rev->date, value, LY_REV_SIZE - 1); |
| 1806 | |
| 1807 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 1808 | if (!child->ns) { |
| 1809 | /* garbage */ |
| 1810 | continue; |
| 1811 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 1812 | /* possible extension instance */ |
| 1813 | if (lyp_yin_parse_subnode_ext(module, rev, LYEXT_PAR_REVISION, |
| 1814 | child, LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 1815 | goto error; |
| 1816 | } |
| 1817 | } else if (!strcmp(child->name, "description")) { |
| 1818 | if (rev->dsc) { |
| 1819 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 1820 | goto error; |
| 1821 | } |
| 1822 | if (lyp_yin_parse_subnode_ext(module, rev, LYEXT_PAR_REVISION, |
| 1823 | child, LYEXT_SUBSTMT_DESCRIPTION, 0, unres)) { |
| 1824 | goto error; |
| 1825 | } |
| 1826 | rev->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 1827 | if (!rev->dsc) { |
| 1828 | goto error; |
| 1829 | } |
| 1830 | } else if (!strcmp(child->name, "reference")) { |
| 1831 | if (rev->ref) { |
| 1832 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 1833 | goto error; |
| 1834 | } |
| 1835 | if (lyp_yin_parse_subnode_ext(module, rev, LYEXT_PAR_REVISION, |
| 1836 | child, LYEXT_SUBSTMT_REFERENCE, 0, unres)) { |
| 1837 | goto error; |
| 1838 | } |
| 1839 | rev->ref = read_yin_subnode(module->ctx, child, "text"); |
| 1840 | if (!rev->ref) { |
| 1841 | goto error; |
| 1842 | } |
| 1843 | } else { |
| 1844 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1845 | goto error; |
| 1846 | } |
| 1847 | } |
| 1848 | |
| 1849 | return EXIT_SUCCESS; |
| 1850 | |
| 1851 | error: |
| 1852 | return EXIT_FAILURE; |
| 1853 | } |
| 1854 | |
| 1855 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1856 | fill_yin_unique(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_unique *unique, |
| 1857 | struct unres_schema *unres) |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1858 | { |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 1859 | int i, j, ret = EXIT_FAILURE; |
| 1860 | const char *orig; |
Radek Krejci | 2449b39 | 2017-04-25 09:37:16 +0200 | [diff] [blame] | 1861 | char *value, *vaux, *start = NULL, c; |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 1862 | struct unres_list_uniq *unique_info; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1863 | |
| 1864 | /* get unique value (list of leafs supposed to be unique */ |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 1865 | GETVAL(orig, yin, "tag"); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1866 | |
| 1867 | /* count the number of unique leafs in the value */ |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 1868 | start = value = vaux = strdup(orig); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 1869 | LY_CHECK_ERR_GOTO(!vaux, LOGMEM, error); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1870 | while ((vaux = strpbrk(vaux, " \t\n"))) { |
Michal Vasko | 98645db | 2016-03-07 14:38:49 +0100 | [diff] [blame] | 1871 | unique->expr_size++; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1872 | while (isspace(*vaux)) { |
| 1873 | vaux++; |
| 1874 | } |
| 1875 | } |
| 1876 | unique->expr_size++; |
| 1877 | unique->expr = calloc(unique->expr_size, sizeof *unique->expr); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 1878 | LY_CHECK_ERR_GOTO(!unique->expr, LOGMEM, error); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1879 | |
| 1880 | for (i = 0; i < unique->expr_size; i++) { |
| 1881 | vaux = strpbrk(value, " \t\n"); |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 1882 | if (vaux) { |
| 1883 | c = *vaux; |
| 1884 | *vaux = '\0'; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | /* store token into unique structure */ |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 1888 | unique->expr[i] = transform_schema2json(module, value); |
| 1889 | if (vaux) { |
| 1890 | *vaux = c; |
| 1891 | } |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1892 | |
| 1893 | /* check that the expression does not repeat */ |
| 1894 | for (j = 0; j < i; j++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 1895 | if (ly_strequal(unique->expr[j], unique->expr[i], 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1896 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, unique->expr[i], "unique"); |
| 1897 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "The identifier is not unique"); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1898 | goto error; |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | /* try to resolve leaf */ |
| 1903 | if (unres) { |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 1904 | unique_info = malloc(sizeof *unique_info); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 1905 | LY_CHECK_ERR_GOTO(!unique_info, LOGMEM, error); |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 1906 | unique_info->list = parent; |
| 1907 | unique_info->expr = unique->expr[i]; |
| 1908 | unique_info->trg_type = &unique->trg_type; |
| 1909 | 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] | 1910 | goto error; |
| 1911 | } |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1912 | } else { |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 1913 | if (resolve_unique(parent, unique->expr[i], &unique->trg_type)) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1914 | goto error; |
| 1915 | } |
| 1916 | } |
| 1917 | |
| 1918 | /* move to next token */ |
| 1919 | value = vaux; |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 1920 | while(value && isspace(*value)) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1921 | value++; |
| 1922 | } |
| 1923 | } |
| 1924 | |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 1925 | ret = EXIT_SUCCESS; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1926 | |
| 1927 | error: |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 1928 | free(start); |
| 1929 | return ret; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1930 | } |
| 1931 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1932 | /* logs directly |
| 1933 | * |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1934 | * type: 0 - min, 1 - max |
| 1935 | */ |
| 1936 | static int |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1937 | 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] | 1938 | { |
| 1939 | const char *value; |
| 1940 | char *endptr; |
| 1941 | unsigned long val; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1942 | uint32_t *ui32val, *min, *max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1943 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1944 | /* del min/max is forbidden */ |
| 1945 | if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1946 | 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] | 1947 | goto error; |
| 1948 | } |
| 1949 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1950 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1951 | if (target->nodetype == LYS_LEAFLIST) { |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1952 | max = &((struct lys_node_leaflist *)target)->max; |
| 1953 | min = &((struct lys_node_leaflist *)target)->min; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1954 | } else if (target->nodetype == LYS_LIST) { |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1955 | max = &((struct lys_node_list *)target)->max; |
| 1956 | min = &((struct lys_node_list *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1957 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1958 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
| 1959 | 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] | 1960 | goto error; |
| 1961 | } |
| 1962 | |
| 1963 | GETVAL(value, node, "value"); |
| 1964 | while (isspace(value[0])) { |
| 1965 | value++; |
| 1966 | } |
| 1967 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1968 | if (type && !strcmp(value, "unbounded")) { |
| 1969 | d->max = val = 0; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 1970 | d->max_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1971 | ui32val = max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1972 | } else { |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1973 | /* convert it to uint32_t */ |
| 1974 | errno = 0; |
| 1975 | endptr = NULL; |
| 1976 | val = strtoul(value, &endptr, 10); |
| 1977 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1978 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1979 | goto error; |
| 1980 | } |
| 1981 | if (type) { |
| 1982 | d->max = (uint32_t)val; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 1983 | d->max_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1984 | ui32val = max; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1985 | } else { |
| 1986 | d->min = (uint32_t)val; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 1987 | d->min_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1988 | ui32val = min; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1989 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1990 | } |
| 1991 | |
| 1992 | if (d->mod == LY_DEVIATE_ADD) { |
| 1993 | /* check that there is no current value */ |
| 1994 | if (*ui32val) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1995 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
| 1996 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1997 | goto error; |
| 1998 | } |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 1999 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2000 | /* unfortunately, there is no way to check reliably that there |
| 2001 | * was a value before, it could have been the default */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2002 | } |
| 2003 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2004 | /* add (already checked) and replace */ |
| 2005 | /* set new value specified in deviation */ |
| 2006 | *ui32val = (uint32_t)val; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2007 | |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2008 | /* check min-elements is smaller than max-elements */ |
| 2009 | if (*max && *min > *max) { |
| 2010 | if (type) { |
Radek Krejci | 73f9601 | 2016-10-03 13:53:53 +0200 | [diff] [blame] | 2011 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "max-elements"); |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2012 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"max-elements\" is smaller than \"min-elements\"."); |
| 2013 | } else { |
Radek Krejci | 73f9601 | 2016-10-03 13:53:53 +0200 | [diff] [blame] | 2014 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "min-elements"); |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2015 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"min-elements\" is bigger than \"max-elements\"."); |
| 2016 | } |
| 2017 | goto error; |
| 2018 | } |
| 2019 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2020 | return EXIT_SUCCESS; |
| 2021 | |
| 2022 | error: |
| 2023 | |
| 2024 | return EXIT_FAILURE; |
| 2025 | } |
| 2026 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2027 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2028 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 2029 | fill_yin_deviation(struct lys_module *module, struct lyxml_elem *yin, struct lys_deviation *dev, |
| 2030 | struct unres_schema *unres) |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2031 | { |
| 2032 | const char *value, **stritem; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2033 | struct lyxml_elem *next, *next2, *child, *develem; |
| 2034 | 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] | 2035 | int f_min = 0, f_max = 0; /* flags */ |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2036 | int i, j, k, rc; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2037 | unsigned int u; |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2038 | struct ly_ctx *ctx; |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 2039 | struct lys_deviate *d = NULL; |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2040 | struct lys_node *node = NULL, *parent, *dev_target = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2041 | struct lys_node_choice *choice = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2042 | struct lys_node_leaf *leaf = NULL; |
Michal Vasko | 5057671 | 2017-07-28 12:28:33 +0200 | [diff] [blame] | 2043 | struct ly_set *dflt_check = ly_set_new(), *set; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2044 | struct lys_node_list *list = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2045 | struct lys_node_leaflist *llist = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2046 | struct lys_type *t = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2047 | uint8_t *trg_must_size = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2048 | struct lys_restr **trg_must = NULL; |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2049 | struct unres_schema tmp_unres; |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 2050 | struct lys_module *mod; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2051 | void *reallocated; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2052 | |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2053 | ctx = module->ctx; |
| 2054 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2055 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2056 | dev->target_name = transform_schema2json(module, value); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 2057 | if (!dev->target_name) { |
| 2058 | goto error; |
| 2059 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2060 | |
| 2061 | /* resolve target node */ |
Michal Vasko | 5057671 | 2017-07-28 12:28:33 +0200 | [diff] [blame] | 2062 | rc = resolve_schema_nodeid(dev->target_name, NULL, module, &set, 0, 1); |
| 2063 | if (rc == -1) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2064 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, yin->name); |
Michal Vasko | 5057671 | 2017-07-28 12:28:33 +0200 | [diff] [blame] | 2065 | ly_set_free(set); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2066 | goto error; |
| 2067 | } |
Michal Vasko | 5057671 | 2017-07-28 12:28:33 +0200 | [diff] [blame] | 2068 | dev_target = set->set.s[0]; |
| 2069 | ly_set_free(set); |
| 2070 | |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 2071 | if (dev_target->module == lys_main_module(module)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2072 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, yin->name); |
| 2073 | 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] | 2074 | goto error; |
| 2075 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2076 | |
| 2077 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2078 | if (!child->ns ) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2079 | /* garbage */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2080 | lyxml_free(ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2081 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2082 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 2083 | /* extension */ |
| 2084 | c_ext++; |
| 2085 | continue; |
| 2086 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2087 | if (dev->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2088 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2089 | goto error; |
| 2090 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2091 | 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] | 2092 | goto error; |
| 2093 | } |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2094 | dev->dsc = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2095 | if (!dev->dsc) { |
| 2096 | goto error; |
| 2097 | } |
| 2098 | } else if (!strcmp(child->name, "reference")) { |
| 2099 | if (dev->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2100 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2101 | goto error; |
| 2102 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2103 | 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] | 2104 | goto error; |
| 2105 | } |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2106 | dev->ref = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2107 | if (!dev->ref) { |
| 2108 | goto error; |
| 2109 | } |
| 2110 | } else if (!strcmp(child->name, "deviate")) { |
| 2111 | c_dev++; |
| 2112 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2113 | /* skip lyxml_free() at the end of the loop, node will be |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2114 | * further processed later |
| 2115 | */ |
| 2116 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 2117 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2118 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2119 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2120 | goto error; |
| 2121 | } |
| 2122 | |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2123 | lyxml_free(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2124 | } |
| 2125 | |
| 2126 | if (c_dev) { |
| 2127 | dev->deviate = calloc(c_dev, sizeof *dev->deviate); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 2128 | LY_CHECK_ERR_GOTO(!dev->deviate, LOGMEM, error); |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 2129 | } else { |
| 2130 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "deviate", "deviation"); |
| 2131 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2132 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2133 | if (c_ext) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2134 | /* some extensions may be already present from the substatements */ |
| 2135 | reallocated = realloc(dev->ext, (c_ext + dev->ext_size) * sizeof *dev->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 2136 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2137 | dev->ext = reallocated; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2138 | |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2139 | /* init memory */ |
| 2140 | memset(&dev->ext[dev->ext_size], 0, c_ext * sizeof *dev->ext); |
| 2141 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2142 | |
| 2143 | LY_TREE_FOR_SAFE(yin->child, next, develem) { |
| 2144 | if (strcmp(develem->ns->value, LY_NSYIN)) { |
| 2145 | /* deviation's extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 2146 | 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] | 2147 | dev->ext_size++; |
| 2148 | if (rc) { |
| 2149 | goto error; |
| 2150 | } |
| 2151 | continue; |
| 2152 | } |
| 2153 | |
| 2154 | /* deviate */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2155 | /* init */ |
| 2156 | f_min = 0; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2157 | f_max = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2158 | c_must = 0; |
| 2159 | c_uniq = 0; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2160 | c_dflt = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2161 | c_ext = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2162 | |
| 2163 | /* get deviation type */ |
| 2164 | GETVAL(value, develem, "value"); |
| 2165 | if (!strcmp(value, "not-supported")) { |
| 2166 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_NO; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2167 | /* no other deviate statement is expected, |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 2168 | * not-supported deviation must be the only deviation of the target |
| 2169 | */ |
| 2170 | if (dev->deviate_size || develem->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2171 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
| 2172 | 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] | 2173 | goto error; |
| 2174 | } |
| 2175 | |
Michal Vasko | ad1f7b7 | 2016-02-17 11:13:58 +0100 | [diff] [blame] | 2176 | /* you cannot remove a key leaf */ |
Michal Vasko | 43c9477 | 2016-05-03 11:47:44 +0200 | [diff] [blame] | 2177 | if ((dev_target->nodetype == LYS_LEAF) && lys_parent(dev_target) && (lys_parent(dev_target)->nodetype == LYS_LIST)) { |
| 2178 | for (i = 0; i < ((struct lys_node_list *)lys_parent(dev_target))->keys_size; ++i) { |
| 2179 | 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] | 2180 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
| 2181 | 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] | 2182 | goto error; |
| 2183 | } |
| 2184 | } |
| 2185 | } |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 2186 | |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2187 | /* unlink and store the original node */ |
Radek Krejci | 30bfcd2 | 2017-01-27 16:54:48 +0100 | [diff] [blame] | 2188 | parent = dev_target->parent; |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2189 | lys_node_unlink(dev_target); |
Radek Krejci | 30bfcd2 | 2017-01-27 16:54:48 +0100 | [diff] [blame] | 2190 | if (parent && parent->nodetype == LYS_AUGMENT) { |
| 2191 | /* hack for augment, because when the original will be sometime reconnected back, we actually need |
| 2192 | * to reconnect it to both - the augment and its target (which is deduced from the deviations target |
| 2193 | * path), so we need to remember the augment as an addition */ |
| 2194 | dev_target->parent = parent; |
| 2195 | } |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2196 | dev->orig_node = dev_target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2197 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2198 | } else if (!strcmp(value, "add")) { |
| 2199 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_ADD; |
| 2200 | } else if (!strcmp(value, "replace")) { |
| 2201 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_RPL; |
| 2202 | } else if (!strcmp(value, "delete")) { |
| 2203 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_DEL; |
| 2204 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2205 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2206 | goto error; |
| 2207 | } |
| 2208 | d = &dev->deviate[dev->deviate_size]; |
Michal Vasko | 0f7d7ee | 2016-03-08 09:20:25 +0100 | [diff] [blame] | 2209 | dev->deviate_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2210 | |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 2211 | /* store a shallow copy of the original node */ |
| 2212 | if (!dev->orig_node) { |
| 2213 | memset(&tmp_unres, 0, sizeof tmp_unres); |
Radek Krejci | 6ff885d | 2017-01-03 14:06:22 +0100 | [diff] [blame] | 2214 | 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] | 2215 | /* just to be safe */ |
| 2216 | if (tmp_unres.count) { |
| 2217 | LOGINT; |
| 2218 | goto error; |
| 2219 | } |
| 2220 | } |
| 2221 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2222 | /* process deviation properties */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2223 | LY_TREE_FOR_SAFE(develem->child, next2, child) { |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2224 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2225 | /* garbage */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2226 | lyxml_free(ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2227 | continue; |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2228 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 2229 | /* extensions */ |
| 2230 | c_ext++; |
| 2231 | } else if (d->mod == LY_DEVIATE_NO) { |
| 2232 | /* no YIN substatement expected in this case */ |
| 2233 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2234 | goto error; |
| 2235 | } else if (!strcmp(child->name, "config")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2236 | if (d->flags & LYS_CONFIG_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2237 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2238 | goto error; |
| 2239 | } |
| 2240 | |
| 2241 | /* for we deviate from RFC 6020 and allow config property even it is/is not |
| 2242 | * specified in the target explicitly since config property inherits. So we expect |
| 2243 | * that config is specified in every node. But for delete, we check that the value |
| 2244 | * is the same as here in deviation |
| 2245 | */ |
| 2246 | GETVAL(value, child, "value"); |
| 2247 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2248 | d->flags |= LYS_CONFIG_R; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2249 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2250 | d->flags |= LYS_CONFIG_W; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2251 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2252 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2253 | goto error; |
| 2254 | } |
| 2255 | |
| 2256 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2257 | /* del config is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2258 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "config", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2259 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2260 | } else { /* add and replace are the same in this case */ |
| 2261 | /* remove current config value of the target ... */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2262 | dev_target->flags &= ~LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2263 | |
| 2264 | /* ... and replace it with the value specified in deviation */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2265 | dev_target->flags |= d->flags & LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2266 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2267 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2268 | 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] | 2269 | goto error; |
| 2270 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2271 | } else if (!strcmp(child->name, "default")) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2272 | 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] | 2273 | goto error; |
| 2274 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2275 | c_dflt++; |
| 2276 | |
| 2277 | /* check target node type */ |
| 2278 | if (module->version < 2 && dev_target->nodetype == LYS_LEAFLIST) { |
| 2279 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2280 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"default\" property."); |
| 2281 | goto error; |
| 2282 | } else if (c_dflt > 1 && dev_target->nodetype != LYS_LEAFLIST) { /* from YANG 1.1 */ |
| 2283 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2284 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow multiple \"default\" properties."); |
| 2285 | goto error; |
| 2286 | } else if (c_dflt == 1 && (!(dev_target->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_CHOICE)))) { |
| 2287 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2288 | 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] | 2289 | goto error; |
| 2290 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2291 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2292 | /* skip lyxml_free() at the end of the loop, this node will be processed later */ |
| 2293 | continue; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2294 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2295 | } else if (!strcmp(child->name, "mandatory")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2296 | if (d->flags & LYS_MAND_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2297 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2298 | goto error; |
| 2299 | } |
| 2300 | |
| 2301 | /* check target node type */ |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2302 | if (!(dev_target->nodetype & (LYS_LEAF | LYS_CHOICE | LYS_ANYDATA))) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2303 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2304 | 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] | 2305 | goto error; |
| 2306 | } |
| 2307 | |
| 2308 | GETVAL(value, child, "value"); |
| 2309 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2310 | d->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2311 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2312 | d->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2313 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2314 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2315 | goto error; |
| 2316 | } |
| 2317 | |
| 2318 | if (d->mod == LY_DEVIATE_ADD) { |
| 2319 | /* check that there is no current value */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2320 | if (dev_target->flags & LYS_MAND_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2321 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2322 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2323 | goto error; |
| 2324 | } |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2325 | |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 2326 | /* check collision with default-stmt */ |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2327 | if (d->flags & LYS_MAND_TRUE) { |
| 2328 | if (dev_target->nodetype == LYS_CHOICE) { |
| 2329 | if (((struct lys_node_choice *)(dev_target))->dflt) { |
| 2330 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 2331 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2332 | "Adding the \"mandatory\" statement is forbidden on choice with the \"default\" statement."); |
| 2333 | goto error; |
| 2334 | } |
| 2335 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 2336 | if (((struct lys_node_leaf *)(dev_target))->dflt) { |
| 2337 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 2338 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2339 | "Adding the \"mandatory\" statement is forbidden on leaf with the \"default\" statement."); |
| 2340 | goto error; |
| 2341 | } |
| 2342 | } |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 2343 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2344 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2345 | dev_target->flags |= d->flags & LYS_MAND_MASK; |
| 2346 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2347 | /* check that there was a value before */ |
| 2348 | if (!(dev_target->flags & LYS_MAND_MASK)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2349 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2350 | 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] | 2351 | goto error; |
| 2352 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2353 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2354 | dev_target->flags &= ~LYS_MAND_MASK; |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2355 | dev_target->flags |= d->flags & LYS_MAND_MASK; |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2356 | } else if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2357 | /* del mandatory is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2358 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "mandatory", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2359 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2360 | } |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 2361 | |
| 2362 | /* check for mandatory node in default case, first find the closest parent choice to the changed node */ |
| 2363 | for (parent = dev_target->parent; |
| 2364 | parent && !(parent->nodetype & (LYS_CHOICE | LYS_GROUPING | LYS_ACTION)); |
| 2365 | parent = parent->parent) { |
| 2366 | if (parent->nodetype == LYS_CONTAINER && ((struct lys_node_container *)parent)->presence) { |
| 2367 | /* stop also on presence containers */ |
| 2368 | break; |
| 2369 | } |
| 2370 | } |
| 2371 | /* and if it is a choice with the default case, check it for presence of a mandatory node in it */ |
| 2372 | if (parent && parent->nodetype == LYS_CHOICE && ((struct lys_node_choice *)parent)->dflt) { |
| 2373 | if (lyp_check_mandatory_choice(parent)) { |
| 2374 | goto error; |
| 2375 | } |
| 2376 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2377 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2378 | 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] | 2379 | goto error; |
| 2380 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2381 | } else if (!strcmp(child->name, "min-elements")) { |
| 2382 | if (f_min) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2383 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2384 | goto error; |
| 2385 | } |
| 2386 | f_min = 1; |
| 2387 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2388 | if (deviate_minmax(dev_target, child, d, 0)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2389 | goto error; |
| 2390 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2391 | 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] | 2392 | goto error; |
| 2393 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2394 | } else if (!strcmp(child->name, "max-elements")) { |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2395 | if (f_max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2396 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2397 | goto error; |
| 2398 | } |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2399 | f_max = 1; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2400 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2401 | if (deviate_minmax(dev_target, child, d, 1)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2402 | goto error; |
| 2403 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2404 | 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] | 2405 | goto error; |
| 2406 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2407 | } else if (!strcmp(child->name, "must")) { |
| 2408 | c_must++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2409 | /* 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] | 2410 | continue; |
| 2411 | } else if (!strcmp(child->name, "type")) { |
| 2412 | if (d->type) { |
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 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2417 | /* add, del type is forbidden */ |
| 2418 | if (d->mod == LY_DEVIATE_ADD) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2419 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "deviate add"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2420 | goto error; |
| 2421 | } else if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2422 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2423 | goto error; |
| 2424 | } |
| 2425 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2426 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2427 | if (dev_target->nodetype == LYS_LEAF) { |
| 2428 | t = &((struct lys_node_leaf *)dev_target)->type; |
Pavol Vican | 2e32282 | 2016-09-07 15:48:13 +0200 | [diff] [blame] | 2429 | if (((struct lys_node_leaf *)dev_target)->dflt) { |
| 2430 | ly_set_add(dflt_check, dev_target, 0); |
| 2431 | } |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2432 | } else if (dev_target->nodetype == LYS_LEAFLIST) { |
| 2433 | t = &((struct lys_node_leaflist *)dev_target)->type; |
Pavol Vican | 2e32282 | 2016-09-07 15:48:13 +0200 | [diff] [blame] | 2434 | if (((struct lys_node_leaflist *)dev_target)->dflt) { |
| 2435 | ly_set_add(dflt_check, dev_target, 0); |
| 2436 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2437 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2438 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2439 | 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] | 2440 | goto error; |
| 2441 | } |
| 2442 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2443 | /* replace */ |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 2444 | lys_type_free(ctx, t, NULL); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 2445 | /* HACK for unres */ |
| 2446 | t->der = (struct lys_tpdf *)child; |
Michal Vasko | 3767fb2 | 2016-07-21 12:10:57 +0200 | [diff] [blame] | 2447 | 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] | 2448 | goto error; |
| 2449 | } |
| 2450 | d->type = t; |
| 2451 | } else if (!strcmp(child->name, "unique")) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2452 | 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] | 2453 | goto error; |
| 2454 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2455 | c_uniq++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2456 | /* 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] | 2457 | continue; |
| 2458 | } else if (!strcmp(child->name, "units")) { |
| 2459 | if (d->units) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2460 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2461 | goto error; |
| 2462 | } |
| 2463 | |
| 2464 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2465 | if (dev_target->nodetype == LYS_LEAFLIST) { |
| 2466 | stritem = &((struct lys_node_leaflist *)dev_target)->units; |
| 2467 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 2468 | stritem = &((struct lys_node_leaf *)dev_target)->units; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2469 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2470 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2471 | 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] | 2472 | goto error; |
| 2473 | } |
| 2474 | |
| 2475 | /* get units value */ |
| 2476 | GETVAL(value, child, "name"); |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2477 | d->units = lydict_insert(ctx, value, 0); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2478 | |
| 2479 | /* apply to target */ |
| 2480 | if (d->mod == LY_DEVIATE_ADD) { |
| 2481 | /* check that there is no current value */ |
| 2482 | if (*stritem) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2483 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2484 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2485 | goto error; |
| 2486 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2487 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 2488 | *stritem = lydict_insert(ctx, value, 0); |
| 2489 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2490 | /* check that there was a value before */ |
| 2491 | if (!*stritem) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2492 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2493 | 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] | 2494 | goto error; |
| 2495 | } |
| 2496 | |
| 2497 | lydict_remove(ctx, *stritem); |
| 2498 | *stritem = lydict_insert(ctx, value, 0); |
| 2499 | } else if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2500 | /* check values */ |
Michal Vasko | b42b697 | 2016-06-06 14:21:30 +0200 | [diff] [blame] | 2501 | if (!ly_strequal(*stritem, d->units, 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2502 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
| 2503 | 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] | 2504 | goto error; |
| 2505 | } |
| 2506 | /* remove current units value of the target */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2507 | lydict_remove(ctx, *stritem); |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2508 | (*stritem) = NULL; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2509 | |
| 2510 | /* remove its extensions */ |
| 2511 | j = -1; |
| 2512 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_UNITS)) != -1) { |
| 2513 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2514 | --j; |
| 2515 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2516 | } |
| 2517 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 2518 | 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] | 2519 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2520 | } |
| 2521 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2522 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2523 | goto error; |
| 2524 | } |
| 2525 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 2526 | /* 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] | 2527 | } |
| 2528 | |
| 2529 | if (c_must) { |
| 2530 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2531 | switch (dev_target->nodetype) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2532 | case LYS_LEAF: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2533 | trg_must = &((struct lys_node_leaf *)dev_target)->must; |
| 2534 | trg_must_size = &((struct lys_node_leaf *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2535 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2536 | case LYS_CONTAINER: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2537 | trg_must = &((struct lys_node_container *)dev_target)->must; |
| 2538 | trg_must_size = &((struct lys_node_container *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2539 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2540 | case LYS_LEAFLIST: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2541 | trg_must = &((struct lys_node_leaflist *)dev_target)->must; |
| 2542 | trg_must_size = &((struct lys_node_leaflist *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2543 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2544 | case LYS_LIST: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2545 | trg_must = &((struct lys_node_list *)dev_target)->must; |
| 2546 | trg_must_size = &((struct lys_node_list *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2547 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2548 | case LYS_ANYXML: |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2549 | case LYS_ANYDATA: |
| 2550 | trg_must = &((struct lys_node_anydata *)dev_target)->must; |
| 2551 | trg_must_size = &((struct lys_node_anydata *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2552 | break; |
| 2553 | default: |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2554 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "must"); |
| 2555 | 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] | 2556 | goto error; |
| 2557 | } |
| 2558 | |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 2559 | dev_target->flags &= ~LYS_XPATH_DEP; |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 2560 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2561 | if (d->mod == LY_DEVIATE_RPL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2562 | /* replace must is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2563 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "must", "deviate replace"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2564 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2565 | } else if (d->mod == LY_DEVIATE_ADD) { |
| 2566 | /* reallocate the must array of the target */ |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2567 | d->must = ly_realloc(*trg_must, (c_must + *trg_must_size) * sizeof *d->must); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 2568 | LY_CHECK_ERR_GOTO(!d->must, LOGMEM, error); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2569 | *trg_must = d->must; |
Michal Vasko | 979ad5b | 2015-10-23 10:12:55 +0200 | [diff] [blame] | 2570 | d->must = &((*trg_must)[*trg_must_size]); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2571 | d->must_size = c_must; |
| 2572 | } else { /* LY_DEVIATE_DEL */ |
| 2573 | d->must = calloc(c_must, sizeof *d->must); |
| 2574 | } |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 2575 | LY_CHECK_ERR_GOTO(!d->must, LOGMEM, error); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2576 | } |
| 2577 | if (c_uniq) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2578 | /* replace unique is forbidden */ |
| 2579 | if (d->mod == LY_DEVIATE_RPL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2580 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "unique", "deviate replace"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2581 | goto error; |
| 2582 | } |
| 2583 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2584 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2585 | if (dev_target->nodetype != LYS_LIST) { |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2586 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "unique"); |
| 2587 | 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] | 2588 | goto error; |
| 2589 | } |
| 2590 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2591 | list = (struct lys_node_list *)dev_target; |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2592 | if (d->mod == LY_DEVIATE_ADD) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2593 | /* reallocate the unique array of the target */ |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2594 | d->unique = ly_realloc(list->unique, (c_uniq + list->unique_size) * sizeof *d->unique); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 2595 | LY_CHECK_ERR_GOTO(!d->unique, LOGMEM, error); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2596 | list->unique = d->unique; |
| 2597 | d->unique = &list->unique[list->unique_size]; |
| 2598 | d->unique_size = c_uniq; |
| 2599 | } else { /* LY_DEVIATE_DEL */ |
| 2600 | d->unique = calloc(c_uniq, sizeof *d->unique); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 2601 | LY_CHECK_ERR_GOTO(!d->unique, LOGMEM, error); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2602 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2603 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2604 | if (c_dflt) { |
| 2605 | if (d->mod == LY_DEVIATE_ADD) { |
| 2606 | /* check that there is no current value */ |
| 2607 | if ((dev_target->nodetype == LYS_LEAF && ((struct lys_node_leaf *)dev_target)->dflt) || |
| 2608 | (dev_target->nodetype == LYS_CHOICE && ((struct lys_node_choice *)dev_target)->dflt)) { |
| 2609 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2610 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
| 2611 | goto error; |
| 2612 | } |
| 2613 | |
| 2614 | /* check collision with mandatory/min-elements */ |
| 2615 | if ((dev_target->flags & LYS_MAND_TRUE) || |
| 2616 | (dev_target->nodetype == LYS_LEAFLIST && ((struct lys_node_leaflist *)dev_target)->min)) { |
| 2617 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 2618 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2619 | "Adding the \"default\" statement is forbidden on %s statement.", |
| 2620 | (dev_target->flags & LYS_MAND_TRUE) ? "nodes with the \"mandatory\"" : "leaflists with non-zero \"min-elements\""); |
| 2621 | goto error; |
| 2622 | } |
| 2623 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2624 | /* check that there was a value before */ |
| 2625 | if (((dev_target->nodetype & (LYS_LEAF | LYS_LEAFLIST)) && !((struct lys_node_leaf *)dev_target)->dflt) || |
| 2626 | (dev_target->nodetype == LYS_CHOICE && !((struct lys_node_choice *)dev_target)->dflt)) { |
| 2627 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2628 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Replacing a property that does not exist."); |
| 2629 | goto error; |
| 2630 | } |
| 2631 | } |
| 2632 | |
| 2633 | if (dev_target->nodetype == LYS_LEAFLIST) { |
| 2634 | /* reallocate default list in the target */ |
| 2635 | llist = (struct lys_node_leaflist *)dev_target; |
| 2636 | if (d->mod == LY_DEVIATE_ADD) { |
| 2637 | /* reallocate (enlarge) the unique array of the target */ |
| 2638 | llist->dflt = ly_realloc(llist->dflt, (c_dflt + llist->dflt_size) * sizeof *d->dflt); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 2639 | LY_CHECK_ERR_GOTO(!llist->dflt, LOGMEM, error); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2640 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2641 | /* reallocate (replace) the unique array of the target */ |
| 2642 | for (i = 0; i < llist->dflt_size; i++) { |
| 2643 | lydict_remove(llist->module->ctx, llist->dflt[i]); |
| 2644 | } |
| 2645 | llist->dflt = ly_realloc(llist->dflt, c_dflt * sizeof *d->dflt); |
| 2646 | llist->dflt_size = 0; |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 2647 | LY_CHECK_ERR_GOTO(!llist->dflt, LOGMEM, error); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2648 | } |
| 2649 | } |
| 2650 | d->dflt = calloc(c_dflt, sizeof *d->dflt); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 2651 | LY_CHECK_ERR_GOTO(!d->dflt, LOGMEM, error); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2652 | } |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2653 | if (c_ext) { |
| 2654 | /* some extensions may be already present from the substatements */ |
| 2655 | reallocated = realloc(d->ext, (c_ext + d->ext_size) * sizeof *d->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 2656 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2657 | d->ext = reallocated; |
| 2658 | |
| 2659 | /* init memory */ |
| 2660 | memset(&d->ext[d->ext_size], 0, c_ext * sizeof *d->ext); |
| 2661 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2662 | |
| 2663 | /* process deviation properties with 0..n cardinality */ |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2664 | LY_TREE_FOR_SAFE(develem->child, next2, child) { |
| 2665 | if (strcmp(child->ns->value, LY_NSYIN)) { |
| 2666 | /* extension */ |
| 2667 | if (lyp_yin_fill_ext(d, LYEXT_PAR_DEVIATE, 0, 0, module, child, &d->ext, d->ext_size, unres)) { |
| 2668 | goto error; |
| 2669 | } |
| 2670 | d->ext_size++; |
| 2671 | } else if (!strcmp(child->name, "must")) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2672 | if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 2673 | if (fill_yin_must(module, child, &d->must[d->must_size], unres)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2674 | goto error; |
| 2675 | } |
| 2676 | |
| 2677 | /* find must to delete, we are ok with just matching conditions */ |
| 2678 | for (i = 0; i < *trg_must_size; i++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 2679 | 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] | 2680 | /* we have a match, free the must structure ... */ |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 2681 | lys_restr_free(ctx, &((*trg_must)[i]), NULL); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2682 | /* ... and maintain the array */ |
| 2683 | (*trg_must_size)--; |
| 2684 | if (i != *trg_must_size) { |
| 2685 | (*trg_must)[i].expr = (*trg_must)[*trg_must_size].expr; |
| 2686 | (*trg_must)[i].dsc = (*trg_must)[*trg_must_size].dsc; |
| 2687 | (*trg_must)[i].ref = (*trg_must)[*trg_must_size].ref; |
| 2688 | (*trg_must)[i].eapptag = (*trg_must)[*trg_must_size].eapptag; |
| 2689 | (*trg_must)[i].emsg = (*trg_must)[*trg_must_size].emsg; |
| 2690 | } |
| 2691 | if (!(*trg_must_size)) { |
| 2692 | free(*trg_must); |
| 2693 | *trg_must = NULL; |
| 2694 | } else { |
| 2695 | (*trg_must)[*trg_must_size].expr = NULL; |
| 2696 | (*trg_must)[*trg_must_size].dsc = NULL; |
| 2697 | (*trg_must)[*trg_must_size].ref = NULL; |
| 2698 | (*trg_must)[*trg_must_size].eapptag = NULL; |
| 2699 | (*trg_must)[*trg_must_size].emsg = NULL; |
| 2700 | } |
| 2701 | |
| 2702 | i = -1; /* set match flag */ |
| 2703 | break; |
| 2704 | } |
| 2705 | } |
| 2706 | d->must_size++; |
| 2707 | if (i != -1) { |
| 2708 | /* no match found */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2709 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, |
Radek Krejci | adb5761 | 2016-02-16 13:34:34 +0100 | [diff] [blame] | 2710 | d->must[d->must_size - 1].expr, child->name); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2711 | 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] | 2712 | goto error; |
| 2713 | } |
| 2714 | } else { /* replace or add */ |
Michal Vasko | f92a728 | 2016-02-11 12:35:57 +0100 | [diff] [blame] | 2715 | memset(&((*trg_must)[*trg_must_size]), 0, sizeof **trg_must); |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 2716 | if (fill_yin_must(module, child, &((*trg_must)[*trg_must_size]), unres)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2717 | goto error; |
| 2718 | } |
| 2719 | (*trg_must_size)++; |
| 2720 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 2721 | |
| 2722 | /* check XPath dependencies again */ |
Michal Vasko | f96dfb6 | 2017-08-17 12:23:49 +0200 | [diff] [blame] | 2723 | if (*trg_must_size && (unres_schema_add_node(module, unres, dev_target, UNRES_XPATH, NULL) == -1)) { |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 2724 | goto error; |
| 2725 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2726 | } else if (!strcmp(child->name, "unique")) { |
| 2727 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | a0a10ab | 2016-03-07 14:41:23 +0100 | [diff] [blame] | 2728 | memset(&d->unique[d->unique_size], 0, sizeof *d->unique); |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2729 | 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] | 2730 | d->unique_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2731 | goto error; |
| 2732 | } |
| 2733 | |
| 2734 | /* find unique structures to delete */ |
| 2735 | for (i = 0; i < list->unique_size; i++) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2736 | 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] | 2737 | continue; |
| 2738 | } |
| 2739 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2740 | for (j = 0; j < d->unique[d->unique_size].expr_size; j++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 2741 | 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] | 2742 | break; |
| 2743 | } |
| 2744 | } |
| 2745 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2746 | if (j == d->unique[d->unique_size].expr_size) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2747 | /* we have a match, free the unique structure ... */ |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2748 | for (j = 0; j < list->unique[i].expr_size; j++) { |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2749 | lydict_remove(ctx, list->unique[i].expr[j]); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2750 | } |
| 2751 | free(list->unique[i].expr); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2752 | /* ... and maintain the array */ |
| 2753 | list->unique_size--; |
| 2754 | if (i != list->unique_size) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2755 | list->unique[i].expr_size = list->unique[list->unique_size].expr_size; |
| 2756 | list->unique[i].expr = list->unique[list->unique_size].expr; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2757 | } |
| 2758 | |
| 2759 | if (!list->unique_size) { |
| 2760 | free(list->unique); |
| 2761 | list->unique = NULL; |
| 2762 | } else { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2763 | list->unique[list->unique_size].expr_size = 0; |
| 2764 | list->unique[list->unique_size].expr = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2765 | } |
| 2766 | |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2767 | k = i; /* remember index for removing extensions */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2768 | i = -1; /* set match flag */ |
| 2769 | break; |
| 2770 | } |
| 2771 | } |
| 2772 | |
| 2773 | d->unique_size++; |
| 2774 | if (i != -1) { |
| 2775 | /* no match found */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2776 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, lyxml_get_attr(child, "tag", NULL), child->name); |
| 2777 | 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] | 2778 | goto error; |
| 2779 | } |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2780 | |
| 2781 | /* remove extensions of this unique instance from the target node */ |
| 2782 | j = -1; |
| 2783 | 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] | 2784 | if (dev_target->ext[j]->insubstmt_index == k) { |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2785 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2786 | --j; |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2787 | } else if (dev_target->ext[j]->insubstmt_index > k) { |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2788 | /* 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] | 2789 | dev_target->ext[j]->insubstmt_index--; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2790 | } |
| 2791 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2792 | } else { /* replace or add */ |
Michal Vasko | a0a10ab | 2016-03-07 14:41:23 +0100 | [diff] [blame] | 2793 | memset(&list->unique[list->unique_size], 0, sizeof *list->unique); |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2794 | 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] | 2795 | list->unique_size++; |
| 2796 | if (i) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2797 | goto error; |
| 2798 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2799 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2800 | } else if (!strcmp(child->name, "default")) { |
| 2801 | GETVAL(value, child, "value"); |
| 2802 | u = strlen(value); |
| 2803 | d->dflt[d->dflt_size++] = lydict_insert(module->ctx, value, u); |
| 2804 | |
| 2805 | if (dev_target->nodetype == LYS_CHOICE) { |
| 2806 | choice = (struct lys_node_choice *)dev_target; |
| 2807 | rc = resolve_choice_default_schema_nodeid(value, choice->child, (const struct lys_node **)&node); |
| 2808 | if (rc || !node) { |
| 2809 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2810 | goto error; |
| 2811 | } |
| 2812 | if (d->mod == LY_DEVIATE_DEL) { |
| 2813 | if (!choice->dflt || (choice->dflt != node)) { |
| 2814 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2815 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
| 2816 | goto error; |
| 2817 | } |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2818 | choice->dflt = NULL; |
| 2819 | /* remove extensions of this default instance from the target node */ |
| 2820 | j = -1; |
| 2821 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_DEFAULT)) != -1) { |
| 2822 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2823 | --j; |
| 2824 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2825 | } else { /* add or replace */ |
| 2826 | choice->dflt = node; |
| 2827 | if (!choice->dflt) { |
| 2828 | /* default branch not found */ |
| 2829 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2830 | goto error; |
| 2831 | } |
| 2832 | } |
| 2833 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 2834 | leaf = (struct lys_node_leaf *)dev_target; |
| 2835 | if (d->mod == LY_DEVIATE_DEL) { |
| 2836 | if (!leaf->dflt || !ly_strequal(leaf->dflt, value, 1)) { |
| 2837 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2838 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
| 2839 | goto error; |
| 2840 | } |
| 2841 | /* remove value */ |
| 2842 | lydict_remove(ctx, leaf->dflt); |
| 2843 | leaf->dflt = NULL; |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 2844 | leaf->flags &= ~LYS_DFLTJSON; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2845 | |
| 2846 | /* remove extensions of this default instance from the target node */ |
| 2847 | j = -1; |
| 2848 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_DEFAULT)) != -1) { |
| 2849 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2850 | --j; |
| 2851 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2852 | } else { /* add (already checked) and replace */ |
| 2853 | /* remove value */ |
| 2854 | lydict_remove(ctx, leaf->dflt); |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 2855 | leaf->flags &= ~LYS_DFLTJSON; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2856 | |
| 2857 | /* set new value */ |
| 2858 | leaf->dflt = lydict_insert(ctx, value, u); |
| 2859 | |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 2860 | /* 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] | 2861 | ly_set_add(dflt_check, dev_target, 0); |
| 2862 | } |
| 2863 | } else { /* LYS_LEAFLIST */ |
| 2864 | llist = (struct lys_node_leaflist *)dev_target; |
| 2865 | if (d->mod == LY_DEVIATE_DEL) { |
| 2866 | /* find and remove the value in target list */ |
| 2867 | for (i = 0; i < llist->dflt_size; i++) { |
| 2868 | if (llist->dflt[i] && ly_strequal(llist->dflt[i], value, 1)) { |
| 2869 | /* match, remove the value */ |
| 2870 | lydict_remove(llist->module->ctx, llist->dflt[i]); |
| 2871 | llist->dflt[i] = NULL; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2872 | |
| 2873 | /* remove extensions of this default instance from the target node */ |
| 2874 | j = -1; |
| 2875 | 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] | 2876 | if (dev_target->ext[j]->insubstmt_index == i) { |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2877 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 2878 | --j; |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2879 | } else if (dev_target->ext[j]->insubstmt_index > i) { |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2880 | /* 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] | 2881 | dev_target->ext[j]->insubstmt_index--; |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 2882 | } |
| 2883 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2884 | break; |
| 2885 | } |
| 2886 | } |
| 2887 | if (i == llist->dflt_size) { |
| 2888 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2889 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "The default value to delete not found in the target node."); |
| 2890 | goto error; |
| 2891 | } |
| 2892 | } else { |
| 2893 | /* add or replace, anyway we place items into the deviate's list |
| 2894 | which propagates to the target */ |
| 2895 | /* we just want to check that the value isn't already in the list */ |
| 2896 | for (i = 0; i < llist->dflt_size; i++) { |
| 2897 | if (ly_strequal(llist->dflt[i], value, 1)) { |
| 2898 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2899 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Duplicated default value \"%s\".", value); |
| 2900 | goto error; |
| 2901 | } |
| 2902 | } |
| 2903 | /* store it in target node */ |
| 2904 | llist->dflt[llist->dflt_size++] = lydict_insert(module->ctx, value, u); |
| 2905 | |
| 2906 | /* remember to check it later (it may not fit now, but the type can be deviated too) */ |
| 2907 | ly_set_add(dflt_check, dev_target, 0); |
Radek Krejci | 3c4b0ea | 2017-01-24 16:00:47 +0100 | [diff] [blame] | 2908 | llist->flags &= ~LYS_DFLTJSON; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2909 | } |
| 2910 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2911 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2912 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2913 | |
| 2914 | if (c_dflt && dev_target->nodetype == LYS_LEAFLIST && d->mod == LY_DEVIATE_DEL) { |
| 2915 | /* consolidate the final list in the target after removing items from it */ |
| 2916 | llist = (struct lys_node_leaflist *)dev_target; |
| 2917 | for (i = j = 0; j < llist->dflt_size; j++) { |
| 2918 | llist->dflt[i] = llist->dflt[j]; |
| 2919 | if (llist->dflt[i]) { |
| 2920 | i++; |
| 2921 | } |
| 2922 | } |
| 2923 | llist->dflt_size = i + 1; |
| 2924 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2925 | } |
| 2926 | |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2927 | /* now check whether default value, if any, matches the type */ |
Pavol Vican | 85991ec | 2016-08-16 14:58:12 +0200 | [diff] [blame] | 2928 | for (u = 0; u < dflt_check->number; ++u) { |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2929 | value = NULL; |
| 2930 | rc = EXIT_SUCCESS; |
| 2931 | if (dflt_check->set.s[u]->nodetype == LYS_LEAF) { |
| 2932 | leaf = (struct lys_node_leaf *)dflt_check->set.s[u]; |
Radek Krejci | 5167320 | 2016-11-01 17:00:32 +0100 | [diff] [blame] | 2933 | value = leaf->dflt; |
| 2934 | 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] | 2935 | } else { /* LYS_LEAFLIST */ |
| 2936 | llist = (struct lys_node_leaflist *)dflt_check->set.s[u]; |
| 2937 | for (j = 0; j < llist->dflt_size; j++) { |
Radek Krejci | 5167320 | 2016-11-01 17:00:32 +0100 | [diff] [blame] | 2938 | rc = unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DFLT, |
| 2939 | (struct lys_node *)(&llist->dflt[j])); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2940 | if (rc == -1) { |
Radek Krejci | 5167320 | 2016-11-01 17:00:32 +0100 | [diff] [blame] | 2941 | value = llist->dflt[j]; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2942 | break; |
| 2943 | } |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2944 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2945 | |
| 2946 | } |
| 2947 | if (rc == -1) { |
| 2948 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2949 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2950 | "The default value \"%s\" of the deviated node \"%s\"no longer matches its type.", |
| 2951 | dev->target_name); |
| 2952 | goto error; |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2953 | } |
| 2954 | } |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2955 | |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 2956 | /* mark all the affected modules as deviated and implemented */ |
| 2957 | for(parent = dev_target; parent; parent = lys_parent(parent)) { |
| 2958 | mod = lys_node_module(parent); |
| 2959 | if (module != mod) { |
Radek Krejci | 29eac3d | 2017-06-01 16:50:02 +0200 | [diff] [blame] | 2960 | mod->deviated = 1; /* main module */ |
| 2961 | parent->module->deviated = 1; /* possible submodule */ |
Radek Krejci | 2bb5be7 | 2017-02-27 13:07:25 +0100 | [diff] [blame] | 2962 | if (lys_set_implemented(mod)) { |
| 2963 | LOGERR(ly_errno, "Setting the deviated module \"%s\" implemented failed.", mod->name); |
| 2964 | goto error; |
| 2965 | } |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 2966 | } |
| 2967 | } |
| 2968 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2969 | ly_set_free(dflt_check); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2970 | return EXIT_SUCCESS; |
| 2971 | |
| 2972 | error: |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2973 | ly_set_free(dflt_check); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2974 | return EXIT_FAILURE; |
| 2975 | } |
| 2976 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2977 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2978 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2979 | 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] | 2980 | int options, struct unres_schema *unres) |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2981 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2982 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2983 | struct lyxml_elem *sub, *next; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2984 | struct lys_node *node; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 2985 | int ret, c_ftrs = 0, c_ext = 0; |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 2986 | void *reallocated; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2987 | |
Michal Vasko | 591e0b2 | 2015-08-13 13:53:43 +0200 | [diff] [blame] | 2988 | aug->nodetype = LYS_AUGMENT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2989 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2990 | aug->target_name = transform_schema2json(module, value); |
Michal Vasko | 488c19e | 2015-10-20 15:21:00 +0200 | [diff] [blame] | 2991 | if (!aug->target_name) { |
| 2992 | goto error; |
| 2993 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2994 | aug->parent = parent; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2995 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 2996 | 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] | 2997 | goto error; |
| 2998 | } |
| 2999 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3000 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 3001 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3002 | /* extension */ |
| 3003 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3004 | continue; |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 3005 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3006 | c_ftrs++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3007 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3008 | } else if (!strcmp(sub->name, "when")) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3009 | if (aug->when) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3010 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3011 | goto error; |
| 3012 | } |
| 3013 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3014 | aug->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3015 | if (!aug->when) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3016 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3017 | goto error; |
| 3018 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3019 | lyxml_free(module->ctx, sub); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3020 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3021 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3022 | /* check allowed data sub-statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3023 | } else if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3024 | node = read_yin_container(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3025 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3026 | node = read_yin_leaflist(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3027 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3028 | node = read_yin_leaf(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3029 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3030 | node = read_yin_list(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3031 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3032 | node = read_yin_uses(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3033 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3034 | node = read_yin_choice(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3035 | } else if (!strcmp(sub->name, "case")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3036 | node = read_yin_case(module, (struct lys_node *)aug, sub, options, unres); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3037 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3038 | 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] | 3039 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3040 | 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] | 3041 | } else if (!strcmp(sub->name, "action")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3042 | 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] | 3043 | } else if (!strcmp(sub->name, "notification")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3044 | node = read_yin_notif(module, (struct lys_node *)aug, sub, options, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3045 | } else { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3046 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3047 | goto error; |
| 3048 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3049 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3050 | if (!node) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3051 | goto error; |
| 3052 | } |
| 3053 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3054 | node = NULL; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3055 | lyxml_free(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3056 | } |
| 3057 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3058 | if (c_ftrs) { |
| 3059 | aug->iffeature = calloc(c_ftrs, sizeof *aug->iffeature); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 3060 | LY_CHECK_ERR_GOTO(!aug->iffeature, LOGMEM, error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3061 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3062 | if (c_ext) { |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 3063 | /* some extensions may be already present from the substatements */ |
| 3064 | reallocated = realloc(aug->ext, (c_ext + aug->ext_size) * sizeof *aug->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 3065 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | 30701b4 | 2017-01-23 16:41:38 +0100 | [diff] [blame] | 3066 | aug->ext = reallocated; |
| 3067 | |
| 3068 | /* init memory */ |
| 3069 | memset(&aug->ext[aug->ext_size], 0, c_ext * sizeof *aug->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3070 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3071 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3072 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 3073 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3074 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3075 | 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] | 3076 | aug->ext_size++; |
| 3077 | if (ret) { |
| 3078 | goto error; |
| 3079 | } |
| 3080 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3081 | 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] | 3082 | aug->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3083 | if (ret) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3084 | goto error; |
| 3085 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3086 | lyxml_free(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3087 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3088 | } |
| 3089 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3090 | /* aug->child points to the parsed nodes, they must now be |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 3091 | * connected to the tree and adjusted (if possible right now). |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 3092 | * 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] | 3093 | * when the uses does and cannot be resolved now for sure |
| 3094 | * (the grouping was not yet copied into uses). |
| 3095 | */ |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 3096 | if (!parent) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3097 | if (unres_schema_add_node(module, unres, aug, UNRES_AUGMENT, NULL) == -1) { |
Michal Vasko | 4adc10f | 2015-08-11 15:26:17 +0200 | [diff] [blame] | 3098 | goto error; |
| 3099 | } |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 3100 | } |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3101 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 3102 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3103 | if (aug->when) { |
| 3104 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 3105 | if (lyxp_node_check_syntax((struct lys_node *)aug)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3106 | goto error; |
| 3107 | } |
| 3108 | } else { |
| 3109 | if (unres_schema_add_node(module, unres, (struct lys_node *)aug, UNRES_XPATH, NULL) == -1) { |
| 3110 | goto error; |
| 3111 | } |
| 3112 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 3113 | } |
| 3114 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3115 | return EXIT_SUCCESS; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3116 | |
| 3117 | error: |
| 3118 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3119 | return EXIT_FAILURE; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 3120 | } |
| 3121 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3122 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3123 | static int |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3124 | 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] | 3125 | { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3126 | struct lys_module *module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3127 | struct lyxml_elem *sub, *next; |
| 3128 | const char *value; |
| 3129 | char *endptr; |
| 3130 | int f_mand = 0, f_min = 0, f_max = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3131 | 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] | 3132 | int r; |
| 3133 | unsigned long int val; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3134 | void *reallocated; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3135 | |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3136 | assert(uses); |
| 3137 | module = uses->module; /* shorthand */ |
| 3138 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3139 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3140 | rfn->target_name = transform_schema2json(module, value); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 3141 | if (!rfn->target_name) { |
| 3142 | goto error; |
| 3143 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3144 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3145 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3146 | if (!sub->ns) { |
| 3147 | /* garbage */ |
| 3148 | } else if (strcmp(sub->ns->value, LY_NSYIN)) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3149 | /* extension */ |
| 3150 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3151 | continue; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3152 | |
Radek Krejci | 411b1bf | 2017-01-23 16:40:05 +0100 | [diff] [blame] | 3153 | } else if (!strcmp(sub->name, "description")) { |
| 3154 | if (rfn->dsc) { |
| 3155 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3156 | goto error; |
| 3157 | } |
| 3158 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3159 | 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] | 3160 | goto error; |
| 3161 | } |
| 3162 | |
| 3163 | rfn->dsc = read_yin_subnode(module->ctx, sub, "text"); |
| 3164 | if (!rfn->dsc) { |
| 3165 | goto error; |
| 3166 | } |
| 3167 | } else if (!strcmp(sub->name, "reference")) { |
| 3168 | if (rfn->ref) { |
| 3169 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3170 | goto error; |
| 3171 | } |
| 3172 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3173 | 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] | 3174 | goto error; |
| 3175 | } |
| 3176 | |
| 3177 | rfn->ref = read_yin_subnode(module->ctx, sub, "text"); |
| 3178 | if (!rfn->ref) { |
| 3179 | goto error; |
| 3180 | } |
| 3181 | } else if (!strcmp(sub->name, "config")) { |
| 3182 | if (rfn->flags & LYS_CONFIG_MASK) { |
| 3183 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3184 | goto error; |
| 3185 | } |
| 3186 | GETVAL(value, sub, "value"); |
| 3187 | if (!strcmp(value, "false")) { |
| 3188 | rfn->flags |= LYS_CONFIG_R; |
| 3189 | } else if (!strcmp(value, "true")) { |
| 3190 | rfn->flags |= LYS_CONFIG_W; |
| 3191 | } else { |
| 3192 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
| 3193 | goto error; |
| 3194 | } |
| 3195 | rfn->flags |= LYS_CONFIG_SET; |
| 3196 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3197 | 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] | 3198 | goto error; |
| 3199 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3200 | } else if (!strcmp(sub->name, "default")) { |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3201 | /* leaf, leaf-list or choice */ |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3202 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3203 | /* check possibility of statements combination */ |
| 3204 | if (rfn->target_type) { |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3205 | if (c_dflt) { |
| 3206 | /* multiple defaults are allowed only in leaf-list */ |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3207 | if (module->version < 2) { |
| 3208 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3209 | goto error; |
| 3210 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3211 | rfn->target_type &= LYS_LEAFLIST; |
| 3212 | } else { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3213 | if (module->version < 2) { |
| 3214 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE); |
| 3215 | } else { |
| 3216 | /* YANG 1.1 */ |
| 3217 | rfn->target_type &= (LYS_LEAFLIST | LYS_LEAF | LYS_CHOICE); |
| 3218 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3219 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3220 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3221 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3222 | 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] | 3223 | goto error; |
| 3224 | } |
| 3225 | } else { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3226 | if (module->version < 2) { |
| 3227 | rfn->target_type = LYS_LEAF | LYS_CHOICE; |
| 3228 | } else { |
| 3229 | /* YANG 1.1 */ |
| 3230 | rfn->target_type = LYS_LEAFLIST | LYS_LEAF | LYS_CHOICE; |
| 3231 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3232 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3233 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3234 | 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] | 3235 | goto error; |
| 3236 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3237 | c_dflt++; |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3238 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3239 | } else if (!strcmp(sub->name, "mandatory")) { |
| 3240 | /* leaf, choice or anyxml */ |
| 3241 | if (f_mand) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3242 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3243 | goto error; |
| 3244 | } |
| 3245 | /* just checking the flags in leaf is not sufficient, we would allow |
| 3246 | * multiple mandatory statements with the "false" value |
| 3247 | */ |
| 3248 | f_mand = 1; |
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 | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3252 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE | LYS_ANYDATA); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3253 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3254 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3255 | 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] | 3256 | goto error; |
| 3257 | } |
| 3258 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3259 | rfn->target_type = LYS_LEAF | LYS_CHOICE | LYS_ANYDATA; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3260 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3261 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3262 | GETVAL(value, sub, "value"); |
| 3263 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3264 | rfn->flags |= LYS_MAND_TRUE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3265 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3266 | rfn->flags |= LYS_MAND_FALSE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3267 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3268 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3269 | goto error; |
| 3270 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3271 | 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] | 3272 | goto error; |
| 3273 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3274 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3275 | /* list or leaf-list */ |
| 3276 | if (f_min) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3277 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3278 | goto error; |
| 3279 | } |
| 3280 | f_min = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3281 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3282 | /* check possibility of statements combination */ |
| 3283 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3284 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3285 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3286 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3287 | 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] | 3288 | goto error; |
| 3289 | } |
| 3290 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3291 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3292 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3293 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3294 | GETVAL(value, sub, "value"); |
| 3295 | while (isspace(value[0])) { |
| 3296 | value++; |
| 3297 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3298 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3299 | /* convert it to uint32_t */ |
| 3300 | errno = 0; |
| 3301 | endptr = NULL; |
| 3302 | val = strtoul(value, &endptr, 10); |
| 3303 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3304 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3305 | goto error; |
| 3306 | } |
| 3307 | rfn->mod.list.min = (uint32_t) val; |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 3308 | rfn->flags |= LYS_RFN_MINSET; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3309 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3310 | 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] | 3311 | goto error; |
| 3312 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3313 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3314 | /* list or leaf-list */ |
| 3315 | if (f_max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3316 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3317 | goto error; |
| 3318 | } |
| 3319 | f_max = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3320 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3321 | /* check possibility of statements combination */ |
| 3322 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3323 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3324 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3325 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3326 | 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] | 3327 | goto error; |
| 3328 | } |
| 3329 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3330 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3331 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3332 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3333 | GETVAL(value, sub, "value"); |
| 3334 | while (isspace(value[0])) { |
| 3335 | value++; |
| 3336 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3337 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 3338 | if (!strcmp(value, "unbounded")) { |
| 3339 | rfn->mod.list.max = 0; |
| 3340 | } else { |
| 3341 | /* convert it to uint32_t */ |
| 3342 | errno = 0; |
| 3343 | endptr = NULL; |
| 3344 | val = strtoul(value, &endptr, 10); |
| 3345 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3346 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 3347 | goto error; |
| 3348 | } |
| 3349 | rfn->mod.list.max = (uint32_t) val; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3350 | } |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 3351 | rfn->flags |= LYS_RFN_MAXSET; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3352 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3353 | if (lyp_yin_parse_subnode_ext(module, rfn, LYEXT_PAR_REFINE, sub, LYEXT_SUBSTMT_MAX, 0, unres)) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3354 | goto error; |
| 3355 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3356 | } else if (!strcmp(sub->name, "presence")) { |
| 3357 | /* container */ |
| 3358 | if (rfn->mod.presence) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3359 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3360 | goto error; |
| 3361 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3362 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3363 | /* check possibility of statements combination */ |
| 3364 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3365 | rfn->target_type &= LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3366 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3367 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3368 | 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] | 3369 | goto error; |
| 3370 | } |
| 3371 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3372 | rfn->target_type = LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3373 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3374 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3375 | GETVAL(value, sub, "value"); |
| 3376 | rfn->mod.presence = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3377 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3378 | 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] | 3379 | goto error; |
| 3380 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3381 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3382 | /* leafm leaf-list, list, container or anyxml */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3383 | /* check possibility of statements combination */ |
| 3384 | if (rfn->target_type) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3385 | 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] | 3386 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3387 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3388 | 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] | 3389 | goto error; |
| 3390 | } |
| 3391 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3392 | 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] | 3393 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3394 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3395 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3396 | continue; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3397 | |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3398 | } else if ((module->version >= 2) && !strcmp(sub->name, "if-feature")) { |
| 3399 | /* leaf, leaf-list, list, container or anyxml */ |
| 3400 | /* check possibility of statements combination */ |
| 3401 | if (rfn->target_type) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3402 | 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] | 3403 | if (!rfn->target_type) { |
| 3404 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 3405 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid refine target nodetype for the substatements."); |
| 3406 | goto error; |
| 3407 | } |
| 3408 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3409 | 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] | 3410 | } |
| 3411 | |
| 3412 | c_ftrs++; |
| 3413 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3414 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3415 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3416 | goto error; |
| 3417 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3418 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3419 | lyxml_free(module->ctx, sub); |
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 | /* process nodes with cardinality of 0..n */ |
| 3423 | if (c_must) { |
| 3424 | rfn->must = calloc(c_must, sizeof *rfn->must); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 3425 | LY_CHECK_ERR_GOTO(!rfn->must, LOGMEM, error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3426 | } |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3427 | if (c_ftrs) { |
Radek Krejci | 947e034 | 2016-08-15 09:42:56 +0200 | [diff] [blame] | 3428 | rfn->iffeature = calloc(c_ftrs, sizeof *rfn->iffeature); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 3429 | LY_CHECK_ERR_GOTO(!rfn->iffeature, LOGMEM, error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3430 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3431 | if (c_dflt) { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 3432 | rfn->dflt = calloc(c_dflt, sizeof *rfn->dflt); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 3433 | LY_CHECK_ERR_GOTO(!rfn->dflt, LOGMEM, error); |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3434 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3435 | if (c_ext) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3436 | /* some extensions may be already present from the substatements */ |
| 3437 | reallocated = realloc(rfn->ext, (c_ext + rfn->ext_size) * sizeof *rfn->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 3438 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 3439 | rfn->ext = reallocated; |
| 3440 | |
| 3441 | /* init memory */ |
| 3442 | memset(&rfn->ext[rfn->ext_size], 0, c_ext * sizeof *rfn->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3443 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3444 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3445 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 3446 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3447 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3448 | 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] | 3449 | rfn->ext_size++; |
| 3450 | if (r) { |
| 3451 | goto error; |
| 3452 | } |
| 3453 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 3454 | 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] | 3455 | rfn->iffeature_size++; |
| 3456 | if (r) { |
| 3457 | goto error; |
| 3458 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3459 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 3460 | r = fill_yin_must(module, sub, &rfn->must[rfn->must_size], unres); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3461 | rfn->must_size++; |
| 3462 | if (r) { |
| 3463 | goto error; |
| 3464 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3465 | } else { /* default */ |
| 3466 | GETVAL(value, sub, "value"); |
| 3467 | |
| 3468 | /* check for duplicity */ |
| 3469 | for (r = 0; r < rfn->dflt_size; r++) { |
| 3470 | if (ly_strequal(rfn->dflt[r], value, 1)) { |
| 3471 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 3472 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Duplicated default value \"%s\".", value); |
| 3473 | goto error; |
| 3474 | } |
| 3475 | } |
| 3476 | rfn->dflt[rfn->dflt_size++] = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 3477 | } |
| 3478 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3479 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3480 | return EXIT_SUCCESS; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3481 | |
| 3482 | error: |
| 3483 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3484 | return EXIT_FAILURE; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 3485 | } |
| 3486 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3487 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3488 | static int |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3489 | 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] | 3490 | { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3491 | struct lyxml_elem *child, *next, exts; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3492 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3493 | int r, c_ext = 0; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3494 | void *reallocated; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3495 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3496 | /* init */ |
| 3497 | memset(&exts, 0, sizeof exts); |
| 3498 | |
| 3499 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 3500 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3501 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3502 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3503 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 3504 | /* extension */ |
| 3505 | c_ext++; |
| 3506 | lyxml_unlink_elem(module->ctx, child, 2); |
| 3507 | lyxml_add_child(module->ctx, &exts, child); |
| 3508 | } else if (!strcmp(child->name, "prefix")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3509 | GETVAL(value, child, "value"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3510 | if (lyp_check_identifier(value, LY_IDENT_PREFIX, module, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3511 | goto error; |
| 3512 | } |
| 3513 | imp->prefix = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3514 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3515 | 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] | 3516 | goto error; |
| 3517 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3518 | } else if (!strcmp(child->name, "revision-date")) { |
| 3519 | if (imp->rev[0]) { |
Radek Krejci | d52195b | 2016-06-22 11:18:49 +0200 | [diff] [blame] | 3520 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3521 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3522 | } |
| 3523 | GETVAL(value, child, "date"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3524 | if (lyp_check_date(value)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3525 | goto error; |
| 3526 | } |
| 3527 | memcpy(imp->rev, value, LY_REV_SIZE - 1); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3528 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3529 | 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] | 3530 | goto error; |
| 3531 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3532 | } else if ((module->version >= 2) && !strcmp(child->name, "description")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3533 | if (imp->dsc) { |
| 3534 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3535 | goto error; |
| 3536 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3537 | 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] | 3538 | goto error; |
| 3539 | } |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3540 | imp->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 3541 | if (!imp->dsc) { |
| 3542 | goto error; |
| 3543 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3544 | } else if ((module->version >= 2) && !strcmp(child->name, "reference")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3545 | if (imp->ref) { |
| 3546 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3547 | goto error; |
| 3548 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3549 | 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] | 3550 | goto error; |
| 3551 | } |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3552 | imp->ref = read_yin_subnode(module->ctx, child, "text"); |
| 3553 | if (!imp->ref) { |
| 3554 | goto error; |
| 3555 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3556 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3557 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3558 | goto error; |
| 3559 | } |
| 3560 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3561 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3562 | /* check mandatory information */ |
| 3563 | if (!imp->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3564 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3565 | goto error; |
| 3566 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 3567 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3568 | /* process extensions */ |
| 3569 | if (c_ext) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3570 | /* some extensions may be already present from the substatements */ |
| 3571 | reallocated = realloc(imp->ext, (c_ext + imp->ext_size) * sizeof *imp->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 3572 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3573 | imp->ext = reallocated; |
| 3574 | |
| 3575 | /* init memory */ |
| 3576 | memset(&imp->ext[imp->ext_size], 0, c_ext * sizeof *imp->ext); |
| 3577 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3578 | LY_TREE_FOR_SAFE(exts.child, next, child) { |
| 3579 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3580 | 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] | 3581 | imp->ext_size++; |
| 3582 | if (r) { |
| 3583 | goto error; |
| 3584 | } |
| 3585 | } |
| 3586 | } |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 3587 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3588 | GETVAL(value, yin, "module"); |
Pavol Vican | e994fda | 2016-03-22 10:47:58 +0100 | [diff] [blame] | 3589 | return lyp_check_import(module, value, imp); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 3590 | |
| 3591 | error: |
| 3592 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3593 | while (exts.child) { |
| 3594 | lyxml_free(module->ctx, exts.child); |
| 3595 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3596 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3597 | } |
| 3598 | |
Radek Krejci | 5b2c8a8 | 2016-06-17 15:36:03 +0200 | [diff] [blame] | 3599 | /* logs directly |
| 3600 | * returns: |
| 3601 | * 0 - inc successfully filled |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 3602 | * -1 - error |
Radek Krejci | 5b2c8a8 | 2016-06-17 15:36:03 +0200 | [diff] [blame] | 3603 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3604 | static int |
Michal Vasko | 5ff7882 | 2016-02-12 09:33:31 +0100 | [diff] [blame] | 3605 | fill_yin_include(struct lys_module *module, struct lys_submodule *submodule, struct lyxml_elem *yin, |
| 3606 | struct lys_include *inc, struct unres_schema *unres) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3607 | { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3608 | struct lyxml_elem *child, *next, exts; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3609 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3610 | int r, c_ext = 0; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3611 | void *reallocated; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3612 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3613 | /* init */ |
| 3614 | memset(&exts, 0, sizeof exts); |
| 3615 | |
| 3616 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 3617 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3618 | /* garbage */ |
| 3619 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3620 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 3621 | /* extension */ |
| 3622 | c_ext++; |
| 3623 | lyxml_unlink_elem(module->ctx, child, 2); |
| 3624 | lyxml_add_child(module->ctx, &exts, child); |
| 3625 | } else if (!strcmp(child->name, "revision-date")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3626 | if (inc->rev[0]) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3627 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3628 | goto error; |
| 3629 | } |
| 3630 | GETVAL(value, child, "date"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3631 | if (lyp_check_date(value)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3632 | goto error; |
| 3633 | } |
| 3634 | memcpy(inc->rev, value, LY_REV_SIZE - 1); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3635 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3636 | 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] | 3637 | goto error; |
| 3638 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3639 | } else if ((module->version >= 2) && !strcmp(child->name, "description")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3640 | if (inc->dsc) { |
| 3641 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3642 | goto error; |
| 3643 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3644 | 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] | 3645 | goto error; |
| 3646 | } |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3647 | inc->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 3648 | if (!inc->dsc) { |
| 3649 | goto error; |
| 3650 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 3651 | } else if ((module->version >= 2) && !strcmp(child->name, "reference")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3652 | if (inc->ref) { |
| 3653 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 3654 | goto error; |
| 3655 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3656 | 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] | 3657 | goto error; |
| 3658 | } |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 3659 | inc->ref = read_yin_subnode(module->ctx, child, "text"); |
| 3660 | if (!inc->ref) { |
| 3661 | goto error; |
| 3662 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3663 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3664 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3665 | goto error; |
| 3666 | } |
| 3667 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3668 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3669 | /* process extensions */ |
| 3670 | if (c_ext) { |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3671 | /* some extensions may be already present from the substatements */ |
| 3672 | reallocated = realloc(inc->ext, (c_ext + inc->ext_size) * sizeof *inc->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 3673 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 3674 | inc->ext = reallocated; |
| 3675 | |
| 3676 | /* init memory */ |
| 3677 | memset(&inc->ext[inc->ext_size], 0, c_ext * sizeof *inc->ext); |
| 3678 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3679 | LY_TREE_FOR_SAFE(exts.child, next, child) { |
| 3680 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3681 | 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] | 3682 | inc->ext_size++; |
| 3683 | if (r) { |
| 3684 | goto error; |
| 3685 | } |
| 3686 | } |
| 3687 | } |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 3688 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3689 | GETVAL(value, yin, "module"); |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 3690 | 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] | 3691 | |
| 3692 | error: |
| 3693 | |
Radek Krejci | 83e3f5b | 2016-06-24 14:55:25 +0200 | [diff] [blame] | 3694 | return -1; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 3695 | } |
| 3696 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3697 | /* logs directly |
| 3698 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3699 | * Covers: |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 3700 | * description, reference, status, optionaly config |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 3701 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3702 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3703 | static int |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3704 | read_yin_common(struct lys_module *module, struct lys_node *parent, void *stmt, LYEXT_PAR stmt_type, |
| 3705 | struct lyxml_elem *xmlnode, int opt, struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3706 | { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3707 | struct lys_node *node = stmt; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3708 | const char *value; |
| 3709 | struct lyxml_elem *sub, *next; |
| 3710 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3711 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3712 | if (opt & OPT_MODULE) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3713 | node->module = module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3714 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3715 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3716 | if (opt & OPT_IDENT) { |
| 3717 | GETVAL(value, xmlnode, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3718 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3719 | goto error; |
| 3720 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3721 | node->name = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3722 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3723 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3724 | /* process local parameters */ |
| 3725 | LY_TREE_FOR_SAFE(xmlnode->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3726 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3727 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3728 | lyxml_free(ctx, sub); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3729 | continue; |
| 3730 | } |
| 3731 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
Radek Krejci | 6ff885d | 2017-01-03 14:06:22 +0100 | [diff] [blame] | 3732 | /* 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] | 3733 | continue; |
| 3734 | } |
| 3735 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3736 | if (!strcmp(sub->name, "description")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3737 | if (node->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3738 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3739 | goto error; |
| 3740 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3741 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3742 | 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] | 3743 | goto error; |
| 3744 | } |
| 3745 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3746 | node->dsc = read_yin_subnode(ctx, sub, "text"); |
| 3747 | if (!node->dsc) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3748 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3749 | } |
| 3750 | } else if (!strcmp(sub->name, "reference")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3751 | if (node->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3752 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3753 | goto error; |
| 3754 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3755 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3756 | 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] | 3757 | goto error; |
| 3758 | } |
| 3759 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3760 | node->ref = read_yin_subnode(ctx, sub, "text"); |
| 3761 | if (!node->ref) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3762 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3763 | } |
| 3764 | } else if (!strcmp(sub->name, "status")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3765 | if (node->flags & LYS_STATUS_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3766 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3767 | goto error; |
| 3768 | } |
| 3769 | GETVAL(value, sub, "value"); |
| 3770 | if (!strcmp(value, "current")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3771 | node->flags |= LYS_STATUS_CURR; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3772 | } else if (!strcmp(value, "deprecated")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3773 | node->flags |= LYS_STATUS_DEPRC; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3774 | } else if (!strcmp(value, "obsolete")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3775 | node->flags |= LYS_STATUS_OBSLT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3776 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3777 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3778 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3779 | } |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3780 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3781 | 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] | 3782 | goto error; |
| 3783 | } |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3784 | } else if ((opt & (OPT_CFG_PARSE | OPT_CFG_IGNORE)) && !strcmp(sub->name, "config")) { |
| 3785 | if (opt & OPT_CFG_PARSE) { |
| 3786 | if (node->flags & LYS_CONFIG_MASK) { |
| 3787 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
| 3788 | goto error; |
| 3789 | } |
| 3790 | GETVAL(value, sub, "value"); |
| 3791 | if (!strcmp(value, "false")) { |
| 3792 | node->flags |= LYS_CONFIG_R; |
| 3793 | } else if (!strcmp(value, "true")) { |
| 3794 | node->flags |= LYS_CONFIG_W; |
| 3795 | } else { |
| 3796 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
| 3797 | goto error; |
| 3798 | } |
| 3799 | node->flags |= LYS_CONFIG_SET; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3800 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3801 | 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] | 3802 | goto error; |
| 3803 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3804 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3805 | } else { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3806 | /* skip the lyxml_free */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3807 | continue; |
| 3808 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3809 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3810 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3811 | |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 3812 | if ((opt & OPT_CFG_INHERIT) && !(node->flags & LYS_CONFIG_MASK)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3813 | /* get config flag from parent */ |
Radek Krejci | f71f48f | 2016-10-25 16:37:24 +0200 | [diff] [blame] | 3814 | if (parent) { |
| 3815 | node->flags |= parent->flags & LYS_CONFIG_MASK; |
| 3816 | } else if (!parent) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3817 | /* default config is true */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3818 | node->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3819 | } |
| 3820 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3821 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3822 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 3823 | |
| 3824 | error: |
| 3825 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3826 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3827 | } |
| 3828 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3829 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3830 | static struct lys_when * |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3831 | 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] | 3832 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3833 | struct lys_when *retval = NULL; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3834 | struct lyxml_elem *child, *next; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3835 | const char *value; |
| 3836 | |
| 3837 | retval = calloc(1, sizeof *retval); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 3838 | LY_CHECK_ERR_RETURN(!retval, LOGMEM, NULL); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3839 | |
| 3840 | GETVAL(value, yin, "condition"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3841 | retval->cond = transform_schema2json(module, value); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 3842 | if (!retval->cond) { |
| 3843 | goto error; |
| 3844 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3845 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3846 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 3847 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3848 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3849 | continue; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3850 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
| 3851 | /* extensions */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3852 | 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] | 3853 | goto error; |
| 3854 | } |
| 3855 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3856 | if (retval->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3857 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3858 | goto error; |
| 3859 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3860 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3861 | 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] | 3862 | goto error; |
| 3863 | } |
| 3864 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3865 | retval->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 3866 | if (!retval->dsc) { |
| 3867 | goto error; |
| 3868 | } |
| 3869 | } else if (!strcmp(child->name, "reference")) { |
| 3870 | if (retval->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3871 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3872 | goto error; |
| 3873 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3874 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 3875 | 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] | 3876 | goto error; |
| 3877 | } |
| 3878 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3879 | retval->ref = read_yin_subnode(module->ctx, child, "text"); |
| 3880 | if (!retval->ref) { |
| 3881 | goto error; |
| 3882 | } |
| 3883 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3884 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3885 | goto error; |
| 3886 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3887 | } |
| 3888 | |
| 3889 | return retval; |
| 3890 | |
| 3891 | error: |
| 3892 | |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3893 | lys_when_free(module->ctx, retval, NULL); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3894 | return NULL; |
| 3895 | } |
| 3896 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3897 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3898 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3899 | 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] | 3900 | struct unres_schema *unres) |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3901 | { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3902 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3903 | struct lys_node_case *cs; |
| 3904 | struct lys_node *retval, *node = NULL; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3905 | int c_ftrs = 0, c_ext = 0, ret; |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 3906 | void *reallocated; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3907 | |
Radek Krejci | e867c85 | 2015-08-27 09:52:34 +0200 | [diff] [blame] | 3908 | /* init */ |
| 3909 | memset(&root, 0, sizeof root); |
| 3910 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3911 | cs = calloc(1, sizeof *cs); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 3912 | LY_CHECK_ERR_RETURN(!cs, LOGMEM, NULL); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3913 | cs->nodetype = LYS_CASE; |
| 3914 | cs->prev = (struct lys_node *)cs; |
| 3915 | retval = (struct lys_node *)cs; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3916 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 3917 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3918 | 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] | 3919 | goto error; |
| 3920 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3921 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 3922 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3923 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3924 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 3925 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3926 | goto error; |
| 3927 | } |
| 3928 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3929 | /* process choice's specific children */ |
| 3930 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3931 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3932 | /* extension */ |
| 3933 | c_ext++; |
| 3934 | } else if (!strcmp(sub->name, "container") || |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3935 | !strcmp(sub->name, "leaf-list") || |
| 3936 | !strcmp(sub->name, "leaf") || |
| 3937 | !strcmp(sub->name, "list") || |
| 3938 | !strcmp(sub->name, "uses") || |
| 3939 | !strcmp(sub->name, "choice") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 3940 | !strcmp(sub->name, "anyxml") || |
| 3941 | !strcmp(sub->name, "anydata")) { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3942 | |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 3943 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3944 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3945 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3946 | c_ftrs++; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3947 | } else if (!strcmp(sub->name, "when")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3948 | if (cs->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 3949 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3950 | goto error; |
| 3951 | } |
| 3952 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 3953 | cs->when = read_yin_when(module, sub, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3954 | if (!cs->when) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3955 | goto error; |
| 3956 | } |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3957 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3958 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3959 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 3960 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3961 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3962 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3963 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3964 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3965 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 3966 | cs->iffeature = calloc(c_ftrs, sizeof *cs->iffeature); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 3967 | LY_CHECK_ERR_GOTO(!cs->iffeature, LOGMEM, error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3968 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3969 | if (c_ext) { |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 3970 | /* some extensions may be already present from the substatements */ |
| 3971 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 3972 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 3973 | retval->ext = reallocated; |
| 3974 | |
| 3975 | /* init memory */ |
| 3976 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3977 | } |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 3978 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 3979 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 3980 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 3981 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 3982 | 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] | 3983 | retval->ext_size++; |
| 3984 | if (ret) { |
| 3985 | goto error; |
| 3986 | } |
| 3987 | } else { |
| 3988 | /* if-feature */ |
| 3989 | ret = fill_yin_iffeature(retval, 0, sub, &cs->iffeature[cs->iffeature_size], unres); |
| 3990 | cs->iffeature_size++; |
| 3991 | if (ret) { |
| 3992 | goto error; |
| 3993 | } |
| 3994 | } |
| 3995 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 3996 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3997 | /* last part - process data nodes */ |
| 3998 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3999 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4000 | node = read_yin_container(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4001 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4002 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4003 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4004 | node = read_yin_leaf(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4005 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4006 | node = read_yin_list(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4007 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4008 | node = read_yin_choice(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4009 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4010 | node = read_yin_uses(module, retval, sub, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4011 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4012 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4013 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4014 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4015 | } |
| 4016 | if (!node) { |
| 4017 | goto error; |
| 4018 | } |
| 4019 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4020 | lyxml_free(module->ctx, sub); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4021 | } |
| 4022 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4023 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4024 | if (cs->when) { |
| 4025 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 4026 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4027 | goto error; |
| 4028 | } |
| 4029 | } else { |
| 4030 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 4031 | goto error; |
| 4032 | } |
| 4033 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4034 | } |
| 4035 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4036 | return retval; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4037 | |
| 4038 | error: |
| 4039 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4040 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4041 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 4042 | } |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4043 | lys_node_free(retval, NULL, 0); |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4044 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4045 | return NULL; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4046 | } |
| 4047 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4048 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4049 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4050 | 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] | 4051 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4052 | { |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4053 | struct lyxml_elem *sub, *next, *dflt = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4054 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4055 | struct lys_node *retval, *node = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4056 | struct lys_node_choice *choice; |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4057 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4058 | int f_mand = 0, c_ftrs = 0, c_ext = 0, ret; |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4059 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4060 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4061 | choice = calloc(1, sizeof *choice); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4062 | LY_CHECK_ERR_RETURN(!choice, LOGMEM, NULL); |
| 4063 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4064 | choice->nodetype = LYS_CHOICE; |
| 4065 | choice->prev = (struct lys_node *)choice; |
| 4066 | retval = (struct lys_node *)choice; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4067 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4068 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4069 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
| 4070 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), |
| 4071 | unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4072 | goto error; |
| 4073 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4074 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 4075 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4076 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4077 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4078 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4079 | goto error; |
| 4080 | } |
| 4081 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4082 | /* process choice's specific children */ |
| 4083 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4084 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4085 | /* extension */ |
| 4086 | c_ext++; |
| 4087 | /* keep it for later processing, skip lyxml_free() */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4088 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4089 | } else if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4090 | if (!(node = read_yin_container(module, retval, sub, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4091 | goto error; |
| 4092 | } |
| 4093 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4094 | if (!(node = read_yin_leaflist(module, retval, sub, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4095 | goto error; |
| 4096 | } |
| 4097 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4098 | if (!(node = read_yin_leaf(module, retval, sub, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4099 | goto error; |
| 4100 | } |
| 4101 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4102 | if (!(node = read_yin_list(module, retval, sub, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4103 | goto error; |
| 4104 | } |
| 4105 | } else if (!strcmp(sub->name, "case")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4106 | if (!(node = read_yin_case(module, retval, sub, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4107 | goto error; |
| 4108 | } |
| 4109 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4110 | if (!(node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres))) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4111 | goto error; |
| 4112 | } |
| 4113 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4114 | if (!(node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4115 | goto error; |
| 4116 | } |
| 4117 | } else if (!strcmp(sub->name, "default")) { |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4118 | if (dflt) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4119 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4120 | goto error; |
| 4121 | } |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4122 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4123 | 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] | 4124 | goto error; |
| 4125 | } |
| 4126 | |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4127 | dflt = sub; |
| 4128 | lyxml_unlink_elem(ctx, dflt, 0); |
Radek Krejci | f9a312c | 2016-06-06 15:14:30 +0200 | [diff] [blame] | 4129 | continue; |
| 4130 | /* skip lyxml_free() at the end of the loop, the sub node is processed later as dflt */ |
| 4131 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4132 | } else if (!strcmp(sub->name, "mandatory")) { |
| 4133 | if (f_mand) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4134 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4135 | goto error; |
| 4136 | } |
| 4137 | /* just checking the flags in leaf is not sufficient, we would allow |
| 4138 | * multiple mandatory statements with the "false" value |
| 4139 | */ |
| 4140 | f_mand = 1; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4141 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4142 | GETVAL(value, sub, "value"); |
| 4143 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4144 | choice->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4145 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4146 | choice->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4147 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4148 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4149 | goto error; |
| 4150 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4151 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4152 | 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] | 4153 | goto error; |
| 4154 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4155 | } else if (!strcmp(sub->name, "when")) { |
| 4156 | if (choice->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4157 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4158 | goto error; |
| 4159 | } |
| 4160 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4161 | choice->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4162 | if (!choice->when) { |
| 4163 | goto error; |
| 4164 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4165 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4166 | c_ftrs++; |
| 4167 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4168 | /* 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] | 4169 | continue; |
Radek Krejci | 2f792db | 2016-09-12 10:52:33 +0200 | [diff] [blame] | 4170 | } else if (module->version >= 2 && !strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4171 | if (!(node = read_yin_choice(module, retval, sub, options, unres))) { |
Radek Krejci | 2f792db | 2016-09-12 10:52:33 +0200 | [diff] [blame] | 4172 | goto error; |
| 4173 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4174 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4175 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4176 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4177 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4178 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4179 | node = NULL; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4180 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4181 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 4182 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4183 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4184 | choice->iffeature = calloc(c_ftrs, sizeof *choice->iffeature); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4185 | LY_CHECK_ERR_GOTO(!choice->iffeature, LOGMEM, error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4186 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4187 | if (c_ext) { |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4188 | /* some extensions may be already present from the substatements */ |
| 4189 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4190 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | 21c8165 | 2017-01-23 10:42:55 +0100 | [diff] [blame] | 4191 | retval->ext = reallocated; |
| 4192 | |
| 4193 | /* init memory */ |
| 4194 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4195 | } |
| 4196 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4197 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4198 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4199 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4200 | 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] | 4201 | retval->ext_size++; |
| 4202 | if (ret) { |
| 4203 | goto error; |
| 4204 | } |
| 4205 | } else { |
| 4206 | ret = fill_yin_iffeature(retval, 0, sub, &choice->iffeature[choice->iffeature_size], unres); |
| 4207 | choice->iffeature_size++; |
| 4208 | if (ret) { |
| 4209 | goto error; |
| 4210 | } |
| 4211 | } |
| 4212 | } |
| 4213 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4214 | /* check - default is prohibited in combination with mandatory */ |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4215 | if (dflt && (choice->flags & LYS_MAND_TRUE)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4216 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "default", "choice"); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4217 | 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] | 4218 | goto error; |
| 4219 | } |
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 | /* link default with the case */ |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4222 | if (dflt) { |
| 4223 | GETVAL(value, dflt, "value"); |
| 4224 | 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] | 4225 | goto error; |
| 4226 | } |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4227 | lyxml_free(ctx, dflt); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4228 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4229 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4230 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4231 | if (choice->when) { |
| 4232 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 4233 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4234 | goto error; |
| 4235 | } |
| 4236 | } else { |
| 4237 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 4238 | goto error; |
| 4239 | } |
| 4240 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4241 | } |
| 4242 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4243 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4244 | |
| 4245 | error: |
| 4246 | |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 4247 | lyxml_free(ctx, dflt); |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4248 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4249 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4250 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4251 | } |
| 4252 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4253 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4254 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 4255 | 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] | 4256 | int options, struct unres_schema *unres) |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4257 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4258 | struct lys_node *retval; |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4259 | struct lys_node_anydata *anyxml; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4260 | struct lyxml_elem *sub, *next; |
| 4261 | const char *value; |
| 4262 | int r; |
| 4263 | int f_mand = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4264 | int c_must = 0, c_ftrs = 0, c_ext = 0; |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4265 | void *reallocated; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4266 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4267 | anyxml = calloc(1, sizeof *anyxml); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4268 | LY_CHECK_ERR_RETURN(!anyxml, LOGMEM, NULL); |
| 4269 | |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4270 | anyxml->nodetype = type; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4271 | anyxml->prev = (struct lys_node *)anyxml; |
| 4272 | retval = (struct lys_node *)anyxml; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4273 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4274 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4275 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
| 4276 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), |
| 4277 | unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4278 | goto error; |
| 4279 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4280 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 4281 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4282 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4283 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4284 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4285 | goto error; |
| 4286 | } |
| 4287 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4288 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4289 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4290 | /* extension */ |
| 4291 | c_ext++; |
| 4292 | } else if (!strcmp(sub->name, "mandatory")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4293 | if (f_mand) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4294 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4295 | goto error; |
| 4296 | } |
| 4297 | /* just checking the flags in leaf is not sufficient, we would allow |
| 4298 | * multiple mandatory statements with the "false" value |
| 4299 | */ |
| 4300 | f_mand = 1; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4301 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4302 | GETVAL(value, sub, "value"); |
| 4303 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4304 | anyxml->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4305 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4306 | anyxml->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4307 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4308 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4309 | goto error; |
| 4310 | } |
| 4311 | /* else false is the default value, so we can ignore it */ |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4312 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4313 | 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] | 4314 | goto error; |
| 4315 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4316 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4317 | } else if (!strcmp(sub->name, "when")) { |
| 4318 | if (anyxml->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4319 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4320 | goto error; |
| 4321 | } |
| 4322 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4323 | anyxml->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4324 | if (!anyxml->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4325 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4326 | goto error; |
| 4327 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4328 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4329 | } else if (!strcmp(sub->name, "must")) { |
| 4330 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4331 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4332 | c_ftrs++; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4333 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4334 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4335 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4336 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4337 | } |
| 4338 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4339 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4340 | /* middle part - process nodes with cardinality of 0..n */ |
| 4341 | if (c_must) { |
| 4342 | anyxml->must = calloc(c_must, sizeof *anyxml->must); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4343 | LY_CHECK_ERR_GOTO(!anyxml->must, LOGMEM, error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4344 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4345 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4346 | anyxml->iffeature = calloc(c_ftrs, sizeof *anyxml->iffeature); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4347 | LY_CHECK_ERR_GOTO(!anyxml->iffeature, LOGMEM, error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4348 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4349 | if (c_ext) { |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4350 | /* some extensions may be already present from the substatements */ |
| 4351 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4352 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | 3a5d9cf | 2017-01-18 14:06:25 +0100 | [diff] [blame] | 4353 | retval->ext = reallocated; |
| 4354 | |
| 4355 | /* init memory */ |
| 4356 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4357 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4358 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4359 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4360 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4361 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4362 | 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] | 4363 | retval->ext_size++; |
| 4364 | if (r) { |
| 4365 | goto error; |
| 4366 | } |
| 4367 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4368 | r = fill_yin_must(module, sub, &anyxml->must[anyxml->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4369 | anyxml->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4370 | if (r) { |
| 4371 | goto error; |
| 4372 | } |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 4373 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 4374 | 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] | 4375 | anyxml->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4376 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4377 | goto error; |
| 4378 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4379 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4380 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4381 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4382 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4383 | if (anyxml->when || anyxml->must) { |
| 4384 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 4385 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4386 | goto error; |
| 4387 | } |
| 4388 | } else { |
| 4389 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 4390 | goto error; |
| 4391 | } |
| 4392 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4393 | } |
| 4394 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4395 | return retval; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4396 | |
| 4397 | error: |
| 4398 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4399 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4400 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4401 | return NULL; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 4402 | } |
| 4403 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4404 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4405 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4406 | 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] | 4407 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4408 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4409 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4410 | struct lys_node_leaf *leaf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4411 | struct lyxml_elem *sub, *next; |
| 4412 | const char *value; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4413 | int r, has_type = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4414 | 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] | 4415 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4416 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4417 | leaf = calloc(1, sizeof *leaf); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4418 | LY_CHECK_ERR_RETURN(!leaf, LOGMEM, NULL); |
| 4419 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4420 | leaf->nodetype = LYS_LEAF; |
| 4421 | leaf->prev = (struct lys_node *)leaf; |
| 4422 | retval = (struct lys_node *)leaf; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4423 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4424 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4425 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
| 4426 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), |
| 4427 | unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4428 | goto error; |
| 4429 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4430 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 4431 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4432 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4433 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4434 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4435 | goto error; |
| 4436 | } |
| 4437 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4438 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4439 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4440 | /* extension */ |
| 4441 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4442 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4443 | } else if (!strcmp(sub->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 4444 | if (has_type) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4445 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4446 | goto error; |
| 4447 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4448 | /* HACK for unres */ |
| 4449 | leaf->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 4450 | leaf->type.parent = (struct lys_tpdf *)leaf; |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4451 | /* postpone type resolution when if-feature parsing is done since we need |
| 4452 | * if-feature for check_leafref_features() */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4453 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4454 | } else if (!strcmp(sub->name, "default")) { |
| 4455 | if (leaf->dflt) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4456 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4457 | goto error; |
| 4458 | } |
| 4459 | GETVAL(value, sub, "value"); |
| 4460 | leaf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 1abcdae | 2017-01-18 14:14:18 +0100 | [diff] [blame] | 4461 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4462 | 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] | 4463 | goto error; |
| 4464 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4465 | } else if (!strcmp(sub->name, "units")) { |
| 4466 | if (leaf->units) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4467 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4468 | goto error; |
| 4469 | } |
| 4470 | GETVAL(value, sub, "name"); |
| 4471 | leaf->units = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4472 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4473 | 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] | 4474 | goto error; |
| 4475 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4476 | } else if (!strcmp(sub->name, "mandatory")) { |
| 4477 | if (f_mand) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4478 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4479 | goto error; |
| 4480 | } |
| 4481 | /* just checking the flags in leaf is not sufficient, we would allow |
| 4482 | * multiple mandatory statements with the "false" value |
| 4483 | */ |
| 4484 | f_mand = 1; |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4485 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4486 | GETVAL(value, sub, "value"); |
| 4487 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4488 | leaf->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4489 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4490 | leaf->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4491 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4492 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4493 | goto error; |
| 4494 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4495 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4496 | 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] | 4497 | goto error; |
| 4498 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4499 | } else if (!strcmp(sub->name, "when")) { |
| 4500 | if (leaf->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4501 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4502 | goto error; |
| 4503 | } |
| 4504 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4505 | leaf->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4506 | if (!leaf->when) { |
| 4507 | goto error; |
| 4508 | } |
| 4509 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4510 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4511 | c_must++; |
| 4512 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4513 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4514 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4515 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4516 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4517 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4518 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4519 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4520 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4521 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4522 | /* 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] | 4523 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4524 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4525 | /* check mandatory parameters */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4526 | if (!has_type) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4527 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_LYS, retval, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4528 | goto error; |
| 4529 | } |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 4530 | if (leaf->dflt && (leaf->flags & LYS_MAND_TRUE)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4531 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "mandatory", "leaf"); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4532 | LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 4533 | "The \"mandatory\" statement is forbidden on leaf with the \"default\" statement."); |
| 4534 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4535 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4536 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4537 | /* middle part - process nodes with cardinality of 0..n */ |
| 4538 | if (c_must) { |
| 4539 | leaf->must = calloc(c_must, sizeof *leaf->must); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4540 | LY_CHECK_ERR_GOTO(!leaf->must, LOGMEM, error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4541 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4542 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4543 | leaf->iffeature = calloc(c_ftrs, sizeof *leaf->iffeature); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4544 | LY_CHECK_ERR_GOTO(!leaf->iffeature, LOGMEM, error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4545 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4546 | if (c_ext) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4547 | /* some extensions may be already present from the substatements */ |
| 4548 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4549 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4550 | retval->ext = reallocated; |
| 4551 | |
| 4552 | /* init memory */ |
| 4553 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4554 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4555 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4556 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4557 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4558 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4559 | 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] | 4560 | retval->ext_size++; |
| 4561 | if (r) { |
| 4562 | goto error; |
| 4563 | } |
| 4564 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4565 | r = fill_yin_must(module, sub, &leaf->must[leaf->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4566 | leaf->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4567 | if (r) { |
| 4568 | goto error; |
| 4569 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4570 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 4571 | 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] | 4572 | leaf->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4573 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4574 | goto error; |
| 4575 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4576 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4577 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4578 | |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4579 | /* finalize type parsing */ |
| 4580 | if (unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DER, retval) == -1) { |
| 4581 | leaf->type.der = NULL; |
| 4582 | goto error; |
| 4583 | } |
| 4584 | |
| 4585 | /* check default value (if not defined, there still could be some restrictions |
| 4586 | * 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] | 4587 | if (!(options & LYS_PARSE_OPT_INGRP) && |
| 4588 | (unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DFLT, |
| 4589 | (struct lys_node *)(&leaf->dflt)) == -1)) { |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4590 | goto error; |
| 4591 | } |
| 4592 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4593 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4594 | if (leaf->when || leaf->must) { |
| 4595 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 4596 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4597 | goto error; |
| 4598 | } |
| 4599 | } else { |
| 4600 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 4601 | goto error; |
| 4602 | } |
| 4603 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4604 | } |
| 4605 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4606 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4607 | |
| 4608 | error: |
| 4609 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4610 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4611 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4612 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4613 | } |
| 4614 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4615 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4616 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4617 | 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] | 4618 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4619 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4620 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4621 | struct lys_node_leaflist *llist; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4622 | struct lyxml_elem *sub, *next; |
| 4623 | const char *value; |
| 4624 | char *endptr; |
| 4625 | unsigned long val; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4626 | int r, has_type = 0; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4627 | 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] | 4628 | int f_ordr = 0, f_min = 0, f_max = 0; |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4629 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4630 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4631 | llist = calloc(1, sizeof *llist); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4632 | LY_CHECK_ERR_RETURN(!llist, LOGMEM, NULL); |
| 4633 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4634 | llist->nodetype = LYS_LEAFLIST; |
| 4635 | llist->prev = (struct lys_node *)llist; |
| 4636 | retval = (struct lys_node *)llist; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4637 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4638 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4639 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
| 4640 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), |
| 4641 | unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4642 | goto error; |
| 4643 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4644 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 4645 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4646 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4647 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4648 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4649 | goto error; |
| 4650 | } |
| 4651 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4652 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4653 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4654 | /* extension */ |
| 4655 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4656 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4657 | } else if (!strcmp(sub->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 4658 | if (has_type) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4659 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4660 | goto error; |
| 4661 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4662 | /* HACK for unres */ |
| 4663 | llist->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 4664 | llist->type.parent = (struct lys_tpdf *)llist; |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4665 | /* postpone type resolution when if-feature parsing is done since we need |
| 4666 | * if-feature for check_leafref_features() */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4667 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4668 | } else if (!strcmp(sub->name, "units")) { |
| 4669 | if (llist->units) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4670 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4671 | goto error; |
| 4672 | } |
| 4673 | GETVAL(value, sub, "name"); |
| 4674 | llist->units = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4675 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4676 | 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] | 4677 | goto error; |
| 4678 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4679 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 4680 | if (f_ordr) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4681 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4682 | goto error; |
| 4683 | } |
| 4684 | /* just checking the flags in llist is not sufficient, we would |
| 4685 | * allow multiple ordered-by statements with the "system" value |
| 4686 | */ |
| 4687 | f_ordr = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4688 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4689 | if (llist->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4690 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 4691 | * state data |
| 4692 | */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4693 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4694 | continue; |
| 4695 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4696 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4697 | GETVAL(value, sub, "value"); |
| 4698 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4699 | llist->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4700 | } else if (strcmp(value, "system")) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4701 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4702 | goto error; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4703 | } /* else system is the default value, so we can ignore it */ |
| 4704 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4705 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, LYEXT_SUBSTMT_ORDEREDBY, 0, unres)) { |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 4706 | goto error; |
| 4707 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4708 | } else if (!strcmp(sub->name, "must")) { |
| 4709 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4710 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4711 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4712 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4713 | continue; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4714 | } else if ((module->version >= 2) && !strcmp(sub->name, "default")) { |
Radek Krejci | ac00b2a | 2017-01-17 14:05:00 +0100 | [diff] [blame] | 4715 | /* read the default's extension instances */ |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4716 | 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] | 4717 | goto error; |
| 4718 | } |
| 4719 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4720 | c_dflt++; |
| 4721 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 4722 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4723 | } else if (!strcmp(sub->name, "min-elements")) { |
| 4724 | if (f_min) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4725 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4726 | goto error; |
| 4727 | } |
| 4728 | f_min = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4729 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4730 | GETVAL(value, sub, "value"); |
| 4731 | while (isspace(value[0])) { |
| 4732 | value++; |
| 4733 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4734 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4735 | /* convert it to uint32_t */ |
| 4736 | errno = 0; |
| 4737 | endptr = NULL; |
| 4738 | val = strtoul(value, &endptr, 10); |
| 4739 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4740 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4741 | goto error; |
| 4742 | } |
| 4743 | llist->min = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 4744 | if (llist->max && (llist->min > llist->max)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4745 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4746 | 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] | 4747 | goto error; |
| 4748 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4749 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4750 | 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] | 4751 | goto error; |
| 4752 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4753 | } else if (!strcmp(sub->name, "max-elements")) { |
| 4754 | if (f_max) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4755 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4756 | goto error; |
| 4757 | } |
| 4758 | f_max = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4759 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4760 | GETVAL(value, sub, "value"); |
| 4761 | while (isspace(value[0])) { |
| 4762 | value++; |
| 4763 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4764 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 4765 | if (!strcmp(value, "unbounded")) { |
| 4766 | llist->max = 0; |
| 4767 | } else { |
| 4768 | /* convert it to uint32_t */ |
| 4769 | errno = 0; |
| 4770 | endptr = NULL; |
| 4771 | val = strtoul(value, &endptr, 10); |
| 4772 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4773 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 4774 | goto error; |
| 4775 | } |
| 4776 | llist->max = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 4777 | if (llist->min > llist->max) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4778 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4779 | 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] | 4780 | goto error; |
| 4781 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4782 | } |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4783 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 4784 | 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] | 4785 | goto error; |
| 4786 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4787 | } else if (!strcmp(sub->name, "when")) { |
| 4788 | if (llist->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4789 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4790 | goto error; |
| 4791 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4792 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4793 | llist->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4794 | if (!llist->when) { |
| 4795 | goto error; |
| 4796 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4797 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4798 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4799 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4800 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4801 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 4802 | /* 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] | 4803 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4804 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4805 | /* check constraints */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4806 | if (!has_type) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4807 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_LYS, retval, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4808 | goto error; |
| 4809 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4810 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4811 | /* middle part - process nodes with cardinality of 0..n */ |
| 4812 | if (c_must) { |
| 4813 | llist->must = calloc(c_must, sizeof *llist->must); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4814 | LY_CHECK_ERR_GOTO(!llist->must, LOGMEM, error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4815 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4816 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4817 | llist->iffeature = calloc(c_ftrs, sizeof *llist->iffeature); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4818 | LY_CHECK_ERR_GOTO(!llist->iffeature, LOGMEM, error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4819 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4820 | if (c_dflt) { |
| 4821 | llist->dflt = calloc(c_dflt, sizeof *llist->dflt); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4822 | LY_CHECK_ERR_GOTO(!llist->dflt, LOGMEM, error); |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4823 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4824 | if (c_ext) { |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4825 | /* some extensions may be already present from the substatements */ |
| 4826 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4827 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 4828 | retval->ext = reallocated; |
| 4829 | |
| 4830 | /* init memory */ |
| 4831 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4832 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 4833 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4834 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 4835 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4836 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 4837 | 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] | 4838 | retval->ext_size++; |
| 4839 | if (r) { |
| 4840 | goto error; |
| 4841 | } |
| 4842 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 4843 | r = fill_yin_must(module, sub, &llist->must[llist->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4844 | llist->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4845 | if (r) { |
| 4846 | goto error; |
| 4847 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4848 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 4849 | 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] | 4850 | llist->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4851 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4852 | goto error; |
| 4853 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4854 | } else if (!strcmp(sub->name, "default")) { |
| 4855 | GETVAL(value, sub, "value"); |
| 4856 | |
Radek Krejci | ac1a52c | 2016-09-15 14:42:40 +0200 | [diff] [blame] | 4857 | /* check for duplicity in case of configuration data, |
| 4858 | * in case of status data duplicities are allowed */ |
| 4859 | if (llist->flags & LYS_CONFIG_W) { |
| 4860 | for (r = 0; r < llist->dflt_size; r++) { |
| 4861 | if (ly_strequal(llist->dflt[r], value, 1)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4862 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, "default"); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4863 | LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, "Duplicated default value \"%s\".", value); |
Radek Krejci | ac1a52c | 2016-09-15 14:42:40 +0200 | [diff] [blame] | 4864 | goto error; |
| 4865 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4866 | } |
| 4867 | } |
| 4868 | llist->dflt[llist->dflt_size++] = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4869 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4870 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4871 | |
Radek Krejci | cbb473e | 2016-09-16 14:48:32 +0200 | [diff] [blame] | 4872 | /* finalize type parsing */ |
| 4873 | if (unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DER, retval) == -1) { |
| 4874 | llist->type.der = NULL; |
| 4875 | goto error; |
| 4876 | } |
| 4877 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4878 | if (llist->dflt_size && llist->min) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4879 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_LYS, retval, "min-elements", "leaf-list"); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 4880 | LOGVAL(LYE_SPEC, LY_VLOG_PREV, NULL, |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4881 | "The \"min-elements\" statement with non-zero value is forbidden on leaf-lists with the \"default\" statement."); |
| 4882 | goto error; |
| 4883 | } |
| 4884 | |
| 4885 | /* check default value (if not defined, there still could be some restrictions |
| 4886 | * that need to be checked against a default value from a derived type) */ |
| 4887 | for (r = 0; r < llist->dflt_size; r++) { |
Radek Krejci | ab08f0f | 2017-03-09 16:37:15 +0100 | [diff] [blame] | 4888 | if (!(options & LYS_PARSE_OPT_INGRP) && |
| 4889 | (unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DFLT, |
| 4890 | (struct lys_node *)(&llist->dflt[r])) == -1)) { |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 4891 | goto error; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 4892 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4893 | } |
| 4894 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4895 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4896 | if (llist->when || llist->must) { |
| 4897 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 4898 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4899 | goto error; |
| 4900 | } |
| 4901 | } else { |
| 4902 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 4903 | goto error; |
| 4904 | } |
| 4905 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4906 | } |
| 4907 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4908 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4909 | |
| 4910 | error: |
| 4911 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4912 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4913 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4914 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4915 | } |
| 4916 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4917 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4918 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4919 | 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] | 4920 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4921 | { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4922 | struct lys_node *retval, *node; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4923 | struct lys_node_list *list; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4924 | struct lyxml_elem *sub, *next, root, uniq; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4925 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4926 | 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] | 4927 | int f_ordr = 0, f_max = 0, f_min = 0; |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 4928 | const char *value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4929 | char *auxs; |
| 4930 | unsigned long val; |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 4931 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4932 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4933 | /* init */ |
| 4934 | memset(&root, 0, sizeof root); |
| 4935 | memset(&uniq, 0, sizeof uniq); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4936 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4937 | list = calloc(1, sizeof *list); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4938 | LY_CHECK_ERR_RETURN(!list, LOGMEM, NULL); |
| 4939 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4940 | list->nodetype = LYS_LIST; |
| 4941 | list->prev = (struct lys_node *)list; |
| 4942 | retval = (struct lys_node *)list; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4943 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 4944 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4945 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
| 4946 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), |
| 4947 | unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4948 | goto error; |
| 4949 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4950 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 4951 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4952 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4953 | /* insert the node into the schema tree */ |
| 4954 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 4955 | goto error; |
| 4956 | } |
| 4957 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4958 | /* process list's specific children */ |
| 4959 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4960 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 4961 | /* extension */ |
| 4962 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4963 | continue; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4964 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4965 | /* data statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 4966 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4967 | !strcmp(sub->name, "leaf-list") || |
| 4968 | !strcmp(sub->name, "leaf") || |
| 4969 | !strcmp(sub->name, "list") || |
| 4970 | !strcmp(sub->name, "choice") || |
| 4971 | !strcmp(sub->name, "uses") || |
| 4972 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 4973 | !strcmp(sub->name, "anyxml") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 4974 | !strcmp(sub->name, "anydata") || |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 4975 | !strcmp(sub->name, "action") || |
| 4976 | !strcmp(sub->name, "notification")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4977 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4978 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4979 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4980 | /* array counters */ |
| 4981 | } else if (!strcmp(sub->name, "key")) { |
| 4982 | /* check cardinality 0..1 */ |
| 4983 | if (list->keys_size) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 4984 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, list->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4985 | goto error; |
| 4986 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4987 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4988 | /* count the number of keys */ |
| 4989 | GETVAL(value, sub, "value"); |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 4990 | list->keys_str = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4991 | while ((value = strpbrk(value, " \t\n"))) { |
| 4992 | list->keys_size++; |
| 4993 | while (isspace(*value)) { |
| 4994 | value++; |
| 4995 | } |
| 4996 | } |
| 4997 | list->keys_size++; |
| 4998 | list->keys = calloc(list->keys_size, sizeof *list->keys); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4999 | LY_CHECK_ERR_GOTO(!list->keys, LOGMEM, error); |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5000 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5001 | 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] | 5002 | goto error; |
| 5003 | } |
| 5004 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5005 | } else if (!strcmp(sub->name, "unique")) { |
| 5006 | c_uniq++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5007 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5008 | lyxml_add_child(module->ctx, &uniq, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5009 | } else if (!strcmp(sub->name, "typedef")) { |
| 5010 | c_tpdf++; |
| 5011 | } else if (!strcmp(sub->name, "must")) { |
| 5012 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5013 | } else if (!strcmp(sub->name, "if-feature")) { |
| 5014 | c_ftrs++; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5015 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5016 | /* optional stetments */ |
| 5017 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 5018 | if (f_ordr) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5019 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5020 | goto error; |
| 5021 | } |
| 5022 | /* just checking the flags in llist is not sufficient, we would |
| 5023 | * allow multiple ordered-by statements with the "system" value |
| 5024 | */ |
| 5025 | f_ordr = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5026 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 5027 | if (list->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5028 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 5029 | * state data |
| 5030 | */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5031 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5032 | continue; |
| 5033 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5034 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5035 | GETVAL(value, sub, "value"); |
| 5036 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 5037 | list->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5038 | } else if (strcmp(value, "system")) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5039 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5040 | goto error; |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5041 | } /* else system is the default value, so we can ignore it */ |
| 5042 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5043 | 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] | 5044 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5045 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5046 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5047 | } else if (!strcmp(sub->name, "min-elements")) { |
| 5048 | if (f_min) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5049 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5050 | goto error; |
| 5051 | } |
| 5052 | f_min = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5053 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5054 | GETVAL(value, sub, "value"); |
| 5055 | while (isspace(value[0])) { |
| 5056 | value++; |
| 5057 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5058 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5059 | /* convert it to uint32_t */ |
| 5060 | errno = 0; |
| 5061 | auxs = NULL; |
| 5062 | val = strtoul(value, &auxs, 10); |
| 5063 | if (*auxs || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5064 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5065 | goto error; |
| 5066 | } |
| 5067 | list->min = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 5068 | if (list->max && (list->min > list->max)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5069 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 5070 | 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] | 5071 | lyxml_free(module->ctx, sub); |
| 5072 | goto error; |
| 5073 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5074 | 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] | 5075 | goto error; |
| 5076 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5077 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5078 | } else if (!strcmp(sub->name, "max-elements")) { |
| 5079 | if (f_max) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5080 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5081 | goto error; |
| 5082 | } |
| 5083 | f_max = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5084 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5085 | GETVAL(value, sub, "value"); |
| 5086 | while (isspace(value[0])) { |
| 5087 | value++; |
| 5088 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5089 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 5090 | if (!strcmp(value, "unbounded")) { |
| 5091 | list->max = 0;; |
| 5092 | } else { |
| 5093 | /* convert it to uint32_t */ |
| 5094 | errno = 0; |
| 5095 | auxs = NULL; |
| 5096 | val = strtoul(value, &auxs, 10); |
| 5097 | if (*auxs || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5098 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 5099 | goto error; |
| 5100 | } |
| 5101 | list->max = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 5102 | if (list->min > list->max) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5103 | LOGVAL(LYE_INARG, LY_VLOG_LYS, retval, value, sub->name); |
Michal Vasko | 51e5c58 | 2017-01-19 14:16:39 +0100 | [diff] [blame] | 5104 | 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] | 5105 | goto error; |
| 5106 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5107 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5108 | 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] | 5109 | goto error; |
| 5110 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5111 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5112 | } else if (!strcmp(sub->name, "when")) { |
| 5113 | if (list->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5114 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5115 | goto error; |
| 5116 | } |
| 5117 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 5118 | list->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5119 | if (!list->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5120 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5121 | goto error; |
| 5122 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5123 | lyxml_free(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5124 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5125 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5126 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5127 | } |
| 5128 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 5129 | |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5130 | /* check - if list is configuration, key statement is mandatory |
| 5131 | * (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] | 5132 | 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] | 5133 | if (!node && (list->flags & LYS_CONFIG_W) && !list->keys_str) { |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5134 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_LYS, retval, "key", "list"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5135 | goto error; |
| 5136 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5137 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5138 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5139 | if (c_tpdf) { |
| 5140 | list->tpdf = calloc(c_tpdf, sizeof *list->tpdf); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5141 | LY_CHECK_ERR_GOTO(!list->tpdf, LOGMEM, error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5142 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5143 | if (c_must) { |
| 5144 | list->must = calloc(c_must, sizeof *list->must); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5145 | LY_CHECK_ERR_GOTO(!list->must, LOGMEM, error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5146 | } |
| 5147 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5148 | list->iffeature = calloc(c_ftrs, sizeof *list->iffeature); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5149 | LY_CHECK_ERR_GOTO(!list->iffeature, LOGMEM, error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5150 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5151 | if (c_ext) { |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5152 | /* some extensions may be already present from the substatements */ |
| 5153 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5154 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5155 | retval->ext = reallocated; |
| 5156 | |
| 5157 | /* init memory */ |
| 5158 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5159 | } |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5160 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5161 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5162 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5163 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5164 | 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] | 5165 | retval->ext_size++; |
| 5166 | if (r) { |
| 5167 | goto error; |
| 5168 | } |
| 5169 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5170 | r = fill_yin_typedef(module, retval, sub, &list->tpdf[list->tpdf_size], unres); |
| 5171 | list->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5172 | if (r) { |
| 5173 | goto error; |
| 5174 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5175 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 5176 | 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] | 5177 | list->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 5178 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 5179 | goto error; |
| 5180 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5181 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5182 | r = fill_yin_must(module, sub, &list->must[list->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5183 | list->must_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5184 | if (r) { |
| 5185 | goto error; |
| 5186 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5187 | } |
| 5188 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5189 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5190 | /* last part - process data nodes */ |
| 5191 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5192 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5193 | node = read_yin_container(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5194 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5195 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5196 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5197 | node = read_yin_leaf(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5198 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5199 | node = read_yin_list(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5200 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5201 | node = read_yin_choice(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5202 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5203 | node = read_yin_uses(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5204 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5205 | node = read_yin_grouping(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5206 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5207 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5208 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5209 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5210 | } else if (!strcmp(sub->name, "action")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5211 | node = read_yin_rpc_action(module, retval, sub, options, unres); |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 5212 | } else if (!strcmp(sub->name, "notification")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5213 | node = read_yin_notif(module, retval, sub, options, unres); |
Michal Vasko | c07187d | 2015-08-13 15:20:57 +0200 | [diff] [blame] | 5214 | } else { |
| 5215 | LOGINT; |
| 5216 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5217 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5218 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5219 | goto error; |
| 5220 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5221 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5222 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5223 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5224 | |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 5225 | if (list->keys_str) { |
| 5226 | /* check that we are not in grouping */ |
| 5227 | for (node = parent; node && node->nodetype != LYS_GROUPING; node = lys_parent(node)); |
| 5228 | 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] | 5229 | goto error; |
| 5230 | } |
| 5231 | } /* 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] | 5232 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5233 | /* process unique statements */ |
| 5234 | if (c_uniq) { |
| 5235 | list->unique = calloc(c_uniq, sizeof *list->unique); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5236 | LY_CHECK_ERR_GOTO(!list->unique, LOGMEM, error); |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 5237 | |
Radek Krejci | 461efb9 | 2016-02-12 15:52:18 +0100 | [diff] [blame] | 5238 | LY_TREE_FOR_SAFE(uniq.child, next, sub) { |
| 5239 | r = fill_yin_unique(module, retval, sub, &list->unique[list->unique_size], unres); |
| 5240 | list->unique_size++; |
| 5241 | if (r) { |
| 5242 | goto error; |
| 5243 | } |
| 5244 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5245 | if (lyp_yin_parse_subnode_ext(module, retval, LYEXT_PAR_NODE, sub, |
Radek Krejci | e36d7c7 | 2017-01-17 16:12:30 +0100 | [diff] [blame] | 5246 | LYEXT_SUBSTMT_UNIQUE, list->unique_size - 1, unres)) { |
| 5247 | goto error; |
| 5248 | } |
Radek Krejci | 461efb9 | 2016-02-12 15:52:18 +0100 | [diff] [blame] | 5249 | lyxml_free(module->ctx, sub); |
| 5250 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5251 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 5252 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5253 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5254 | if (list->when || list->must) { |
| 5255 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 5256 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5257 | goto error; |
| 5258 | } |
| 5259 | } else { |
| 5260 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 5261 | goto error; |
| 5262 | } |
| 5263 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5264 | } |
| 5265 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5266 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5267 | |
| 5268 | error: |
| 5269 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5270 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5271 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5272 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5273 | } |
| 5274 | while (uniq.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5275 | lyxml_free(module->ctx, uniq.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5276 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5277 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5278 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5279 | } |
| 5280 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5281 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5282 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5283 | 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] | 5284 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5285 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5286 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5287 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5288 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5289 | struct lys_node_container *cont; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5290 | const char *value; |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5291 | void *reallocated; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5292 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5293 | 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] | 5294 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5295 | /* init */ |
| 5296 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5297 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5298 | cont = calloc(1, sizeof *cont); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5299 | LY_CHECK_ERR_RETURN(!cont, LOGMEM, NULL); |
| 5300 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5301 | cont->nodetype = LYS_CONTAINER; |
| 5302 | cont->prev = (struct lys_node *)cont; |
| 5303 | retval = (struct lys_node *)cont; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5304 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5305 | if (read_yin_common(module, parent, retval, LYEXT_PAR_NODE, yin, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5306 | OPT_IDENT | OPT_MODULE | ((options & LYS_PARSE_OPT_CFG_IGNORE) ? OPT_CFG_IGNORE : |
| 5307 | (options & LYS_PARSE_OPT_CFG_NOINHERIT) ? OPT_CFG_PARSE : OPT_CFG_PARSE | OPT_CFG_INHERIT), |
| 5308 | unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5309 | goto error; |
| 5310 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5311 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 5312 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5313 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5314 | /* insert the node into the schema tree */ |
| 5315 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5316 | goto error; |
| 5317 | } |
| 5318 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5319 | /* process container's specific children */ |
| 5320 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5321 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5322 | /* extension */ |
| 5323 | c_ext++; |
| 5324 | } else if (!strcmp(sub->name, "presence")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5325 | if (cont->presence) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5326 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5327 | goto error; |
| 5328 | } |
| 5329 | GETVAL(value, sub, "value"); |
| 5330 | cont->presence = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 5331 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 5332 | 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] | 5333 | goto error; |
| 5334 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5335 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5336 | } else if (!strcmp(sub->name, "when")) { |
| 5337 | if (cont->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5338 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5339 | goto error; |
| 5340 | } |
| 5341 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 5342 | cont->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5343 | if (!cont->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5344 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5345 | goto error; |
| 5346 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5347 | lyxml_free(module->ctx, sub); |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 5348 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5349 | /* data statements */ |
| 5350 | } else if (!strcmp(sub->name, "container") || |
| 5351 | !strcmp(sub->name, "leaf-list") || |
| 5352 | !strcmp(sub->name, "leaf") || |
| 5353 | !strcmp(sub->name, "list") || |
| 5354 | !strcmp(sub->name, "choice") || |
| 5355 | !strcmp(sub->name, "uses") || |
| 5356 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5357 | !strcmp(sub->name, "anyxml") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 5358 | !strcmp(sub->name, "anydata") || |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 5359 | !strcmp(sub->name, "action") || |
| 5360 | !strcmp(sub->name, "notification")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5361 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5362 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5363 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5364 | /* array counters */ |
| 5365 | } else if (!strcmp(sub->name, "typedef")) { |
| 5366 | c_tpdf++; |
| 5367 | } else if (!strcmp(sub->name, "must")) { |
| 5368 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5369 | } else if (!strcmp(sub->name, "if-feature")) { |
| 5370 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5371 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5372 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5373 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5374 | } |
| 5375 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5376 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5377 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5378 | if (c_tpdf) { |
| 5379 | cont->tpdf = calloc(c_tpdf, sizeof *cont->tpdf); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5380 | LY_CHECK_ERR_GOTO(!cont->tpdf, LOGMEM, error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5381 | } |
| 5382 | if (c_must) { |
| 5383 | cont->must = calloc(c_must, sizeof *cont->must); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5384 | LY_CHECK_ERR_GOTO(!cont->must, LOGMEM, error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5385 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5386 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5387 | cont->iffeature = calloc(c_ftrs, sizeof *cont->iffeature); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5388 | LY_CHECK_ERR_GOTO(!cont->iffeature, LOGMEM, error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5389 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5390 | if (c_ext) { |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5391 | /* some extensions may be already present from the substatements */ |
| 5392 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5393 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5394 | retval->ext = reallocated; |
| 5395 | |
| 5396 | /* init memory */ |
| 5397 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5398 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 5399 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5400 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5401 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5402 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5403 | 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] | 5404 | retval->ext_size++; |
| 5405 | if (r) { |
| 5406 | goto error; |
| 5407 | } |
| 5408 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5409 | r = fill_yin_typedef(module, retval, sub, &cont->tpdf[cont->tpdf_size], unres); |
| 5410 | cont->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5411 | if (r) { |
| 5412 | goto error; |
| 5413 | } |
| 5414 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5415 | r = fill_yin_must(module, sub, &cont->must[cont->must_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5416 | cont->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5417 | if (r) { |
| 5418 | goto error; |
| 5419 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5420 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 5421 | 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] | 5422 | cont->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 5423 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 5424 | goto error; |
| 5425 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5426 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5427 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5428 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5429 | /* last part - process data nodes */ |
| 5430 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5431 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5432 | node = read_yin_container(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5433 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5434 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5435 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5436 | node = read_yin_leaf(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5437 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5438 | node = read_yin_list(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5439 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5440 | node = read_yin_choice(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5441 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5442 | node = read_yin_uses(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5443 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5444 | node = read_yin_grouping(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5445 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5446 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5447 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5448 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5449 | } else if (!strcmp(sub->name, "action")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5450 | node = read_yin_rpc_action(module, retval, sub, options, unres); |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 5451 | } else if (!strcmp(sub->name, "notification")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5452 | node = read_yin_notif(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5453 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5454 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5455 | goto error; |
| 5456 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5457 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5458 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5459 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5460 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5461 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5462 | if (cont->when || cont->must) { |
| 5463 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 5464 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5465 | goto error; |
| 5466 | } |
| 5467 | } else { |
| 5468 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 5469 | goto error; |
| 5470 | } |
| 5471 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5472 | } |
| 5473 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5474 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5475 | |
| 5476 | error: |
| 5477 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5478 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5479 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5480 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5481 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5482 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5483 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5484 | } |
| 5485 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5486 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5487 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5488 | 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] | 5489 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5490 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5491 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5492 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5493 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5494 | struct lys_node_grp *grp; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5495 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5496 | int c_tpdf = 0, c_ext = 0; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 5497 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5498 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5499 | /* init */ |
| 5500 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5501 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5502 | grp = calloc(1, sizeof *grp); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5503 | LY_CHECK_ERR_RETURN(!grp, LOGMEM, NULL); |
| 5504 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5505 | grp->nodetype = LYS_GROUPING; |
| 5506 | grp->prev = (struct lys_node *)grp; |
| 5507 | retval = (struct lys_node *)grp; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5508 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5509 | 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] | 5510 | goto error; |
| 5511 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5512 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 5513 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5514 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5515 | /* insert the node into the schema tree */ |
| 5516 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5517 | goto error; |
| 5518 | } |
| 5519 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5520 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5521 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5522 | /* extension */ |
| 5523 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5524 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5525 | /* data statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5526 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5527 | !strcmp(sub->name, "leaf-list") || |
| 5528 | !strcmp(sub->name, "leaf") || |
| 5529 | !strcmp(sub->name, "list") || |
| 5530 | !strcmp(sub->name, "choice") || |
| 5531 | !strcmp(sub->name, "uses") || |
| 5532 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5533 | !strcmp(sub->name, "anyxml") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 5534 | !strcmp(sub->name, "anydata") || |
Michal Vasko | 5acb548 | 2016-09-16 14:35:14 +0200 | [diff] [blame] | 5535 | !strcmp(sub->name, "action") || |
| 5536 | !strcmp(sub->name, "notification")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5537 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5538 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5539 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5540 | /* array counters */ |
| 5541 | } else if (!strcmp(sub->name, "typedef")) { |
| 5542 | c_tpdf++; |
| 5543 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5544 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5545 | goto error; |
| 5546 | } |
| 5547 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5548 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5549 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5550 | if (c_tpdf) { |
| 5551 | grp->tpdf = calloc(c_tpdf, sizeof *grp->tpdf); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5552 | LY_CHECK_ERR_GOTO(!grp->tpdf, LOGMEM, error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5553 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5554 | if (c_ext) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 5555 | /* some extensions may be already present from the substatements */ |
| 5556 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5557 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 5558 | retval->ext = reallocated; |
| 5559 | |
| 5560 | /* init memory */ |
| 5561 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5562 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5563 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5564 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5565 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5566 | 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] | 5567 | retval->ext_size++; |
| 5568 | if (r) { |
| 5569 | goto error; |
| 5570 | } |
| 5571 | } else { |
| 5572 | /* typedef */ |
| 5573 | r = fill_yin_typedef(module, retval, sub, &grp->tpdf[grp->tpdf_size], unres); |
| 5574 | grp->tpdf_size++; |
| 5575 | if (r) { |
| 5576 | goto error; |
| 5577 | } |
| 5578 | } |
| 5579 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5580 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5581 | /* last part - process data nodes */ |
Michal Vasko | 919dbbc | 2016-05-19 15:22:45 +0200 | [diff] [blame] | 5582 | if (!root.child) { |
| 5583 | LOGWRN("Grouping \"%s\" without children.", retval->name); |
| 5584 | } |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5585 | options |= LYS_PARSE_OPT_INGRP; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5586 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5587 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5588 | node = read_yin_container(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5589 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5590 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5591 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5592 | node = read_yin_leaf(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5593 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5594 | node = read_yin_list(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5595 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5596 | node = read_yin_choice(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5597 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5598 | node = read_yin_uses(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5599 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5600 | node = read_yin_grouping(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5601 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5602 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5603 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5604 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5605 | } else if (!strcmp(sub->name, "action")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5606 | node = read_yin_rpc_action(module, retval, sub, options, unres); |
Michal Vasko | 5acb548 | 2016-09-16 14:35:14 +0200 | [diff] [blame] | 5607 | } else if (!strcmp(sub->name, "notification")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5608 | node = read_yin_notif(module, retval, sub, options, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5609 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5610 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5611 | goto error; |
| 5612 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5613 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5614 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5615 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5616 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5617 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5618 | |
| 5619 | error: |
| 5620 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5621 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5622 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5623 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5624 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5625 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5626 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5627 | } |
| 5628 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5629 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5630 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5631 | 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] | 5632 | int options, struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5633 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5634 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5635 | struct lys_node *node = NULL; |
Radek Krejci | 31fc30d | 2015-08-13 08:27:38 +0200 | [diff] [blame] | 5636 | struct lys_node *retval = NULL; |
Michal Vasko | 44fb638 | 2016-06-29 11:12:27 +0200 | [diff] [blame] | 5637 | struct lys_node_inout *inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5638 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5639 | int c_tpdf = 0, c_must = 0, c_ext = 0; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5640 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5641 | /* init */ |
| 5642 | memset(&root, 0, sizeof root); |
| 5643 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5644 | inout = calloc(1, sizeof *inout); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5645 | LY_CHECK_ERR_RETURN(!inout, LOGMEM, NULL); |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 5646 | inout->prev = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5647 | |
| 5648 | if (!strcmp(yin->name, "input")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5649 | inout->nodetype = LYS_INPUT; |
Michal Vasko | 0a1aaa4 | 2016-04-19 09:48:25 +0200 | [diff] [blame] | 5650 | inout->name = lydict_insert(module->ctx, "input", 0); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5651 | } else if (!strcmp(yin->name, "output")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5652 | inout->nodetype = LYS_OUTPUT; |
Michal Vasko | 0a1aaa4 | 2016-04-19 09:48:25 +0200 | [diff] [blame] | 5653 | inout->name = lydict_insert(module->ctx, "output", 0); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5654 | } else { |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 5655 | LOGINT; |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 5656 | free(inout); |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 5657 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5658 | } |
| 5659 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5660 | retval = (struct lys_node *)inout; |
Radek Krejci | e777089 | 2017-01-24 13:18:01 +0100 | [diff] [blame] | 5661 | retval->module = module; |
Michal Vasko | ebeac94 | 2015-06-15 12:11:50 +0200 | [diff] [blame] | 5662 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 5663 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5664 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5665 | /* insert the node into the schema tree */ |
| 5666 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5667 | goto error; |
| 5668 | } |
| 5669 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5670 | /* data statements */ |
| 5671 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e777089 | 2017-01-24 13:18:01 +0100 | [diff] [blame] | 5672 | if (!sub->ns) { |
| 5673 | /* garbage */ |
| 5674 | lyxml_free(module->ctx, sub); |
| 5675 | } else if (strcmp(sub->ns->value, LY_NSYIN)) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5676 | /* extension */ |
| 5677 | c_ext++; |
| 5678 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5679 | !strcmp(sub->name, "leaf-list") || |
| 5680 | !strcmp(sub->name, "leaf") || |
| 5681 | !strcmp(sub->name, "list") || |
| 5682 | !strcmp(sub->name, "choice") || |
| 5683 | !strcmp(sub->name, "uses") || |
| 5684 | !strcmp(sub->name, "grouping") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 5685 | !strcmp(sub->name, "anyxml") || |
| 5686 | !strcmp(sub->name, "anydata")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5687 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5688 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5689 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5690 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5691 | } else if (!strcmp(sub->name, "typedef")) { |
| 5692 | c_tpdf++; |
Radek Krejci | d2bfa79 | 2015-07-02 16:45:29 +0200 | [diff] [blame] | 5693 | |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 5694 | } else if ((module->version >= 2) && !strcmp(sub->name, "must")) { |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5695 | c_must++; |
| 5696 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5697 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5698 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5699 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5700 | } |
| 5701 | } |
| 5702 | |
| 5703 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5704 | if (c_tpdf) { |
| 5705 | inout->tpdf = calloc(c_tpdf, sizeof *inout->tpdf); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5706 | LY_CHECK_ERR_GOTO(!inout->tpdf, LOGMEM, error); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5707 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5708 | if (c_must) { |
| 5709 | inout->must = calloc(c_must, sizeof *inout->must); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5710 | LY_CHECK_ERR_GOTO(!inout->must, LOGMEM, error); |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5711 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5712 | if (c_ext) { |
| 5713 | inout->ext = calloc(c_ext, sizeof *inout->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5714 | LY_CHECK_ERR_GOTO(!inout->ext, LOGMEM, error); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5715 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5716 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5717 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5718 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5719 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5720 | 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] | 5721 | retval->ext_size++; |
| 5722 | if (r) { |
| 5723 | goto error; |
| 5724 | } |
| 5725 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5726 | r = fill_yin_must(module, sub, &inout->must[inout->must_size], unres); |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5727 | inout->must_size++; |
| 5728 | if (r) { |
| 5729 | goto error; |
| 5730 | } |
| 5731 | } else { /* typedef */ |
| 5732 | r = fill_yin_typedef(module, retval, sub, &inout->tpdf[inout->tpdf_size], unres); |
| 5733 | inout->tpdf_size++; |
| 5734 | if (r) { |
| 5735 | goto error; |
| 5736 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5737 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5738 | } |
| 5739 | |
| 5740 | /* last part - process data nodes */ |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5741 | options |= LYS_PARSE_OPT_CFG_IGNORE; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5742 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5743 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5744 | node = read_yin_container(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5745 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5746 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5747 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5748 | node = read_yin_leaf(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5749 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5750 | node = read_yin_list(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5751 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5752 | node = read_yin_choice(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5753 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5754 | node = read_yin_uses(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5755 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5756 | node = read_yin_grouping(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5757 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5758 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5759 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5760 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5761 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5762 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5763 | goto error; |
| 5764 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5765 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5766 | lyxml_free(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5767 | } |
| 5768 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5769 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5770 | if (inout->must) { |
| 5771 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 5772 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5773 | goto error; |
| 5774 | } |
| 5775 | } else { |
| 5776 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 5777 | goto error; |
| 5778 | } |
| 5779 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5780 | } |
| 5781 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5782 | return retval; |
| 5783 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5784 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5785 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5786 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 5787 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5788 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5789 | } |
| 5790 | |
| 5791 | return NULL; |
| 5792 | } |
| 5793 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5794 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5795 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5796 | 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] | 5797 | int options, struct unres_schema *unres) |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5798 | { |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 5799 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5800 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5801 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5802 | struct lys_node_notif *notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5803 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5804 | 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] | 5805 | void *reallocated; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5806 | |
Michal Vasko | 6bb7fc1 | 2016-09-21 14:17:22 +0200 | [diff] [blame] | 5807 | if (parent && (module->version < 2)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5808 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, parent, "notification"); |
Michal Vasko | 6bb7fc1 | 2016-09-21 14:17:22 +0200 | [diff] [blame] | 5809 | return NULL; |
| 5810 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5811 | |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 5812 | memset(&root, 0, sizeof root); |
| 5813 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5814 | notif = calloc(1, sizeof *notif); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5815 | LY_CHECK_ERR_RETURN(!notif, LOGMEM, NULL); |
| 5816 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5817 | notif->nodetype = LYS_NOTIF; |
| 5818 | notif->prev = (struct lys_node *)notif; |
| 5819 | retval = (struct lys_node *)notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5820 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 5821 | 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] | 5822 | goto error; |
| 5823 | } |
| 5824 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 5825 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5826 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5827 | /* insert the node into the schema tree */ |
| 5828 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5829 | goto error; |
| 5830 | } |
| 5831 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5832 | /* process rpc's specific children */ |
| 5833 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5834 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5835 | /* extension */ |
| 5836 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5837 | continue; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5838 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5839 | /* data statements */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5840 | } else if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5841 | !strcmp(sub->name, "leaf-list") || |
| 5842 | !strcmp(sub->name, "leaf") || |
| 5843 | !strcmp(sub->name, "list") || |
| 5844 | !strcmp(sub->name, "choice") || |
| 5845 | !strcmp(sub->name, "uses") || |
| 5846 | !strcmp(sub->name, "grouping") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 5847 | !strcmp(sub->name, "anyxml") || |
| 5848 | !strcmp(sub->name, "anydata")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5849 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5850 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5851 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5852 | /* array counters */ |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5853 | } else if (!strcmp(sub->name, "typedef")) { |
| 5854 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5855 | } else if (!strcmp(sub->name, "if-feature")) { |
| 5856 | c_ftrs++; |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 5857 | } else if ((module->version >= 2) && !strcmp(sub->name, "must")) { |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5858 | c_must++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5859 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5860 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5861 | goto error; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5862 | } |
| 5863 | } |
| 5864 | |
| 5865 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5866 | if (c_tpdf) { |
| 5867 | notif->tpdf = calloc(c_tpdf, sizeof *notif->tpdf); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5868 | LY_CHECK_ERR_GOTO(!notif->tpdf, LOGMEM, error); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5869 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5870 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5871 | notif->iffeature = calloc(c_ftrs, sizeof *notif->iffeature); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5872 | LY_CHECK_ERR_GOTO(!notif->iffeature, LOGMEM, error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5873 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5874 | if (c_must) { |
| 5875 | notif->must = calloc(c_must, sizeof *notif->must); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5876 | LY_CHECK_ERR_GOTO(!notif->must, LOGMEM, error); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5877 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5878 | if (c_ext) { |
Radek Krejci | 478ef1d | 2017-01-24 13:56:09 +0100 | [diff] [blame] | 5879 | /* some extensions may be already present from the substatements */ |
| 5880 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 5881 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | 478ef1d | 2017-01-24 13:56:09 +0100 | [diff] [blame] | 5882 | retval->ext = reallocated; |
| 5883 | |
| 5884 | /* init memory */ |
| 5885 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5886 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5887 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5888 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 5889 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 5890 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 5891 | 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] | 5892 | retval->ext_size++; |
| 5893 | if (r) { |
| 5894 | goto error; |
| 5895 | } |
| 5896 | } else if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5897 | r = fill_yin_typedef(module, retval, sub, ¬if->tpdf[notif->tpdf_size], unres); |
| 5898 | notif->tpdf_size++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5899 | if (r) { |
| 5900 | goto error; |
| 5901 | } |
Radek Krejci | 9629915 | 2016-06-22 10:17:50 +0200 | [diff] [blame] | 5902 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 5903 | 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] | 5904 | notif->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 5905 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 5906 | goto error; |
| 5907 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5908 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | fccd144 | 2017-01-16 10:26:57 +0100 | [diff] [blame] | 5909 | r = fill_yin_must(module, sub, ¬if->must[notif->must_size], unres); |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 5910 | notif->must_size++; |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 5911 | if (r) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5912 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5913 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5914 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5915 | } |
| 5916 | |
| 5917 | /* last part - process data nodes */ |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5918 | options |= LYS_PARSE_OPT_CFG_IGNORE; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5919 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5920 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5921 | node = read_yin_container(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5922 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5923 | node = read_yin_leaflist(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5924 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5925 | node = read_yin_leaf(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5926 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5927 | node = read_yin_list(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5928 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5929 | node = read_yin_choice(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5930 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5931 | node = read_yin_uses(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5932 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5933 | node = read_yin_grouping(module, retval, sub, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5934 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5935 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, options, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5936 | } else if (!strcmp(sub->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 5937 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, options, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5938 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5939 | if (!node) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5940 | goto error; |
| 5941 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5942 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5943 | lyxml_free(module->ctx, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5944 | } |
| 5945 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5946 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5947 | if (notif->must) { |
| 5948 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 5949 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 5950 | goto error; |
| 5951 | } |
| 5952 | } else { |
| 5953 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 5954 | goto error; |
| 5955 | } |
| 5956 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5957 | } |
| 5958 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5959 | return retval; |
| 5960 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5961 | error: |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5962 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5963 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5964 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5965 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 5966 | } |
| 5967 | |
| 5968 | return NULL; |
| 5969 | } |
| 5970 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5971 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5972 | static struct lys_node * |
Michal Vasko | e022a56 | 2016-09-27 14:24:15 +0200 | [diff] [blame] | 5973 | 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] | 5974 | int options, struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5975 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5976 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5977 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5978 | struct lys_node *retval; |
Michal Vasko | 44fb638 | 2016-06-29 11:12:27 +0200 | [diff] [blame] | 5979 | struct lys_node_rpc_action *rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5980 | int r; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 5981 | 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] | 5982 | void *reallocated; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5983 | |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5984 | if (!strcmp(yin->name, "action")) { |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 5985 | if (module->version < 2) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5986 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, parent, "action"); |
Michal Vasko | bb17485 | 2016-07-25 11:00:21 +0200 | [diff] [blame] | 5987 | return NULL; |
| 5988 | } |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5989 | for (node = parent; node; node = lys_parent(node)) { |
Radek Krejci | a3b19f7 | 2016-09-30 13:02:45 +0200 | [diff] [blame] | 5990 | if ((node->nodetype & (LYS_RPC | LYS_ACTION | LYS_NOTIF)) |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5991 | || ((node->nodetype == LYS_LIST) && !((struct lys_node_list *)node)->keys_size)) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 5992 | LOGVAL(LYE_INPAR, LY_VLOG_LYS, parent, strnodetype(node->nodetype), "action"); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5993 | return NULL; |
| 5994 | } |
| 5995 | } |
| 5996 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5997 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5998 | /* init */ |
| 5999 | memset(&root, 0, sizeof root); |
| 6000 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6001 | rpc = calloc(1, sizeof *rpc); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6002 | LY_CHECK_ERR_RETURN(!rpc, LOGMEM, NULL); |
| 6003 | |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6004 | rpc->nodetype = (!strcmp(yin->name, "rpc") ? LYS_RPC : LYS_ACTION); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6005 | rpc->prev = (struct lys_node *)rpc; |
| 6006 | retval = (struct lys_node *)rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6007 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 6008 | 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] | 6009 | goto error; |
| 6010 | } |
| 6011 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 6012 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6013 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 6014 | /* insert the node into the schema tree */ |
| 6015 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 6016 | goto error; |
| 6017 | } |
| 6018 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6019 | /* process rpc's specific children */ |
| 6020 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6021 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6022 | /* extension */ |
| 6023 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6024 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6025 | } else if (!strcmp(sub->name, "input")) { |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6026 | if (c_input) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6027 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6028 | goto error; |
| 6029 | } |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6030 | c_input++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 6031 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 6032 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6033 | } else if (!strcmp(sub->name, "output")) { |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6034 | if (c_output) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6035 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6036 | goto error; |
| 6037 | } |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 6038 | c_output++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 6039 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 6040 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6041 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6042 | /* data statements */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6043 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 6044 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 6045 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6046 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6047 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6048 | } else if (!strcmp(sub->name, "typedef")) { |
| 6049 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6050 | } else if (!strcmp(sub->name, "if-feature")) { |
| 6051 | c_ftrs++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6052 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6053 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6054 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6055 | } |
| 6056 | } |
| 6057 | |
| 6058 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 6059 | if (c_tpdf) { |
| 6060 | rpc->tpdf = calloc(c_tpdf, sizeof *rpc->tpdf); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6061 | LY_CHECK_ERR_GOTO(!rpc->tpdf, LOGMEM, error); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6062 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6063 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 6064 | rpc->iffeature = calloc(c_ftrs, sizeof *rpc->iffeature); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6065 | LY_CHECK_ERR_GOTO(!rpc->iffeature, LOGMEM, error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6066 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6067 | if (c_ext) { |
Radek Krejci | 94596cf | 2017-01-24 13:19:16 +0100 | [diff] [blame] | 6068 | /* some extensions may be already present from the substatements */ |
| 6069 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6070 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | 94596cf | 2017-01-24 13:19:16 +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 | 38d01f7 | 2015-06-15 09:41:06 +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, &rpc->tpdf[rpc->tpdf_size], unres); |
| 6087 | rpc->tpdf_size++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6088 | if (r) { |
| 6089 | goto error; |
| 6090 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37: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, &rpc->iffeature[rpc->iffeature_size], unres); |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 6093 | rpc->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 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6097 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6098 | } |
| 6099 | |
| 6100 | /* last part - process data nodes */ |
| 6101 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 6102 | if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6103 | node = read_yin_grouping(module, retval, sub, options, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 6104 | } else if (!strcmp(sub->name, "input") || !strcmp(sub->name, "output")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6105 | node = read_yin_input_output(module, retval, sub, options, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6106 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6107 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6108 | goto error; |
| 6109 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 6110 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6111 | lyxml_free(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6112 | } |
| 6113 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6114 | return retval; |
| 6115 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6116 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6117 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 6118 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 6119 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6120 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6121 | } |
| 6122 | |
| 6123 | return NULL; |
| 6124 | } |
| 6125 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 6126 | /* logs directly |
| 6127 | * |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6128 | * resolve - referenced grouping should be bounded to the namespace (resolved) |
| 6129 | * only when uses does not appear in grouping. In a case of grouping's uses, |
| 6130 | * we just get information but we do not apply augment or refine to it. |
| 6131 | */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6132 | static struct lys_node * |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6133 | read_yin_uses(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
| 6134 | int options, struct unres_schema *unres) |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6135 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6136 | struct lyxml_elem *sub, *next; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6137 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 6138 | struct lys_node_uses *uses; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6139 | const char *value; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6140 | 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] | 6141 | int r; |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 6142 | void *reallocated; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6143 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6144 | uses = calloc(1, sizeof *uses); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6145 | LY_CHECK_ERR_RETURN(!uses, LOGMEM, NULL); |
| 6146 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 6147 | uses->nodetype = LYS_USES; |
| 6148 | uses->prev = (struct lys_node *)uses; |
| 6149 | retval = (struct lys_node *)uses; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6150 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6151 | GETVAL(value, yin, "name"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6152 | uses->name = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 6153 | |
Radek Krejci | 07d0fb9 | 2017-01-13 14:11:05 +0100 | [diff] [blame] | 6154 | 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] | 6155 | goto error; |
| 6156 | } |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6157 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 6158 | LOGDBG(LY_LDGYIN, "parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6159 | |
Radek Krejci | c189a95 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 6160 | /* insert the node into the schema tree */ |
| 6161 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 6162 | goto error; |
| 6163 | } |
| 6164 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6165 | /* get other properties of uses */ |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 6166 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6167 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6168 | /* extension */ |
| 6169 | c_ext++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6170 | continue; |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6171 | } else if (!strcmp(sub->name, "refine")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6172 | c_ref++; |
| 6173 | } else if (!strcmp(sub->name, "augment")) { |
| 6174 | c_aug++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6175 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 56e8977 | 2015-06-19 10:00:54 +0200 | [diff] [blame] | 6176 | c_ftrs++; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6177 | } else if (!strcmp(sub->name, "when")) { |
| 6178 | if (uses->when) { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6179 | LOGVAL(LYE_TOOMANY, LY_VLOG_LYS, retval, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6180 | goto error; |
| 6181 | } |
| 6182 | |
Radek Krejci | 5323b49 | 2017-01-16 15:40:11 +0100 | [diff] [blame] | 6183 | uses->when = read_yin_when(module, sub, unres); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6184 | if (!uses->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6185 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 6186 | goto error; |
| 6187 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6188 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6189 | } else { |
Radek Krejci | 6f3d631 | 2016-11-04 17:23:18 +0100 | [diff] [blame] | 6190 | LOGVAL(LYE_INSTMT, LY_VLOG_LYS, retval, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6191 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6192 | } |
| 6193 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 6194 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6195 | /* process properties with cardinality 0..n */ |
| 6196 | if (c_ref) { |
| 6197 | uses->refine = calloc(c_ref, sizeof *uses->refine); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6198 | LY_CHECK_ERR_GOTO(!uses->refine, LOGMEM, error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6199 | } |
| 6200 | if (c_aug) { |
| 6201 | uses->augment = calloc(c_aug, sizeof *uses->augment); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6202 | LY_CHECK_ERR_GOTO(!uses->augment, LOGMEM, error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6203 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6204 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 6205 | uses->iffeature = calloc(c_ftrs, sizeof *uses->iffeature); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6206 | LY_CHECK_ERR_GOTO(!uses->iffeature, LOGMEM, error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6207 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6208 | if (c_ext) { |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 6209 | /* some extensions may be already present from the substatements */ |
| 6210 | reallocated = realloc(retval->ext, (c_ext + retval->ext_size) * sizeof *retval->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6211 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | fdc0d70 | 2017-01-23 15:58:38 +0100 | [diff] [blame] | 6212 | retval->ext = reallocated; |
| 6213 | |
| 6214 | /* init memory */ |
| 6215 | memset(&retval->ext[retval->ext_size], 0, c_ext * sizeof *retval->ext); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6216 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 6217 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6218 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
| 6219 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 6220 | /* extension */ |
Radek Krejci | 2b999ac | 2017-01-18 16:22:12 +0100 | [diff] [blame] | 6221 | 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] | 6222 | retval->ext_size++; |
| 6223 | if (r) { |
| 6224 | goto error; |
| 6225 | } |
| 6226 | } else if (!strcmp(sub->name, "refine")) { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 6227 | r = fill_yin_refine(retval, sub, &uses->refine[uses->refine_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 6228 | uses->refine_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 6229 | if (r) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6230 | goto error; |
| 6231 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 6232 | } else if (!strcmp(sub->name, "augment")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6233 | 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] | 6234 | uses->augment_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 6235 | if (r) { |
| 6236 | goto error; |
| 6237 | } |
| 6238 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 9de2c04 | 2016-10-19 16:53:06 +0200 | [diff] [blame] | 6239 | 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] | 6240 | uses->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 6241 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 6242 | goto error; |
| 6243 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6244 | } |
| 6245 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 6246 | |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6247 | if (unres_schema_add_node(module, unres, uses, UNRES_USES, NULL) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 6248 | goto error; |
| 6249 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6250 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 6251 | /* check XPath dependencies */ |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 6252 | if (uses->when) { |
| 6253 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 6254 | if (lyxp_node_check_syntax(retval)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 6255 | goto error; |
| 6256 | } |
| 6257 | } else { |
| 6258 | if (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1) { |
| 6259 | goto error; |
| 6260 | } |
| 6261 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 6262 | } |
| 6263 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6264 | return retval; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6265 | |
| 6266 | error: |
| 6267 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 6268 | lys_node_free(retval, NULL, 0); |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6269 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6270 | return NULL; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 6271 | } |
| 6272 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 6273 | /* logs directly |
| 6274 | * |
| 6275 | * common code for yin_read_module() and yin_read_submodule() |
| 6276 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6277 | static int |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6278 | read_sub_module(struct lys_module *module, struct lys_submodule *submodule, struct lyxml_elem *yin, |
| 6279 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6280 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6281 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 6282 | struct lyxml_elem *next, *child, root, grps, augs, revs, exts; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6283 | struct lys_node *node = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6284 | struct lys_module *trg; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6285 | const char *value; |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6286 | int i, r, ret = -1; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6287 | int version_flag = 0; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6288 | /* (sub)module substatements are ordered in groups, increment this value when moving to another group |
| 6289 | * 0 - header-stmts, 1 - linkage-stmts, 2 - meta-stmts, 3 - revision-stmts, 4 - body-stmts */ |
| 6290 | int substmt_group; |
| 6291 | /* just remember last substatement for logging */ |
| 6292 | const char *substmt_prev; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6293 | /* counters */ |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6294 | 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; |
| 6295 | int c_ext = 0, c_extinst = 0; |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6296 | void *reallocated; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6297 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6298 | /* to simplify code, store the module/submodule being processed as trg */ |
Michal Vasko | fe7e5a7 | 2016-05-02 14:49:23 +0200 | [diff] [blame] | 6299 | trg = submodule ? (struct lys_module *)submodule : module; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6300 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6301 | /* init */ |
| 6302 | memset(&root, 0, sizeof root); |
| 6303 | memset(&grps, 0, sizeof grps); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6304 | memset(&augs, 0, sizeof augs); |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6305 | memset(&exts, 0, sizeof exts); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6306 | memset(&revs, 0, sizeof revs); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 6307 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6308 | /* |
| 6309 | * in the first run, we process elements with cardinality of 1 or 0..1 and |
| 6310 | * count elements with cardinality 0..n. Data elements (choices, containers, |
| 6311 | * leafs, lists, leaf-lists) are moved aside to be processed last, since we |
| 6312 | * need have all top-level and groupings already prepared at that time. In |
| 6313 | * the middle loop, we process other elements with carinality of 0..n since |
| 6314 | * we need to allocate arrays to store them. |
| 6315 | */ |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6316 | substmt_group = 0; |
| 6317 | substmt_prev = NULL; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6318 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6319 | if (!child->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 6320 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6321 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6322 | continue; |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame] | 6323 | } else if (strcmp(child->ns->value, LY_NSYIN)) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6324 | /* possible extension instance */ |
| 6325 | lyxml_unlink_elem(module->ctx, child, 2); |
| 6326 | lyxml_add_child(module->ctx, &exts, child); |
| 6327 | c_extinst++; |
| 6328 | } else if (!submodule && !strcmp(child->name, "namespace")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6329 | if (substmt_group > 0) { |
| 6330 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6331 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6332 | child->name, substmt_prev); |
| 6333 | goto error; |
| 6334 | } |
| 6335 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6336 | if (trg->ns) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6337 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6338 | goto error; |
| 6339 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6340 | GETVAL(value, child, "uri"); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6341 | trg->ns = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6342 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6343 | 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] | 6344 | goto error; |
| 6345 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6346 | lyxml_free(ctx, child); |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6347 | |
| 6348 | substmt_prev = "namespace"; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6349 | } else if (!submodule && !strcmp(child->name, "prefix")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6350 | if (substmt_group > 0) { |
| 6351 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6352 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6353 | child->name, substmt_prev); |
| 6354 | goto error; |
| 6355 | } |
| 6356 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6357 | if (trg->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6358 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6359 | goto error; |
| 6360 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6361 | GETVAL(value, child, "value"); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6362 | if (lyp_check_identifier(value, LY_IDENT_PREFIX, trg, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6363 | goto error; |
| 6364 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6365 | trg->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 6366 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6367 | 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] | 6368 | goto error; |
| 6369 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6370 | lyxml_free(ctx, child); |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6371 | |
| 6372 | substmt_prev = "prefix"; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6373 | } else if (submodule && !strcmp(child->name, "belongs-to")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6374 | if (substmt_group > 0) { |
| 6375 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6376 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6377 | child->name, substmt_prev); |
| 6378 | goto error; |
| 6379 | } |
| 6380 | |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame] | 6381 | if (trg->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6382 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6383 | goto error; |
| 6384 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6385 | GETVAL(value, child, "module"); |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 6386 | if (!ly_strequal(value, submodule->belongsto->name, 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6387 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6388 | goto error; |
| 6389 | } |
Radek Krejci | f388693 | 2015-06-04 17:36:06 +0200 | [diff] [blame] | 6390 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6391 | 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] | 6392 | goto error; |
| 6393 | } |
| 6394 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6395 | /* get the prefix substatement, start with checks */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6396 | if (!child->child) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6397 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6398 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6399 | } else if (strcmp(child->child->name, "prefix")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6400 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6401 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6402 | } else if (child->child->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6403 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->child->next->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6404 | goto error; |
| 6405 | } |
| 6406 | /* and now finally get the value */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6407 | GETVAL(value, child->child, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6408 | /* check here differs from a generic prefix check, since this prefix |
| 6409 | * don't have to be unique |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6410 | */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6411 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6412 | goto error; |
| 6413 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6414 | submodule->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 0af1387 | 2015-05-30 11:50:52 +0200 | [diff] [blame] | 6415 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6416 | 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] | 6417 | goto error; |
| 6418 | } |
| 6419 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6420 | /* we are done with belongs-to */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6421 | lyxml_free(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6422 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6423 | substmt_prev = "belongs-to"; |
| 6424 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6425 | /* counters (statements with n..1 cardinality) */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6426 | } else if (!strcmp(child->name, "import")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6427 | if (substmt_group > 1) { |
| 6428 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6429 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6430 | child->name, substmt_prev); |
| 6431 | goto error; |
| 6432 | } |
| 6433 | substmt_group = 1; |
| 6434 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6435 | c_imp++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6436 | |
| 6437 | substmt_prev = "import"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6438 | } else if (!strcmp(child->name, "revision")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6439 | if (substmt_group > 3) { |
| 6440 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6441 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6442 | child->name, substmt_prev); |
| 6443 | goto error; |
| 6444 | } |
| 6445 | substmt_group = 3; |
| 6446 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6447 | c_rev++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6448 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6449 | lyxml_unlink_elem(ctx, child, 2); |
| 6450 | lyxml_add_child(ctx, &revs, child); |
| 6451 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6452 | substmt_prev = "revision"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6453 | } else if (!strcmp(child->name, "typedef")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6454 | substmt_group = 4; |
| 6455 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6456 | c_tpdf++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6457 | |
| 6458 | substmt_prev = "typedef"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6459 | } else if (!strcmp(child->name, "identity")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6460 | substmt_group = 4; |
| 6461 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6462 | c_ident++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6463 | |
| 6464 | substmt_prev = "identity"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6465 | } else if (!strcmp(child->name, "include")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6466 | if (substmt_group > 1) { |
| 6467 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6468 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6469 | child->name, substmt_prev); |
| 6470 | goto error; |
| 6471 | } |
| 6472 | substmt_group = 1; |
| 6473 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6474 | c_inc++; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6475 | |
| 6476 | substmt_prev = "include"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6477 | } else if (!strcmp(child->name, "augment")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6478 | substmt_group = 4; |
| 6479 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6480 | c_aug++; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6481 | /* keep augments separated, processed last */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6482 | lyxml_unlink_elem(ctx, child, 2); |
| 6483 | lyxml_add_child(ctx, &augs, child); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6484 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6485 | substmt_prev = "augment"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6486 | } else if (!strcmp(child->name, "feature")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6487 | substmt_group = 4; |
| 6488 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6489 | c_ftrs++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6490 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6491 | substmt_prev = "feature"; |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6492 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6493 | /* data statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6494 | } else if (!strcmp(child->name, "container") || |
| 6495 | !strcmp(child->name, "leaf-list") || |
| 6496 | !strcmp(child->name, "leaf") || |
| 6497 | !strcmp(child->name, "list") || |
| 6498 | !strcmp(child->name, "choice") || |
| 6499 | !strcmp(child->name, "uses") || |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6500 | !strcmp(child->name, "anyxml") || |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 6501 | !strcmp(child->name, "anydata") || |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6502 | !strcmp(child->name, "rpc") || |
| 6503 | !strcmp(child->name, "notification")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6504 | substmt_group = 4; |
| 6505 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6506 | lyxml_unlink_elem(ctx, child, 2); |
| 6507 | lyxml_add_child(ctx, &root, child); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6508 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6509 | substmt_prev = "data definition"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6510 | } else if (!strcmp(child->name, "grouping")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6511 | substmt_group = 4; |
| 6512 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6513 | /* keep groupings separated and process them before other data statements */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6514 | lyxml_unlink_elem(ctx, child, 2); |
| 6515 | lyxml_add_child(ctx, &grps, child); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6516 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6517 | substmt_prev = "grouping"; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6518 | /* optional statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6519 | } else if (!strcmp(child->name, "description")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6520 | if (substmt_group > 2) { |
| 6521 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6522 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6523 | child->name, substmt_prev); |
| 6524 | goto error; |
| 6525 | } |
| 6526 | substmt_group = 2; |
| 6527 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6528 | if (trg->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6529 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6530 | goto error; |
| 6531 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6532 | 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] | 6533 | goto error; |
| 6534 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6535 | trg->dsc = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6536 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6537 | if (!trg->dsc) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6538 | goto error; |
| 6539 | } |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6540 | |
| 6541 | substmt_prev = "description"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6542 | } else if (!strcmp(child->name, "reference")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6543 | if (substmt_group > 2) { |
| 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 | substmt_group = 2; |
| 6550 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6551 | if (trg->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6552 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6553 | goto error; |
| 6554 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6555 | 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] | 6556 | goto error; |
| 6557 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6558 | trg->ref = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6559 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6560 | if (!trg->ref) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6561 | goto error; |
| 6562 | } |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6563 | |
| 6564 | substmt_prev = "reference"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6565 | } else if (!strcmp(child->name, "organization")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6566 | if (substmt_group > 2) { |
| 6567 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6568 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6569 | child->name, substmt_prev); |
| 6570 | goto error; |
| 6571 | } |
| 6572 | substmt_group = 2; |
| 6573 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6574 | if (trg->org) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6575 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6576 | goto error; |
| 6577 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6578 | 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] | 6579 | goto error; |
| 6580 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6581 | trg->org = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6582 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6583 | if (!trg->org) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6584 | goto error; |
| 6585 | } |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6586 | |
| 6587 | substmt_prev = "organization"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6588 | } else if (!strcmp(child->name, "contact")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6589 | if (substmt_group > 2) { |
| 6590 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6591 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6592 | child->name, substmt_prev); |
| 6593 | goto error; |
| 6594 | } |
| 6595 | substmt_group = 2; |
| 6596 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6597 | if (trg->contact) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6598 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6599 | goto error; |
| 6600 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6601 | 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] | 6602 | goto error; |
| 6603 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6604 | trg->contact = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6605 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6606 | if (!trg->contact) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6607 | goto error; |
| 6608 | } |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6609 | |
| 6610 | substmt_prev = "contact"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6611 | } else if (!strcmp(child->name, "yang-version")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6612 | if (substmt_group > 0) { |
| 6613 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 6614 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Statement \"%s\" cannot appear after \"%s\" statement.", |
| 6615 | child->name, substmt_prev); |
| 6616 | goto error; |
| 6617 | } |
| 6618 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6619 | if (version_flag) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6620 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6621 | goto error; |
| 6622 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6623 | GETVAL(value, child, "value"); |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6624 | if (strcmp(value, "1") && strcmp(value, "1.1")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6625 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "yang-version"); |
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 | version_flag = 1; |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6629 | if (!strcmp(value, "1")) { |
| 6630 | if (submodule) { |
| 6631 | if (module->version > 1) { |
| 6632 | LOGVAL(LYE_INVER, LY_VLOG_NONE, NULL); |
| 6633 | goto error; |
| 6634 | } |
Radek Krejci | 29eac3d | 2017-06-01 16:50:02 +0200 | [diff] [blame] | 6635 | submodule->version = 1; |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6636 | } else { |
| 6637 | module->version = 1; |
| 6638 | } |
| 6639 | } else { |
| 6640 | if (submodule) { |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 6641 | if (module->version < 2) { |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6642 | LOGVAL(LYE_INVER, LY_VLOG_NONE, NULL); |
| 6643 | goto error; |
| 6644 | } |
Radek Krejci | 29eac3d | 2017-06-01 16:50:02 +0200 | [diff] [blame] | 6645 | submodule->version = 2; |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 6646 | } else { |
| 6647 | module->version = 2; |
| 6648 | } |
| 6649 | } |
| 6650 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 6651 | 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] | 6652 | goto error; |
| 6653 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6654 | lyxml_free(ctx, child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6655 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6656 | substmt_prev = "yang-version"; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6657 | } else if (!strcmp(child->name, "extension")) { |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6658 | substmt_group = 4; |
| 6659 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6660 | c_ext++; |
Radek Krejci | 5166a89 | 2015-07-02 16:44:24 +0200 | [diff] [blame] | 6661 | |
Michal Vasko | 5de8a02 | 2017-02-08 10:57:26 +0100 | [diff] [blame] | 6662 | substmt_prev = "extension"; |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6663 | } else if (!strcmp(child->name, "deviation")) { |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame] | 6664 | substmt_group = 4; |
| 6665 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6666 | c_dev++; |
| 6667 | |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame] | 6668 | substmt_prev = "deviation"; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6669 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6670 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6671 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6672 | } |
| 6673 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6674 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6675 | /* check for mandatory statements */ |
Radek Krejci | 6a1e2f4 | 2017-01-19 15:22:00 +0100 | [diff] [blame] | 6676 | if (submodule) { |
| 6677 | if (!submodule->prefix) { |
| 6678 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "belongs-to", "submodule"); |
| 6679 | goto error; |
| 6680 | } |
| 6681 | if (!version_flag) { |
| 6682 | /* check version compatibility with the main module */ |
| 6683 | if (module->version > 1) { |
| 6684 | LOGVAL(LYE_INVER, LY_VLOG_NONE, NULL); |
| 6685 | goto error; |
| 6686 | } |
| 6687 | } |
| 6688 | } else { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6689 | if (!trg->ns) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6690 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "namespace", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6691 | goto error; |
| 6692 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6693 | if (!trg->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6694 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6695 | goto error; |
| 6696 | } |
| 6697 | } |
Radek Krejci | bb3257d | 2015-05-21 23:03:51 +0200 | [diff] [blame] | 6698 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6699 | /* allocate arrays for elements with cardinality of 0..n */ |
| 6700 | if (c_imp) { |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 6701 | trg->imp = calloc(c_imp, sizeof *trg->imp); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6702 | LY_CHECK_ERR_GOTO(!trg->imp, LOGMEM, error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6703 | } |
| 6704 | if (c_rev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6705 | trg->rev = calloc(c_rev, sizeof *trg->rev); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6706 | LY_CHECK_ERR_GOTO(!trg->rev, LOGMEM, error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6707 | } |
| 6708 | if (c_tpdf) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6709 | trg->tpdf = calloc(c_tpdf, sizeof *trg->tpdf); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6710 | LY_CHECK_ERR_GOTO(!trg->tpdf, LOGMEM, error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6711 | } |
| 6712 | if (c_ident) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6713 | trg->ident = calloc(c_ident, sizeof *trg->ident); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6714 | LY_CHECK_ERR_GOTO(!trg->ident, LOGMEM, error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6715 | } |
| 6716 | if (c_inc) { |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 6717 | trg->inc = calloc(c_inc, sizeof *trg->inc); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6718 | LY_CHECK_ERR_GOTO(!trg->inc, LOGMEM, error); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6719 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6720 | if (c_aug) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6721 | trg->augment = calloc(c_aug, sizeof *trg->augment); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6722 | LY_CHECK_ERR_GOTO(!trg->augment, LOGMEM, error); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6723 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6724 | if (c_ftrs) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6725 | trg->features = calloc(c_ftrs, sizeof *trg->features); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6726 | LY_CHECK_ERR_GOTO(!trg->features, LOGMEM, error); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6727 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6728 | if (c_dev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6729 | trg->deviation = calloc(c_dev, sizeof *trg->deviation); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6730 | LY_CHECK_ERR_GOTO(!trg->deviation, LOGMEM, error); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6731 | } |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6732 | if (c_ext) { |
| 6733 | trg->extensions = calloc(c_ext, sizeof *trg->extensions); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6734 | LY_CHECK_ERR_GOTO(!trg->extensions, LOGMEM, error); |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6735 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6736 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6737 | /* middle part 1 - process revision and then check whether this (sub)module was not already parsed, add it there */ |
| 6738 | LY_TREE_FOR_SAFE(revs.child, next, child) { |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 6739 | r = fill_yin_revision(trg, child, &trg->rev[trg->rev_size], unres); |
| 6740 | trg->rev_size++; |
| 6741 | if (r) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6742 | goto error; |
| 6743 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6744 | |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 6745 | /* check uniqueness of the revision date - not required by RFC */ |
| 6746 | for (i = 0; i < (trg->rev_size - 1); i++) { |
| 6747 | if (!strcmp(trg->rev[i].date, trg->rev[trg->rev_size - 1].date)) { |
| 6748 | LOGWRN("Module's revisions are not unique (%s).", trg->rev[trg->rev_size - 1].date); |
| 6749 | break; |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6750 | } |
| 6751 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6752 | |
| 6753 | lyxml_free(ctx, child); |
| 6754 | } |
| 6755 | |
| 6756 | /* check the module with respect to the context now */ |
| 6757 | if (!submodule) { |
| 6758 | switch (lyp_ctx_check_module(module)) { |
| 6759 | case -1: |
| 6760 | goto error; |
| 6761 | case 0: |
| 6762 | break; |
| 6763 | case 1: |
| 6764 | /* it's already there */ |
| 6765 | ret = 1; |
| 6766 | goto error; |
| 6767 | } |
| 6768 | } |
| 6769 | |
| 6770 | /* 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] | 6771 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6772 | if (!strcmp(child->name, "import")) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6773 | r = fill_yin_import(trg, child, &trg->imp[trg->imp_size], unres); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6774 | trg->imp_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6775 | if (r) { |
| 6776 | goto error; |
| 6777 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 6778 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6779 | } else if (!strcmp(child->name, "include")) { |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 6780 | r = fill_yin_include(module, submodule, child, &trg->inc[trg->inc_size], unres); |
| 6781 | trg->inc_size++; |
| 6782 | if (r) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6783 | goto error; |
| 6784 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 6785 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6786 | } else if (!strcmp(child->name, "typedef")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6787 | r = fill_yin_typedef(trg, NULL, child, &trg->tpdf[trg->tpdf_size], unres); |
| 6788 | trg->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6789 | if (r) { |
| 6790 | goto error; |
| 6791 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6792 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6793 | } else if (!strcmp(child->name, "identity")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6794 | r = fill_yin_identity(trg, child, &trg->ident[trg->ident_size], unres); |
| 6795 | trg->ident_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6796 | if (r) { |
| 6797 | goto error; |
| 6798 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6799 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6800 | } else if (!strcmp(child->name, "feature")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6801 | r = fill_yin_feature(trg, child, &trg->features[trg->features_size], unres); |
| 6802 | trg->features_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 6803 | if (r) { |
| 6804 | goto error; |
| 6805 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6806 | |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6807 | } else if (!strcmp(child->name, "extension")) { |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6808 | r = fill_yin_extension(trg, child, &trg->extensions[trg->extensions_size], unres); |
Radek Krejci | a1a6b76 | 2016-11-14 09:53:38 +0900 | [diff] [blame] | 6809 | trg->extensions_size++; |
| 6810 | if (r) { |
| 6811 | goto error; |
| 6812 | } |
| 6813 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6814 | } else if (!strcmp(child->name, "deviation")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6815 | r = fill_yin_deviation(trg, child, &trg->deviation[trg->deviation_size], unres); |
| 6816 | trg->deviation_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 6817 | if (r) { |
| 6818 | goto error; |
| 6819 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6820 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6821 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6822 | |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6823 | /* process extension instances */ |
Radek Krejci | 8ee9480 | 2017-02-10 12:38:40 +0100 | [diff] [blame] | 6824 | if (c_extinst) { |
| 6825 | /* some extensions may be already present from the substatements */ |
| 6826 | reallocated = realloc(trg->ext, (c_extinst + trg->ext_size) * sizeof *trg->ext); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6827 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); |
Radek Krejci | 8ee9480 | 2017-02-10 12:38:40 +0100 | [diff] [blame] | 6828 | trg->ext = reallocated; |
| 6829 | |
| 6830 | /* init memory */ |
| 6831 | memset(&trg->ext[trg->ext_size], 0, c_extinst * sizeof *trg->ext); |
| 6832 | |
| 6833 | LY_TREE_FOR_SAFE(exts.child, next, child) { |
| 6834 | r = lyp_yin_fill_ext(trg, LYEXT_PAR_MODULE, 0, 0, trg, child, &trg->ext, trg->ext_size, unres); |
| 6835 | trg->ext_size++; |
| 6836 | if (r) { |
| 6837 | goto error; |
| 6838 | } |
| 6839 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6840 | } |
| 6841 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6842 | /* process data nodes. Start with groupings to allow uses |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6843 | * refer to them. Submodule's data nodes are stored in the |
| 6844 | * main module data tree. |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6845 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6846 | LY_TREE_FOR_SAFE(grps.child, next, child) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6847 | node = read_yin_grouping(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6848 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6849 | goto error; |
| 6850 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6851 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6852 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6853 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 6854 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6855 | /* parse data nodes, ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6856 | LY_TREE_FOR_SAFE(root.child, next, child) { |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 6857 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6858 | if (!strcmp(child->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6859 | node = read_yin_container(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6860 | } else if (!strcmp(child->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6861 | node = read_yin_leaflist(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6862 | } else if (!strcmp(child->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6863 | node = read_yin_leaf(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6864 | } else if (!strcmp(child->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6865 | node = read_yin_list(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6866 | } else if (!strcmp(child->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6867 | node = read_yin_choice(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6868 | } else if (!strcmp(child->name, "uses")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6869 | node = read_yin_uses(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6870 | } else if (!strcmp(child->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6871 | node = read_yin_anydata(trg, NULL, child, LYS_ANYXML, 0, unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 6872 | } else if (!strcmp(child->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6873 | node = read_yin_anydata(trg, NULL, child, LYS_ANYDATA, 0, unres); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6874 | } else if (!strcmp(child->name, "rpc")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6875 | node = read_yin_rpc_action(trg, NULL, child, 0, unres); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 6876 | } else if (!strcmp(child->name, "notification")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6877 | node = read_yin_notif(trg, NULL, child, 0, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6878 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 6879 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6880 | goto error; |
| 6881 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 6882 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6883 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6884 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6885 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6886 | /* ... and finally augments (last, so we can augment our data, for instance) */ |
| 6887 | LY_TREE_FOR_SAFE(augs.child, next, child) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 6888 | 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] | 6889 | trg->augment_size++; |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6890 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6891 | if (r) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6892 | goto error; |
| 6893 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6894 | lyxml_free(ctx, child); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 6895 | } |
| 6896 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6897 | return 0; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6898 | |
| 6899 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6900 | while (root.child) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6901 | lyxml_free(ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6902 | } |
| 6903 | while (grps.child) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6904 | lyxml_free(ctx, grps.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6905 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 6906 | while (augs.child) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6907 | lyxml_free(ctx, augs.child); |
| 6908 | } |
| 6909 | while (revs.child) { |
| 6910 | lyxml_free(ctx, revs.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 6911 | } |
Radek Krejci | e534c13 | 2016-11-23 13:32:31 +0100 | [diff] [blame] | 6912 | while (exts.child) { |
| 6913 | lyxml_free(module->ctx, exts.child); |
| 6914 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6915 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6916 | return ret; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6917 | } |
| 6918 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 6919 | /* logs directly */ |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6920 | struct lys_submodule * |
| 6921 | 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] | 6922 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6923 | struct lyxml_elem *yin; |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6924 | struct lys_submodule *submodule = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6925 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6926 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6927 | assert(module->ctx); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6928 | |
Radek Krejci | e1bacd7 | 2017-03-01 13:18:46 +0100 | [diff] [blame] | 6929 | yin = lyxml_parse_mem(module->ctx, data, LYXML_PARSE_NOMIXEDCONTENT); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6930 | if (!yin) { |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6931 | return NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6932 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6933 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6934 | /* check root element */ |
| 6935 | if (!yin->name || strcmp(yin->name, "submodule")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6936 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6937 | goto error; |
| 6938 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6939 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6940 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 6941 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6942 | goto error; |
| 6943 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6944 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6945 | submodule = calloc(1, sizeof *submodule); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 6946 | LY_CHECK_ERR_GOTO(!submodule, LOGMEM, error); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6947 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6948 | submodule->ctx = module->ctx; |
| 6949 | submodule->name = lydict_insert(submodule->ctx, value, strlen(value)); |
| 6950 | submodule->type = 1; |
Radek Krejci | 29eac3d | 2017-06-01 16:50:02 +0200 | [diff] [blame] | 6951 | submodule->implemented = module->implemented; |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6952 | submodule->belongsto = module; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6953 | |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 6954 | /* add into the list of processed modules */ |
| 6955 | if (lyp_check_circmod_add((struct lys_module *)submodule)) { |
| 6956 | goto error; |
| 6957 | } |
| 6958 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6959 | LOGVRB("Reading submodule \"%s\".", submodule->name); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 6960 | /* module cannot be changed in this case and 1 cannot be returned */ |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6961 | if (read_sub_module(module, submodule, yin, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6962 | goto error; |
| 6963 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6964 | |
Radek Krejci | 33fc477 | 2017-01-26 16:00:35 +0100 | [diff] [blame] | 6965 | lyp_sort_revisions((struct lys_module *)submodule); |
| 6966 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6967 | /* cleanup */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6968 | lyxml_free(module->ctx, yin); |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 6969 | lyp_check_circmod_pop(module->ctx); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6970 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6971 | LOGVRB("Submodule \"%s\" successfully parsed.", submodule->name); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6972 | return submodule; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6973 | |
| 6974 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6975 | /* cleanup */ |
Michal Vasko | 44ab146 | 2017-05-18 13:18:36 +0200 | [diff] [blame] | 6976 | unres_schema_free((struct lys_module *)submodule, &unres, 0); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 6977 | lyxml_free(module->ctx, yin); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 6978 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6979 | if (!submodule) { |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 6980 | LOGERR(ly_errno, "Submodule parsing failed."); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6981 | return NULL; |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 6982 | } |
| 6983 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6984 | LOGERR(ly_errno, "Submodule \"%s\" parsing failed.", submodule->name); |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 6985 | |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 6986 | lyp_check_circmod_pop(module->ctx); |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 6987 | lys_sub_module_remove_devs_augs((struct lys_module *)submodule); |
| 6988 | lys_submodule_module_data_free(submodule); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6989 | lys_submodule_free(submodule, NULL); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 6990 | return NULL; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 6991 | } |
| 6992 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 6993 | /* logs directly */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 6994 | struct lys_module * |
Radek Krejci | 37f9ba3 | 2017-02-10 16:50:35 +0100 | [diff] [blame] | 6995 | 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] | 6996 | { |
Pavol Vican | c99b59e | 2016-03-22 15:46:39 +0100 | [diff] [blame] | 6997 | struct lys_module *module = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 6998 | struct unres_schema *unres; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 6999 | const char *value; |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7000 | int ret; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7001 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7002 | unres = calloc(1, sizeof *unres); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7003 | LY_CHECK_ERR_RETURN(!unres, LOGMEM, NULL); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7004 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7005 | /* check root element */ |
| 7006 | if (!yin->name || strcmp(yin->name, "module")) { |
Radek Krejci | 9a909bd | 2016-10-24 15:45:51 +0200 | [diff] [blame] | 7007 | if (ly_strequal("submodule", yin->name, 0)) { |
Radek Krejci | 48cfa0f | 2016-11-08 19:18:34 +0100 | [diff] [blame] | 7008 | LOGVAL(LYE_SUBMODULE, LY_VLOG_NONE, NULL); |
| 7009 | } else { |
| 7010 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, yin->name); |
Radek Krejci | 9a909bd | 2016-10-24 15:45:51 +0200 | [diff] [blame] | 7011 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7012 | goto error; |
| 7013 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7014 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7015 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 7016 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7017 | goto error; |
| 7018 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7019 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7020 | module = calloc(1, sizeof *module); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7021 | LY_CHECK_ERR_GOTO(!module, LOGMEM, error); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7022 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7023 | module->ctx = ctx; |
| 7024 | module->name = lydict_insert(ctx, value, strlen(value)); |
| 7025 | module->type = 0; |
Michal Vasko | d8aa32d | 2015-07-24 11:50:01 +0200 | [diff] [blame] | 7026 | module->implemented = (implement ? 1 : 0); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7027 | |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 7028 | /* add into the list of processed modules */ |
| 7029 | if (lyp_check_circmod_add(module)) { |
| 7030 | goto error; |
| 7031 | } |
| 7032 | |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 7033 | LOGVRB("Reading module \"%s\".", module->name); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7034 | ret = read_sub_module(module, NULL, yin, unres); |
| 7035 | if (ret == -1) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 7036 | goto error; |
| 7037 | } |
| 7038 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7039 | if (ret == 1) { |
| 7040 | assert(!unres->count); |
| 7041 | } else { |
| 7042 | /* resolve rest of unres items */ |
| 7043 | if (unres->count && resolve_unres_schema(module, unres)) { |
| 7044 | goto error; |
| 7045 | } |
| 7046 | |
| 7047 | /* check correctness of includes */ |
| 7048 | if (lyp_check_include_missing(module)) { |
| 7049 | goto error; |
| 7050 | } |
Michal Vasko | 7b460e5 | 2017-02-10 14:50:26 +0100 | [diff] [blame] | 7051 | |
| 7052 | /* remove our submodules from the parsed submodules list */ |
| 7053 | lyp_del_includedup(module); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7054 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 7055 | |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 7056 | lyp_sort_revisions(module); |
Radek Krejci | 6bd2c02 | 2017-02-01 15:04:49 +0100 | [diff] [blame] | 7057 | |
| 7058 | if (lyp_rfn_apply_ext(module) || lyp_deviation_apply_ext(module)) { |
| 7059 | goto error; |
| 7060 | } |
Radek Krejci | 95f22ae | 2017-01-20 14:25:53 +0100 | [diff] [blame] | 7061 | |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 7062 | if (revision) { |
| 7063 | /* check revision of the parsed model */ |
| 7064 | if (!module->rev_size || strcmp(revision, module->rev[0].date)) { |
Michal Vasko | b24e788 | 2016-03-21 16:13:25 +0100 | [diff] [blame] | 7065 | LOGVRB("Module \"%s\" parsed with the wrong revision (\"%s\" instead \"%s\").", |
| 7066 | module->name, module->rev[0].date, revision); |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 7067 | goto error; |
| 7068 | } |
| 7069 | } |
| 7070 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7071 | /* add into context if not already there */ |
| 7072 | if (!ret) { |
| 7073 | if (module->deviation_size && !module->implemented) { |
| 7074 | LOGVRB("Module \"%s\" includes deviations, changing its conformance to \"implement\".", module->name); |
| 7075 | /* deviations always causes target to be made implemented, |
| 7076 | * but augents and leafrefs not, so we have to apply them now */ |
| 7077 | if (lys_set_implemented(module)) { |
| 7078 | goto error; |
| 7079 | } |
| 7080 | } |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 7081 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7082 | if (lyp_ctx_add_module(module)) { |
Michal Vasko | 2605575 | 2016-05-03 11:36:31 +0200 | [diff] [blame] | 7083 | goto error; |
| 7084 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7085 | } else { |
| 7086 | /* free what was parsed */ |
| 7087 | lys_free(module, NULL, 0); |
| 7088 | |
| 7089 | /* get the model from the context */ |
Radek Krejci | dfb00d6 | 2017-09-06 09:39:35 +0200 | [diff] [blame^] | 7090 | module = (struct lys_module *)ly_ctx_get_module(ctx, value, revision, 0); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 7091 | assert(module); |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 7092 | } |
| 7093 | |
Michal Vasko | 44ab146 | 2017-05-18 13:18:36 +0200 | [diff] [blame] | 7094 | unres_schema_free(NULL, &unres, 0); |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 7095 | lyp_check_circmod_pop(ctx); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 7096 | LOGVRB("Module \"%s\" successfully parsed.", module->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7097 | return module; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7098 | |
| 7099 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7100 | /* cleanup */ |
Michal Vasko | 44ab146 | 2017-05-18 13:18:36 +0200 | [diff] [blame] | 7101 | unres_schema_free(module, &unres, 1); |
Radek Krejci | b8c07b8 | 2016-02-12 11:11:55 +0100 | [diff] [blame] | 7102 | |
| 7103 | if (!module) { |
Radek Krejci | 48cfa0f | 2016-11-08 19:18:34 +0100 | [diff] [blame] | 7104 | if (ly_vecode != LYVE_SUBMODULE) { |
| 7105 | LOGERR(ly_errno, "Module parsing failed."); |
| 7106 | } |
Radek Krejci | b8c07b8 | 2016-02-12 11:11:55 +0100 | [diff] [blame] | 7107 | return NULL; |
| 7108 | } |
| 7109 | |
| 7110 | LOGERR(ly_errno, "Module \"%s\" parsing failed.", module->name); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7111 | |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 7112 | lyp_check_circmod_pop(ctx); |
Michal Vasko | cf0489e | 2017-02-13 11:57:45 +0100 | [diff] [blame] | 7113 | lyp_del_includedup(module); |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 7114 | lys_sub_module_remove_devs_augs(module); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 7115 | lys_free(module, NULL, 1); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 7116 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 7117 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7118 | |
Radek Krejci | 37f9ba3 | 2017-02-10 16:50:35 +0100 | [diff] [blame] | 7119 | /* logs directly */ |
| 7120 | struct lys_module * |
| 7121 | yin_read_module(struct ly_ctx *ctx, const char *data, const char *revision, int implement) |
| 7122 | { |
| 7123 | struct lyxml_elem *yin; |
| 7124 | struct lys_module *result; |
| 7125 | |
Radek Krejci | e1bacd7 | 2017-03-01 13:18:46 +0100 | [diff] [blame] | 7126 | yin = lyxml_parse_mem(ctx, data, LYXML_PARSE_NOMIXEDCONTENT); |
Radek Krejci | 37f9ba3 | 2017-02-10 16:50:35 +0100 | [diff] [blame] | 7127 | if (!yin) { |
| 7128 | LOGERR(ly_errno, "Module parsing failed."); |
| 7129 | return NULL; |
| 7130 | } |
| 7131 | |
| 7132 | result = yin_read_module_(ctx, yin, revision, implement); |
| 7133 | |
| 7134 | lyxml_free(ctx, yin); |
| 7135 | |
| 7136 | return result; |
| 7137 | } |
| 7138 | |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7139 | static int |
| 7140 | yin_parse_extcomplex_bool(struct lys_module *mod, struct lyxml_elem *node, |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7141 | struct lys_ext_instance_complex *ext, LY_STMT stmt, |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7142 | const char *true_val, const char *false_val, struct unres_schema *unres) |
| 7143 | { |
| 7144 | uint8_t *val; |
| 7145 | const char *str; |
| 7146 | struct lyext_substmt *info; |
| 7147 | |
| 7148 | val = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7149 | if (!val) { |
| 7150 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7151 | return EXIT_FAILURE; |
| 7152 | } |
| 7153 | if (*val) { |
| 7154 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7155 | return EXIT_FAILURE; |
| 7156 | } |
| 7157 | |
Radek Krejci | db35f17 | 2017-02-27 11:03:01 +0100 | [diff] [blame] | 7158 | 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] | 7159 | return EXIT_FAILURE; |
| 7160 | } |
| 7161 | |
| 7162 | str = lyxml_get_attr(node, "value", NULL); |
| 7163 | if (!str) { |
| 7164 | LOGVAL(LYE_MISSARG, LY_VLOG_NONE, NULL, "value", node->name); |
| 7165 | } else if (true_val && !strcmp(true_val, str)) { |
| 7166 | /* true value */ |
| 7167 | *val = 1; |
| 7168 | } else if (false_val && !strcmp(false_val, str)) { |
| 7169 | /* false value */ |
| 7170 | *val = 2; |
| 7171 | } else { |
| 7172 | /* unknown value */ |
| 7173 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, str, node->name); |
| 7174 | return EXIT_FAILURE; |
| 7175 | } |
| 7176 | |
| 7177 | return EXIT_SUCCESS; |
| 7178 | } |
| 7179 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7180 | /* |
| 7181 | * argelem - 1 if the value is stored in a standalone YIN element, 0 if stored as attribute |
| 7182 | * argname - name of the element/attribute where the value is stored |
| 7183 | */ |
| 7184 | static int |
| 7185 | yin_parse_extcomplex_str(struct lys_module *mod, struct lyxml_elem *node, |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7186 | struct lys_ext_instance_complex *ext, LY_STMT stmt, |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7187 | int argelem, const char *argname, struct unres_schema *unres) |
| 7188 | { |
| 7189 | int c; |
PavolVican | 99c7072 | 2017-02-18 17:25:52 +0100 | [diff] [blame] | 7190 | const char **str, ***p = NULL, *value; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7191 | void *reallocated; |
| 7192 | struct lyext_substmt *info; |
| 7193 | |
| 7194 | str = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7195 | if (!str) { |
| 7196 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7197 | return EXIT_FAILURE; |
| 7198 | } |
| 7199 | if (info->cardinality < LY_STMT_CARD_SOME && *str) { |
| 7200 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7201 | return EXIT_FAILURE; |
| 7202 | } |
| 7203 | |
| 7204 | c = 0; |
| 7205 | if (info->cardinality >= LY_STMT_CARD_SOME) { |
| 7206 | /* there can be multiple instances, str is actually const char *** */ |
| 7207 | p = (const char ***)str; |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7208 | if (!p[0]) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7209 | /* allocate initial array */ |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7210 | p[0] = malloc(2 * sizeof(const char *)); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7211 | LY_CHECK_ERR_RETURN(!p[0], LOGMEM, EXIT_FAILURE); |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7212 | if (stmt == LY_STMT_BELONGSTO) { |
| 7213 | /* allocate another array for the belongs-to's prefixes */ |
| 7214 | p[1] = malloc(2 * sizeof(const char *)); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7215 | LY_CHECK_ERR_RETURN(!p[1], LOGMEM, EXIT_FAILURE); |
PavolVican | 99c7072 | 2017-02-18 17:25:52 +0100 | [diff] [blame] | 7216 | } else if (stmt == LY_STMT_ARGUMENT) { |
| 7217 | /* allocate another array for the yin element */ |
PavolVican | 4b80d04 | 2017-02-23 14:30:27 +0100 | [diff] [blame] | 7218 | ((uint8_t **)p)[1] = malloc(2 * sizeof(uint8_t)); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7219 | LY_CHECK_ERR_RETURN(!p[1], LOGMEM, EXIT_FAILURE); |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7220 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7221 | } else { |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7222 | /* get the index in the array to add new item */ |
| 7223 | for (c = 0; p[0][c]; c++); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7224 | } |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7225 | str = p[0]; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7226 | } |
Radek Krejci | db35f17 | 2017-02-27 11:03:01 +0100 | [diff] [blame] | 7227 | 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] | 7228 | return EXIT_FAILURE; |
| 7229 | } |
| 7230 | |
| 7231 | if (argelem) { |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7232 | str[c] = read_yin_subnode(mod->ctx, node, argname); |
| 7233 | if (!str[c]) { |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7234 | return EXIT_FAILURE; |
| 7235 | } |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7236 | } else { |
| 7237 | str[c] = lyxml_get_attr(node, argname, NULL); |
| 7238 | if (!str[c]) { |
| 7239 | LOGVAL(LYE_MISSARG, LY_VLOG_NONE, NULL, argname, node->name); |
| 7240 | return EXIT_FAILURE; |
| 7241 | } else { |
| 7242 | str[c] = lydict_insert(mod->ctx, str[c], 0); |
| 7243 | } |
| 7244 | |
| 7245 | if (stmt == LY_STMT_BELONGSTO) { |
| 7246 | /* get the belongs-to's mandatory prefix substatement */ |
| 7247 | if (!node->child) { |
| 7248 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", node->name); |
| 7249 | return EXIT_FAILURE; |
| 7250 | } else if (strcmp(node->child->name, "prefix")) { |
| 7251 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->child->name); |
| 7252 | return EXIT_FAILURE; |
| 7253 | } else if (node->child->next) { |
| 7254 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->child->next->name); |
| 7255 | return EXIT_FAILURE; |
| 7256 | } |
| 7257 | /* and now finally get the value */ |
| 7258 | if (p) { |
| 7259 | str = p[1]; |
| 7260 | } else { |
| 7261 | str++; |
| 7262 | } |
| 7263 | str[c] = lyxml_get_attr(node->child, "value", ((void *)0)); |
| 7264 | if (!str[c]) { |
| 7265 | LOGVAL(LYE_MISSARG, LY_VLOG_NONE, NULL, "value", node->child->name); |
| 7266 | return EXIT_FAILURE; |
| 7267 | } |
| 7268 | str[c] = lydict_insert(mod->ctx, str[c], 0); |
| 7269 | |
PavolVican | 6d40087 | 2017-03-01 15:19:18 +0100 | [diff] [blame] | 7270 | 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] | 7271 | return EXIT_FAILURE; |
| 7272 | } |
PavolVican | 99c7072 | 2017-02-18 17:25:52 +0100 | [diff] [blame] | 7273 | } else if (stmt == LY_STMT_ARGUMENT) { |
| 7274 | str = (p) ? p[1] : str + 1; |
| 7275 | if (!node->child) { |
| 7276 | /* default value of yin element */ |
| 7277 | ((uint8_t *)str)[c] = 2; |
| 7278 | } else { |
| 7279 | /* get optional yin-element substatement */ |
| 7280 | if (strcmp(node->child->name, "yin-element")) { |
| 7281 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->child->name); |
| 7282 | return EXIT_FAILURE; |
| 7283 | } else if (node->child->next) { |
| 7284 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->child->next->name); |
| 7285 | return EXIT_FAILURE; |
| 7286 | } else { |
| 7287 | /* and now finally get the value */ |
| 7288 | value = lyxml_get_attr(node->child, "value", NULL); |
| 7289 | if (!value) { |
| 7290 | LOGVAL(LYE_MISSARG, LY_VLOG_NONE, NULL, "value", node->child->name); |
| 7291 | return EXIT_FAILURE; |
| 7292 | } |
| 7293 | if (ly_strequal(value, "true", 0)) { |
| 7294 | ((uint8_t *)str)[c] = 1; |
| 7295 | } else if (ly_strequal(value, "false", 0)) { |
| 7296 | ((uint8_t *)str)[c] = 2; |
| 7297 | } else { |
| 7298 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, str, node->name); |
| 7299 | return EXIT_FAILURE; |
| 7300 | } |
| 7301 | |
| 7302 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node->child, LYEXT_SUBSTMT_YINELEM, c, unres)) { |
| 7303 | return EXIT_FAILURE; |
| 7304 | } |
| 7305 | } |
| 7306 | } |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7307 | } |
| 7308 | } |
| 7309 | if (p) { |
| 7310 | /* enlarge the array(s) */ |
| 7311 | reallocated = realloc(p[0], (c + 2) * sizeof(const char *)); |
| 7312 | if (!reallocated) { |
| 7313 | LOGMEM; |
| 7314 | lydict_remove(mod->ctx, p[0][c]); |
| 7315 | p[0][c] = NULL; |
| 7316 | return EXIT_FAILURE; |
| 7317 | } |
| 7318 | p[0] = reallocated; |
| 7319 | p[0][c + 1] = NULL; |
| 7320 | |
| 7321 | if (stmt == LY_STMT_BELONGSTO) { |
| 7322 | /* enlarge the second belongs-to's array with prefixes */ |
| 7323 | reallocated = realloc(p[1], (c + 2) * sizeof(const char *)); |
| 7324 | if (!reallocated) { |
| 7325 | LOGMEM; |
| 7326 | lydict_remove(mod->ctx, p[1][c]); |
| 7327 | p[1][c] = NULL; |
| 7328 | return EXIT_FAILURE; |
| 7329 | } |
| 7330 | p[1] = reallocated; |
| 7331 | p[1][c + 1] = NULL; |
PavolVican | 99c7072 | 2017-02-18 17:25:52 +0100 | [diff] [blame] | 7332 | } else if (stmt == LY_STMT_ARGUMENT){ |
| 7333 | /* enlarge the second argument's array with yin element */ |
| 7334 | reallocated = realloc(p[1], (c + 2) * sizeof(uint8_t)); |
| 7335 | if (!reallocated) { |
| 7336 | LOGMEM; |
| 7337 | ((uint8_t *)p[1])[c] = 0; |
| 7338 | return EXIT_FAILURE; |
| 7339 | } |
| 7340 | p[1] = reallocated; |
| 7341 | ((uint8_t *)p[1])[c + 1] = 0; |
Radek Krejci | 56c8041 | 2017-02-09 10:44:16 +0100 | [diff] [blame] | 7342 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7343 | } |
| 7344 | |
| 7345 | return EXIT_SUCCESS; |
| 7346 | } |
| 7347 | |
| 7348 | static void * |
| 7349 | yin_getplace_for_extcomplex_flags(struct lyxml_elem *node, struct lys_ext_instance_complex *ext, LY_STMT stmt, |
| 7350 | uint16_t mask) |
| 7351 | { |
| 7352 | void *data; |
| 7353 | struct lyext_substmt *info; |
| 7354 | |
| 7355 | data = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7356 | if (!data) { |
| 7357 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7358 | return NULL; |
| 7359 | } |
| 7360 | if (info->cardinality < LY_STMT_CARD_SOME && ((*(uint16_t *)data) & mask)) { |
| 7361 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7362 | return NULL; |
| 7363 | } |
| 7364 | |
| 7365 | return data; |
| 7366 | } |
| 7367 | |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7368 | static int |
| 7369 | yin_parse_extcomplex_flag(struct lys_module *mod, struct lyxml_elem *node, |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7370 | struct lys_ext_instance_complex *ext, LY_STMT stmt, |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7371 | const char *val1_str, const char *val2_str, uint16_t mask, |
| 7372 | uint16_t val1, uint16_t val2, struct unres_schema *unres) |
| 7373 | { |
| 7374 | uint16_t *val; |
| 7375 | const char *str; |
| 7376 | |
| 7377 | val = yin_getplace_for_extcomplex_flags(node, ext, stmt, mask); |
| 7378 | if (!val) { |
| 7379 | return EXIT_FAILURE; |
| 7380 | } |
| 7381 | |
| 7382 | str = lyxml_get_attr(node, "value", NULL); |
| 7383 | if (!str) { |
| 7384 | LOGVAL(LYE_MISSARG, LY_VLOG_NONE, NULL, "value", node->name); |
| 7385 | } else if (!strcmp(val1_str, str)) { |
| 7386 | *val = *val | val1; |
| 7387 | } else if (!strcmp(val2_str, str)) { |
| 7388 | *val = *val | val2; |
| 7389 | } else { |
| 7390 | /* unknown value */ |
| 7391 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, str, node->name); |
| 7392 | return EXIT_FAILURE; |
| 7393 | } |
Radek Krejci | db35f17 | 2017-02-27 11:03:01 +0100 | [diff] [blame] | 7394 | 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] | 7395 | return EXIT_FAILURE; |
| 7396 | } |
| 7397 | return EXIT_SUCCESS; |
| 7398 | } |
| 7399 | |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 7400 | static struct lys_node ** |
| 7401 | yin_getplace_for_extcomplex_node(struct lyxml_elem *node, struct lys_ext_instance_complex *ext, LY_STMT stmt) |
| 7402 | { |
| 7403 | struct lyext_substmt *info; |
| 7404 | struct lys_node **snode, *siter; |
| 7405 | |
| 7406 | snode = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7407 | if (!snode) { |
| 7408 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7409 | return NULL; |
| 7410 | } |
| 7411 | if (info->cardinality < LY_STMT_CARD_SOME) { |
| 7412 | LY_TREE_FOR(*snode, siter) { |
| 7413 | if (stmt == lys_snode2stmt(siter->nodetype)) { |
| 7414 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7415 | return NULL; |
| 7416 | } |
| 7417 | } |
| 7418 | } |
| 7419 | |
| 7420 | return snode; |
| 7421 | } |
| 7422 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7423 | static void ** |
| 7424 | yin_getplace_for_extcomplex_struct(struct lyxml_elem *node, struct lys_ext_instance_complex *ext, LY_STMT stmt) |
| 7425 | { |
| 7426 | int c; |
| 7427 | void **data, ***p = NULL; |
| 7428 | void *reallocated; |
| 7429 | struct lyext_substmt *info; |
| 7430 | |
| 7431 | data = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 7432 | if (!data) { |
| 7433 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7434 | return NULL; |
| 7435 | } |
| 7436 | if (info->cardinality < LY_STMT_CARD_SOME && *data) { |
| 7437 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); |
| 7438 | return NULL; |
| 7439 | } |
| 7440 | |
| 7441 | c = 0; |
| 7442 | if (info->cardinality >= LY_STMT_CARD_SOME) { |
| 7443 | /* there can be multiple instances, so instead of pointer to array, |
| 7444 | * we have in data pointer to pointer to array */ |
| 7445 | p = (void ***)data; |
| 7446 | data = *p; |
| 7447 | if (!data) { |
| 7448 | /* allocate initial array */ |
| 7449 | *p = data = malloc(2 * sizeof(void *)); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7450 | LY_CHECK_ERR_RETURN(!data, LOGMEM, NULL); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7451 | } else { |
| 7452 | for (c = 0; *data; data++, c++); |
| 7453 | } |
| 7454 | } |
| 7455 | |
| 7456 | if (p) { |
| 7457 | /* enlarge the array */ |
| 7458 | reallocated = realloc(*p, (c + 2) * sizeof(void *)); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7459 | LY_CHECK_ERR_RETURN(!reallocated, LOGMEM, NULL); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7460 | *p = reallocated; |
| 7461 | data = *p; |
| 7462 | data[c + 1] = NULL; |
| 7463 | } |
| 7464 | |
| 7465 | return &data[c]; |
| 7466 | } |
| 7467 | |
| 7468 | int |
| 7469 | lyp_yin_parse_complex_ext(struct lys_module *mod, struct lys_ext_instance_complex *ext, struct lyxml_elem *yin, |
| 7470 | struct unres_schema *unres) |
| 7471 | { |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7472 | struct lyxml_elem *next, *node, *child; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7473 | struct lys_type **type; |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7474 | void **pp, *p, *reallocated; |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7475 | const char *value, *name; |
| 7476 | char *endptr, modifier; |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7477 | struct lyext_substmt *info; |
| 7478 | long int v; |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7479 | long long int ll; |
| 7480 | unsigned long u; |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 7481 | int i, j; |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7482 | |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7483 | #define YIN_STORE_VALUE(TYPE, FROM, TO) \ |
| 7484 | *(TYPE **)TO = malloc(sizeof(TYPE)); \ |
| 7485 | if (!*(TYPE **)TO) { LOGMEM; goto error; } \ |
| 7486 | (**(TYPE **)TO) = (TYPE)FROM; |
| 7487 | |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7488 | #define YIN_EXTCOMPLEX_GETPLACE(STMT, TYPE) \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7489 | p = lys_ext_complex_get_substmt(STMT, ext, &info); \ |
| 7490 | if (!p) { \ |
| 7491 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node->name, node->parent->name); \ |
| 7492 | goto error; \ |
| 7493 | } \ |
| 7494 | if (info->cardinality < LY_STMT_CARD_SOME && (*(TYPE*)p)) { \ |
| 7495 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, node->parent->name); \ |
| 7496 | goto error; \ |
| 7497 | } \ |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7498 | pp = NULL; i = 0; \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7499 | if (info->cardinality >= LY_STMT_CARD_SOME) { \ |
| 7500 | /* there can be multiple instances */ \ |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7501 | pp = p; \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7502 | if (!(*pp)) { \ |
| 7503 | *pp = malloc(2 * sizeof(TYPE)); /* allocate initial array */ \ |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7504 | LY_CHECK_ERR_GOTO(!*pp, LOGMEM, error); \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7505 | } else { \ |
| 7506 | for (i = 0; (*(TYPE**)pp)[i]; i++); \ |
| 7507 | } \ |
| 7508 | p = &(*(TYPE**)pp)[i]; \ |
| 7509 | } |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7510 | #define YIN_EXTCOMPLEX_ENLARGE(TYPE) \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7511 | if (pp) { \ |
| 7512 | /* enlarge the array */ \ |
| 7513 | reallocated = realloc(*pp, (i + 2) * sizeof(TYPE*)); \ |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7514 | LY_CHECK_ERR_GOTO(!reallocated, LOGMEM, error); \ |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7515 | *pp = reallocated; \ |
| 7516 | (*(TYPE**)pp)[i + 1] = 0; \ |
| 7517 | } |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7518 | #define YIN_EXTCOMPLEX_PARSE_SNODE(STMT, FUNC, ARGS...) \ |
| 7519 | pp = (void**)yin_getplace_for_extcomplex_node(node, ext, STMT); \ |
| 7520 | if (!pp) { goto error; } \ |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7521 | 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] | 7522 | #define YIN_EXTCOMPLEX_PARSE_RESTR(STMT) \ |
| 7523 | YIN_EXTCOMPLEX_GETPLACE(STMT, struct lys_restr*); \ |
| 7524 | GETVAL(value, node, "value"); \ |
| 7525 | *(struct lys_restr **)p = calloc(1, sizeof(struct lys_restr)); \ |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7526 | LY_CHECK_ERR_GOTO(!*(struct lys_restr **)p, LOGMEM, error); \ |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7527 | (*(struct lys_restr **)p)->expr = lydict_insert(mod->ctx, value, 0); \ |
| 7528 | if (read_restr_substmt(mod, *(struct lys_restr **)p, node, unres)) { \ |
| 7529 | goto error; \ |
| 7530 | } \ |
| 7531 | YIN_EXTCOMPLEX_ENLARGE(struct lys_restr*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7532 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7533 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 7534 | if (!node->ns) { |
| 7535 | /* garbage */ |
| 7536 | } else if (node->ns == yin->ns && (ext->flags & LYS_YINELEM) && ly_strequal(node->name, ext->def->argument, 1)) { |
| 7537 | /* we have the extension's argument */ |
| 7538 | if (ext->arg_value) { |
| 7539 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
| 7540 | goto error; |
| 7541 | } |
| 7542 | ext->arg_value = node->content; |
| 7543 | node->content = NULL; |
| 7544 | } else if (strcmp(node->ns->value, LY_NSYIN)) { |
| 7545 | /* extension */ |
| 7546 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_SELF, 0, unres)) { |
| 7547 | goto error; |
| 7548 | } |
| 7549 | } else if (!strcmp(node->name, "description")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7550 | 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] | 7551 | goto error; |
| 7552 | } |
| 7553 | } else if (!strcmp(node->name, "reference")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7554 | 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] | 7555 | goto error; |
| 7556 | } |
| 7557 | } else if (!strcmp(node->name, "units")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7558 | 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] | 7559 | goto error; |
| 7560 | } |
| 7561 | } else if (!strcmp(node->name, "type")) { |
| 7562 | type = (struct lys_type **)yin_getplace_for_extcomplex_struct(node, ext, LY_STMT_TYPE); |
| 7563 | if (!type) { |
| 7564 | goto error; |
| 7565 | } |
| 7566 | /* allocate type structure */ |
| 7567 | (*type) = calloc(1, sizeof **type); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7568 | LY_CHECK_ERR_GOTO(!*type, LOGMEM, error); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7569 | |
| 7570 | /* HACK for unres */ |
Radek Krejci | 63fc096 | 2017-02-15 13:20:18 +0100 | [diff] [blame] | 7571 | lyxml_unlink(mod->ctx, node); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7572 | (*type)->der = (struct lys_tpdf *)node; |
| 7573 | (*type)->parent = (struct lys_tpdf *)ext; |
| 7574 | |
| 7575 | if (unres_schema_add_node(mod, unres, *type, UNRES_TYPE_DER_EXT, NULL) == -1) { |
| 7576 | (*type)->der = NULL; |
| 7577 | goto error; |
| 7578 | } |
| 7579 | continue; /* skip lyxml_free() */ |
Radek Krejci | 63fc096 | 2017-02-15 13:20:18 +0100 | [diff] [blame] | 7580 | } else if (!strcmp(node->name, "typedef")) { |
| 7581 | pp = yin_getplace_for_extcomplex_struct(node, ext, LY_STMT_TYPEDEF); |
| 7582 | if (!pp) { |
| 7583 | goto error; |
| 7584 | } |
| 7585 | /* allocate typedef structure */ |
| 7586 | (*pp) = calloc(1, sizeof(struct lys_tpdf)); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7587 | LY_CHECK_ERR_GOTO(!*pp, LOGMEM, error); |
Radek Krejci | 63fc096 | 2017-02-15 13:20:18 +0100 | [diff] [blame] | 7588 | |
| 7589 | if (fill_yin_typedef(mod, (struct lys_node *)ext, node, *((struct lys_tpdf **)pp), unres)) { |
| 7590 | goto error; |
| 7591 | } |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7592 | } else if (!strcmp(node->name, "if-feature")) { |
| 7593 | pp = yin_getplace_for_extcomplex_struct(node, ext, LY_STMT_IFFEATURE); |
| 7594 | if (!pp) { |
| 7595 | goto error; |
| 7596 | } |
| 7597 | /* allocate iffeature structure */ |
| 7598 | (*pp) = calloc(1, sizeof(struct lys_iffeature)); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7599 | LY_CHECK_ERR_GOTO(!*pp, LOGMEM, error); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7600 | |
| 7601 | if (fill_yin_iffeature((struct lys_node *)ext, 0, node, *((struct lys_iffeature **)pp), unres)) { |
| 7602 | goto error; |
| 7603 | } |
| 7604 | } else if (!strcmp(node->name, "status")) { |
| 7605 | p = yin_getplace_for_extcomplex_flags(node, ext, LY_STMT_STATUS, LYS_STATUS_MASK); |
| 7606 | if (!p) { |
| 7607 | goto error; |
| 7608 | } |
| 7609 | |
| 7610 | GETVAL(value, node, "value"); |
| 7611 | if (!strcmp(value, "current")) { |
| 7612 | *(uint16_t*)p |= LYS_STATUS_CURR; |
| 7613 | } else if (!strcmp(value, "deprecated")) { |
| 7614 | *(uint16_t*)p |= LYS_STATUS_DEPRC; |
| 7615 | } else if (!strcmp(value, "obsolete")) { |
| 7616 | *(uint16_t*)p |= LYS_STATUS_OBSLT; |
| 7617 | } else { |
| 7618 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
| 7619 | goto error; |
| 7620 | } |
| 7621 | |
| 7622 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_STATUS, 0, unres)) { |
| 7623 | goto error; |
| 7624 | } |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7625 | } else if (!strcmp(node->name, "config")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7626 | 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] | 7627 | LYS_CONFIG_W | LYS_CONFIG_SET, LYS_CONFIG_R | LYS_CONFIG_SET, unres)) { |
| 7628 | goto error; |
| 7629 | } |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7630 | } else if (!strcmp(node->name, "argument")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7631 | 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] | 7632 | goto error; |
| 7633 | } |
| 7634 | } else if (!strcmp(node->name, "default")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7635 | 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] | 7636 | goto error; |
| 7637 | } |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7638 | } else if (!strcmp(node->name, "mandatory")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7639 | if (yin_parse_extcomplex_flag(mod, node, ext, LY_STMT_MANDATORY, |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7640 | "true", "false", LYS_MAND_MASK, LYS_MAND_TRUE, LYS_MAND_FALSE, unres)) { |
| 7641 | goto error; |
| 7642 | } |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7643 | } else if (!strcmp(node->name, "error-app-tag")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7644 | 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] | 7645 | goto error; |
| 7646 | } |
| 7647 | } else if (!strcmp(node->name, "error-message")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7648 | 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] | 7649 | goto error; |
| 7650 | } |
| 7651 | } else if (!strcmp(node->name, "prefix")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7652 | 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] | 7653 | goto error; |
| 7654 | } |
| 7655 | } else if (!strcmp(node->name, "namespace")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7656 | 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] | 7657 | goto error; |
| 7658 | } |
| 7659 | } else if (!strcmp(node->name, "presence")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7660 | 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] | 7661 | goto error; |
| 7662 | } |
| 7663 | } else if (!strcmp(node->name, "revision-date")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7664 | 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] | 7665 | goto error; |
| 7666 | } |
| 7667 | } else if (!strcmp(node->name, "key")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7668 | 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] | 7669 | goto error; |
| 7670 | } |
| 7671 | } else if (!strcmp(node->name, "base")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7672 | 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] | 7673 | goto error; |
| 7674 | } |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7675 | } else if (!strcmp(node->name, "ordered-by")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7676 | if (yin_parse_extcomplex_flag(mod, node, ext, LY_STMT_ORDEREDBY, |
| 7677 | "user", "system", LYS_USERORDERED, LYS_USERORDERED, 0, unres)) { |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7678 | goto error; |
| 7679 | } |
Radek Krejci | 83ac2cd | 2017-02-06 14:59:47 +0100 | [diff] [blame] | 7680 | } else if (!strcmp(node->name, "belongs-to")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7681 | 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] | 7682 | goto error; |
| 7683 | } |
| 7684 | } else if (!strcmp(node->name, "contact")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7685 | 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] | 7686 | goto error; |
| 7687 | } |
| 7688 | } else if (!strcmp(node->name, "organization")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7689 | 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] | 7690 | goto error; |
| 7691 | } |
| 7692 | } else if (!strcmp(node->name, "path")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7693 | 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] | 7694 | goto error; |
| 7695 | } |
Radek Krejci | c188595 | 2017-02-07 09:37:51 +0100 | [diff] [blame] | 7696 | } else if (!strcmp(node->name, "require-instance")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7697 | 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] | 7698 | goto error; |
| 7699 | } |
| 7700 | } else if (!strcmp(node->name, "modifier")) { |
Radek Krejci | be33639 | 2017-02-07 10:54:24 +0100 | [diff] [blame] | 7701 | 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] | 7702 | goto error; |
| 7703 | } |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7704 | } else if (!strcmp(node->name, "fraction-digits")) { |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7705 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_DIGITS, uint8_t); |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7706 | |
| 7707 | GETVAL(value, node, "value"); |
| 7708 | v = strtol(value, NULL, 10); |
| 7709 | |
| 7710 | /* range check */ |
| 7711 | if (v < 1 || v > 18) { |
| 7712 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
| 7713 | goto error; |
| 7714 | } |
| 7715 | |
| 7716 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_STATUS, i, unres)) { |
| 7717 | goto error; |
| 7718 | } |
| 7719 | |
| 7720 | /* store the value */ |
| 7721 | (*(uint8_t *)p) = (uint8_t)v; |
| 7722 | |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7723 | YIN_EXTCOMPLEX_ENLARGE(uint8_t); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7724 | } else if (!strcmp(node->name, "max-elements")) { |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7725 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_MAX, uint32_t*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7726 | |
| 7727 | GETVAL(value, node, "value"); |
| 7728 | while (isspace(value[0])) { |
| 7729 | value++; |
| 7730 | } |
| 7731 | |
| 7732 | if (!strcmp(value, "unbounded")) { |
| 7733 | u = 0; |
| 7734 | } else { |
| 7735 | /* convert it to uint32_t */ |
| 7736 | errno = 0; endptr = NULL; |
| 7737 | u = strtoul(value, &endptr, 10); |
| 7738 | if (*endptr || value[0] == '-' || errno || u == 0 || u > UINT32_MAX) { |
| 7739 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7740 | goto error; |
| 7741 | } |
Radek Krejci | 3a14dfd | 2017-02-07 13:27:33 +0100 | [diff] [blame] | 7742 | } |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7743 | |
| 7744 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_MAX, i, unres)) { |
| 7745 | goto error; |
| 7746 | } |
| 7747 | |
| 7748 | /* store the value */ |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7749 | YIN_STORE_VALUE(uint32_t, u, p) |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7750 | |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7751 | YIN_EXTCOMPLEX_ENLARGE(uint32_t*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7752 | } else if (!strcmp(node->name, "min-elements")) { |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7753 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_MIN, uint32_t*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7754 | |
| 7755 | GETVAL(value, node, "value"); |
| 7756 | while (isspace(value[0])) { |
| 7757 | value++; |
| 7758 | } |
| 7759 | |
| 7760 | /* convert it to uint32_t */ |
| 7761 | errno = 0; |
| 7762 | endptr = NULL; |
| 7763 | u = strtoul(value, &endptr, 10); |
| 7764 | if (*endptr || value[0] == '-' || errno || u > UINT32_MAX) { |
| 7765 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
| 7766 | goto error; |
| 7767 | } |
| 7768 | |
| 7769 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_MAX, i, unres)) { |
| 7770 | goto error; |
| 7771 | } |
| 7772 | |
| 7773 | /* store the value */ |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7774 | YIN_STORE_VALUE(uint32_t, u, p) |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7775 | |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7776 | YIN_EXTCOMPLEX_ENLARGE(uint32_t*); |
Radek Krejci | 06a9aa0 | 2017-02-17 10:50:24 +0100 | [diff] [blame] | 7777 | } else if (!strcmp(node->name, "value")) { |
PavolVican | 2ed9f4e | 2017-02-16 00:08:45 +0100 | [diff] [blame] | 7778 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_VALUE, int32_t*); |
| 7779 | |
| 7780 | GETVAL(value, node, "value"); |
| 7781 | while (isspace(value[0])) { |
| 7782 | value++; |
| 7783 | } |
| 7784 | |
| 7785 | /* convert it to int32_t */ |
Radek Krejci | 9326fc0 | 2017-02-16 09:57:40 +0100 | [diff] [blame] | 7786 | ll = strtoll(value, NULL, 10); |
PavolVican | 2ed9f4e | 2017-02-16 00:08:45 +0100 | [diff] [blame] | 7787 | |
| 7788 | /* range check */ |
Radek Krejci | 9326fc0 | 2017-02-16 09:57:40 +0100 | [diff] [blame] | 7789 | if (ll < INT32_MIN || ll > INT32_MAX) { |
PavolVican | 2ed9f4e | 2017-02-16 00:08:45 +0100 | [diff] [blame] | 7790 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
| 7791 | goto error; |
| 7792 | } |
| 7793 | |
| 7794 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_VALUE, i, unres)) { |
| 7795 | goto error; |
| 7796 | } |
| 7797 | |
| 7798 | /* store the value */ |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7799 | YIN_STORE_VALUE(int32_t, ll, p) |
PavolVican | 2ed9f4e | 2017-02-16 00:08:45 +0100 | [diff] [blame] | 7800 | |
| 7801 | YIN_EXTCOMPLEX_ENLARGE(int32_t*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7802 | } else if (!strcmp(node->name, "position")) { |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7803 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_POSITION, uint32_t*); |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7804 | |
| 7805 | GETVAL(value, node, "value"); |
| 7806 | ll = strtoll(value, NULL, 10); |
| 7807 | |
| 7808 | /* range check */ |
| 7809 | if (ll < 0 || ll > UINT32_MAX) { |
| 7810 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
| 7811 | goto error; |
| 7812 | } |
| 7813 | |
| 7814 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_POSITION, i, unres)) { |
| 7815 | goto error; |
| 7816 | } |
| 7817 | |
| 7818 | /* store the value */ |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7819 | YIN_STORE_VALUE(uint32_t, ll, p) |
Radek Krejci | 5496fae | 2017-02-10 13:26:48 +0100 | [diff] [blame] | 7820 | |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7821 | YIN_EXTCOMPLEX_ENLARGE(uint32_t*); |
Radek Krejci | 37f9ba3 | 2017-02-10 16:50:35 +0100 | [diff] [blame] | 7822 | } else if (!strcmp(node->name, "module")) { |
| 7823 | pp = yin_getplace_for_extcomplex_struct(node, ext, LY_STMT_MODULE); |
| 7824 | if (!pp) { |
| 7825 | goto error; |
| 7826 | } |
| 7827 | |
| 7828 | *(struct lys_module **)pp = yin_read_module_(mod->ctx, node, NULL, mod->implemented); |
| 7829 | if (!(*pp)) { |
| 7830 | goto error; |
| 7831 | } |
Radek Krejci | c5cc530 | 2017-02-16 10:07:46 +0100 | [diff] [blame] | 7832 | } else if (!strcmp(node->name, "when")) { |
| 7833 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_WHEN, struct lys_when*); |
| 7834 | |
| 7835 | *(struct lys_when**)p = read_yin_when(mod, node, unres); |
| 7836 | if (!*(struct lys_when**)p) { |
| 7837 | goto error; |
| 7838 | } |
| 7839 | |
| 7840 | YIN_EXTCOMPLEX_ENLARGE(struct lys_when*); |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 7841 | } else if (!strcmp(node->name, "revision")) { |
| 7842 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_REVISION, struct lys_revision*); |
| 7843 | |
| 7844 | *(struct lys_revision**)p = calloc(1, sizeof(struct lys_revision)); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7845 | LY_CHECK_ERR_GOTO(!*(struct lys_revision**)p, LOGMEM, error); |
Radek Krejci | 7417a08 | 2017-02-16 11:07:59 +0100 | [diff] [blame] | 7846 | if (fill_yin_revision(mod, node, *(struct lys_revision**)p, unres)) { |
| 7847 | goto error; |
| 7848 | } |
| 7849 | |
| 7850 | /* check uniqueness of the revision dates - not required by RFC */ |
| 7851 | if (pp) { |
| 7852 | for (j = 0; j < i; j++) { |
| 7853 | if (!strcmp((*(struct lys_revision***)pp)[j]->date, (*(struct lys_revision**)p)->date)) { |
| 7854 | LOGWRN("Module's revisions are not unique (%s).", (*(struct lys_revision**)p)->date); |
| 7855 | } |
| 7856 | } |
| 7857 | } |
| 7858 | |
| 7859 | YIN_EXTCOMPLEX_ENLARGE(struct lys_revision*); |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7860 | } else if (!strcmp(node->name, "unique")) { |
| 7861 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_UNIQUE, struct lys_unique*); |
| 7862 | |
| 7863 | *(struct lys_unique**)p = calloc(1, sizeof(struct lys_unique)); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7864 | LY_CHECK_ERR_GOTO(!*(struct lys_unique**)p, LOGMEM, error); |
Radek Krejci | c3f1b6f | 2017-02-15 10:51:10 +0100 | [diff] [blame] | 7865 | if (fill_yin_unique(mod, (struct lys_node*)ext, node, *(struct lys_unique**)p, unres)) { |
| 7866 | goto error; |
| 7867 | } |
| 7868 | |
| 7869 | if (lyp_yin_parse_subnode_ext(mod, ext, LYEXT_PAR_EXTINST, node, LYEXT_SUBSTMT_UNIQUE, i, unres)) { |
| 7870 | goto error; |
| 7871 | } |
| 7872 | YIN_EXTCOMPLEX_ENLARGE(struct lys_unique*); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 7873 | } else if (!strcmp(node->name, "action")) { |
| 7874 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_ACTION, read_yin_rpc_action); |
| 7875 | } else if (!strcmp(node->name, "anydata")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7876 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_ANYDATA, read_yin_anydata, LYS_ANYDATA); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 7877 | } else if (!strcmp(node->name, "anyxml")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7878 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_ANYXML, read_yin_anydata, LYS_ANYXML); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 7879 | } else if (!strcmp(node->name, "case")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7880 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_CASE, read_yin_case); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 7881 | } else if (!strcmp(node->name, "choice")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7882 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_CHOICE, read_yin_choice); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 7883 | } else if (!strcmp(node->name, "container")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7884 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_CONTAINER, read_yin_container); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 7885 | } else if (!strcmp(node->name, "grouping")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7886 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_GROUPING, read_yin_grouping); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 7887 | } else if (!strcmp(node->name, "output")) { |
| 7888 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_OUTPUT, read_yin_input_output); |
| 7889 | } else if (!strcmp(node->name, "input")) { |
| 7890 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_INPUT, read_yin_input_output); |
| 7891 | } else if (!strcmp(node->name, "leaf")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7892 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_LEAF, read_yin_leaf); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 7893 | } else if (!strcmp(node->name, "leaf-list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7894 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_LEAFLIST, read_yin_leaflist); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 7895 | } else if (!strcmp(node->name, "list")) { |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 7896 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_LIST, read_yin_list); |
Radek Krejci | f95b629 | 2017-02-13 15:57:37 +0100 | [diff] [blame] | 7897 | } else if (!strcmp(node->name, "notification")) { |
| 7898 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_NOTIFICATION, read_yin_notif); |
| 7899 | } else if (!strcmp(node->name, "uses")) { |
| 7900 | YIN_EXTCOMPLEX_PARSE_SNODE(LY_STMT_USES, read_yin_uses); |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7901 | } else if (!strcmp(node->name, "length")) { |
| 7902 | YIN_EXTCOMPLEX_PARSE_RESTR(LY_STMT_LENGTH); |
| 7903 | } else if (!strcmp(node->name, "must")) { |
| 7904 | pp = yin_getplace_for_extcomplex_struct(node, ext, LY_STMT_MUST); |
| 7905 | if (!pp) { |
| 7906 | goto error; |
| 7907 | } |
| 7908 | /* allocate structure for must */ |
| 7909 | (*pp) = calloc(1, sizeof(struct lys_restr)); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7910 | LY_CHECK_ERR_GOTO(!*pp, LOGMEM, error); |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7911 | |
| 7912 | if (fill_yin_must(mod, node, *((struct lys_restr **)pp), unres)) { |
| 7913 | goto error; |
| 7914 | } |
| 7915 | } else if (!strcmp(node->name, "pattern")) { |
| 7916 | YIN_EXTCOMPLEX_GETPLACE(LY_STMT_PATTERN, struct lys_restr*); |
| 7917 | GETVAL(value, node, "value"); |
| 7918 | if (lyp_check_pattern(value, NULL)) { |
| 7919 | goto error; |
| 7920 | } |
| 7921 | |
| 7922 | *(struct lys_restr **)p = calloc(1, sizeof(struct lys_restr)); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7923 | LY_CHECK_ERR_GOTO(!*(struct lys_restr **)p, LOGMEM, error); |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7924 | (*(struct lys_restr **)p)->expr = lydict_insert(mod->ctx, value, 0); |
| 7925 | |
| 7926 | modifier = 0x06; /* ACK */ |
| 7927 | if (mod->version >= 2) { |
| 7928 | name = NULL; |
| 7929 | LY_TREE_FOR(node->child, child) { |
| 7930 | if (child->ns && !strcmp(child->ns->value, LY_NSYIN) && !strcmp(child->name, "modifier")) { |
| 7931 | if (name) { |
| 7932 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "modifier", node->name); |
| 7933 | goto error; |
| 7934 | } |
| 7935 | |
| 7936 | GETVAL(name, child, "value"); |
| 7937 | if (!strcmp(name, "invert-match")) { |
| 7938 | modifier = 0x15; /* NACK */ |
| 7939 | } else { |
| 7940 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, name, "modifier"); |
| 7941 | goto error; |
| 7942 | } |
| 7943 | /* get extensions of the modifier */ |
| 7944 | if (lyp_yin_parse_subnode_ext(mod, *(struct lys_restr **)p, LYEXT_PAR_RESTR, child, |
| 7945 | LYEXT_SUBSTMT_MODIFIER, 0, unres)) { |
| 7946 | goto error; |
| 7947 | } |
| 7948 | } |
| 7949 | } |
| 7950 | } |
| 7951 | |
| 7952 | /* store the value: modifier byte + value + terminating NULL byte */ |
| 7953 | (*(struct lys_restr **)p)->expr = malloc((strlen(value) + 2) * sizeof(char)); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 7954 | LY_CHECK_ERR_GOTO(!(*(struct lys_restr **)p)->expr, LOGMEM, error); |
Radek Krejci | aa9c520 | 2017-02-15 16:10:14 +0100 | [diff] [blame] | 7955 | ((char *)(*(struct lys_restr **)p)->expr)[0] = modifier; |
| 7956 | strcpy(&((char *)(*(struct lys_restr **)p)->expr)[1], value); |
| 7957 | lydict_insert_zc(mod->ctx, (char *)(*(struct lys_restr **)p)->expr); |
| 7958 | |
| 7959 | /* get possible sub-statements */ |
| 7960 | if (read_restr_substmt(mod, *(struct lys_restr **)p, node, unres)) { |
| 7961 | goto error; |
| 7962 | } |
| 7963 | |
| 7964 | YIN_EXTCOMPLEX_ENLARGE(struct lys_restr*); |
| 7965 | } else if (!strcmp(node->name, "range")) { |
| 7966 | YIN_EXTCOMPLEX_PARSE_RESTR(LY_STMT_RANGE); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7967 | } else { |
Radek Krejci | 06a9aa0 | 2017-02-17 10:50:24 +0100 | [diff] [blame] | 7968 | LOGERR(LY_SUCCESS, "Extension's substatement \"%s\" not supported.", node->name); |
| 7969 | //LOGERR(LY_EINT, "Extension's substatement \"%s\" not supported.", node->name); |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7970 | //return EXIT_FAILURE; |
| 7971 | } |
| 7972 | lyxml_free(mod->ctx, node); |
| 7973 | } |
| 7974 | |
PavolVican | c4b798e | 2017-02-20 23:15:27 +0100 | [diff] [blame] | 7975 | if (ext->substmt && lyp_mand_check_ext(ext, yin->name)) { |
| 7976 | return EXIT_FAILURE; |
Radek Krejci | 06a9aa0 | 2017-02-17 10:50:24 +0100 | [diff] [blame] | 7977 | } |
| 7978 | |
Radek Krejci | 8d6b742 | 2017-02-03 14:42:13 +0100 | [diff] [blame] | 7979 | return EXIT_SUCCESS; |
| 7980 | |
| 7981 | error: |
| 7982 | return EXIT_FAILURE; |
| 7983 | } |