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 | |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 42 | /* parser.c */ |
| 43 | int dup_prefix_check(const char *prefix, struct lys_module *module); |
| 44 | |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 45 | #define OPT_IDENT 0x01 |
| 46 | #define OPT_CONFIG 0x02 |
| 47 | #define OPT_MODULE 0x04 |
| 48 | #define OPT_INHERIT 0x08 |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 49 | #define OPT_NACMEXT 0x10 |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 50 | static int read_yin_common(struct lys_module *, struct lys_node *, struct lys_node *, struct lyxml_elem *, int); |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 51 | |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 52 | static struct lys_node *read_yin_choice(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 53 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 54 | static struct lys_node *read_yin_case(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 55 | int resolve, struct unres_schema *unres); |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 56 | static struct lys_node *read_yin_anydata(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
| 57 | LYS_NODE type, int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 58 | static struct lys_node *read_yin_container(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 59 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 60 | static struct lys_node *read_yin_leaf(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 61 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 62 | static struct lys_node *read_yin_leaflist(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 63 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 64 | static struct lys_node *read_yin_list(struct lys_module *module,struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 65 | int resolve, struct unres_schema *unres); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 66 | static struct lys_node *read_yin_uses(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 67 | struct unres_schema *unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 68 | static struct lys_node *read_yin_grouping(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 69 | int resolve, struct unres_schema *unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 70 | static struct lys_node *read_yin_rpc_action(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
| 71 | int resolve, struct unres_schema *unres); |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 72 | static struct lys_node *read_yin_notif(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
| 73 | int resolve, struct unres_schema *unres); |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 74 | static struct lys_when *read_yin_when(struct lys_module *module, struct lyxml_elem *yin); |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 75 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 76 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 77 | static const char * |
| 78 | 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] | 79 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 80 | int len; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 81 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 82 | /* there should be <text> child */ |
| 83 | if (!node->child || !node->child->name || strcmp(node->child->name, name)) { |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 84 | LOGERR(LY_EVALID, "Expected \"%s\" element in \"%s\" element.", name, node->name); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 85 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, name, node->name); |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 86 | return NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 87 | } else if (node->child->content) { |
| 88 | len = strlen(node->child->content); |
| 89 | return lydict_insert(ctx, node->child->content, len); |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 90 | } else { |
| 91 | return lydict_insert(ctx, "", 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 92 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 93 | } |
| 94 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 95 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 96 | static int |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 97 | fill_yin_iffeature(struct lys_node *parent, struct lyxml_elem *yin, struct lys_iffeature *iffeat, struct unres_schema *unres) |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 98 | { |
| 99 | int r; |
| 100 | const char *value; |
| 101 | |
| 102 | GETVAL(value, yin, "name"); |
Michal Vasko | 97b32be | 2016-07-25 10:59:53 +0200 | [diff] [blame] | 103 | |
| 104 | if ((lys_node_module(parent)->version != 2) && ((value[0] == '(') || strchr(value, ' '))) { |
| 105 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "if-feature"); |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 106 | error: |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 107 | return EXIT_FAILURE; |
| 108 | } |
| 109 | |
Michal Vasko | 97b32be | 2016-07-25 10:59:53 +0200 | [diff] [blame] | 110 | if (!(value = transform_schema2json(parent->module, value))) { |
| 111 | return EXIT_FAILURE; |
| 112 | } |
| 113 | |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 114 | r = resolve_iffeature_compile(iffeat, value, parent, unres); |
| 115 | lydict_remove(parent->module->ctx, value); |
| 116 | if (r) { |
| 117 | return EXIT_FAILURE; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 118 | } |
| 119 | |
Radek Krejci | 9ff0a92 | 2016-07-14 13:08:05 +0200 | [diff] [blame] | 120 | return EXIT_SUCCESS; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /* logs directly */ |
| 124 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 125 | 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] | 126 | { |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 127 | struct lyxml_elem *node, *next; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 128 | const char *value; |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 129 | int rc; |
| 130 | int c_ftrs = 0, c_base = 0; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 131 | |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 132 | GETVAL(value, yin, "name"); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 133 | ident->name = value; |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 134 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 135 | if (read_yin_common(module, NULL, (struct lys_node *)ident, yin, OPT_IDENT | OPT_MODULE)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 136 | return EXIT_FAILURE; |
| 137 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 138 | |
Pavol Vican | d6cda45 | 2016-07-13 15:08:29 +0200 | [diff] [blame] | 139 | if (dup_identities_check(ident->name, module)) { |
| 140 | return EXIT_FAILURE; |
| 141 | } |
| 142 | |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 143 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 144 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 145 | /* garbage */ |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 146 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 147 | continue; |
| 148 | } |
| 149 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 150 | if (!strcmp(node->name, "base")) { |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 151 | if (c_base && (module->version < 2)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 152 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "base", "identity"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 153 | return EXIT_FAILURE; |
| 154 | } |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 155 | c_base++; |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 156 | |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 157 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
| 158 | c_ftrs++; |
| 159 | |
| 160 | } else { |
| 161 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name, "identity"); |
| 162 | return EXIT_FAILURE; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | if (c_base) { |
| 167 | ident->base_size = 0; |
| 168 | ident->base = calloc(c_base, sizeof *ident->base); |
| 169 | if (!ident->base) { |
| 170 | LOGMEM; |
| 171 | return EXIT_FAILURE; |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | if (c_ftrs) { |
| 176 | ident->iffeature = calloc(c_ftrs, sizeof *ident->iffeature); |
| 177 | if (!ident->iffeature) { |
| 178 | LOGMEM; |
| 179 | return EXIT_FAILURE; |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | LY_TREE_FOR(yin->child, node) { |
| 184 | if (!strcmp(node->name, "base")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 185 | GETVAL(value, node, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 186 | value = transform_schema2json(module, value); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 187 | if (!value) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 188 | return EXIT_FAILURE; |
| 189 | } |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 190 | |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 191 | if (unres_schema_add_str(module, unres, ident, UNRES_IDENT, value) == -1) { |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 192 | lydict_remove(module->ctx, value); |
| 193 | return EXIT_FAILURE; |
| 194 | } |
| 195 | lydict_remove(module->ctx, value); |
Radek Krejci | 018f1f5 | 2016-08-03 16:01:20 +0200 | [diff] [blame] | 196 | } else if (!strcmp(node->name, "if-feature")) { |
| 197 | rc = fill_yin_iffeature((struct lys_node *)ident, node, &ident->iffeature[ident->iffeature_size], unres); |
| 198 | ident->iffeature_size++; |
| 199 | if (rc) { |
| 200 | return EXIT_FAILURE; |
| 201 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 205 | return EXIT_SUCCESS; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 206 | |
| 207 | error: |
| 208 | return EXIT_FAILURE; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 209 | } |
| 210 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 211 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 212 | static int |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 213 | read_restr_substmt(struct ly_ctx *ctx, struct lys_restr *restr, struct lyxml_elem *yin) |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 214 | { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 215 | struct lyxml_elem *child; |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 216 | const char *value; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 217 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 218 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 219 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 220 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 221 | continue; |
| 222 | } |
| 223 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 224 | if (!strcmp(child->name, "description")) { |
| 225 | if (restr->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 226 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 227 | return EXIT_FAILURE; |
| 228 | } |
| 229 | restr->dsc = read_yin_subnode(ctx, child, "text"); |
| 230 | if (!restr->dsc) { |
| 231 | return EXIT_FAILURE; |
| 232 | } |
| 233 | } else if (!strcmp(child->name, "reference")) { |
| 234 | if (restr->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 235 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 236 | return EXIT_FAILURE; |
| 237 | } |
| 238 | restr->ref = read_yin_subnode(ctx, child, "text"); |
| 239 | if (!restr->ref) { |
| 240 | return EXIT_FAILURE; |
| 241 | } |
| 242 | } else if (!strcmp(child->name, "error-app-tag")) { |
| 243 | if (restr->eapptag) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 244 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 245 | return EXIT_FAILURE; |
| 246 | } |
Michal Vasko | 54e426f | 2015-07-07 15:38:02 +0200 | [diff] [blame] | 247 | GETVAL(value, child, "value"); |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 248 | restr->eapptag = lydict_insert(ctx, value, 0); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 249 | } else if (!strcmp(child->name, "error-message")) { |
| 250 | if (restr->emsg) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 251 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 252 | return EXIT_FAILURE; |
| 253 | } |
| 254 | restr->emsg = read_yin_subnode(ctx, child, "value"); |
| 255 | if (!restr->emsg) { |
| 256 | return EXIT_FAILURE; |
| 257 | } |
| 258 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 259 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 260 | return EXIT_FAILURE; |
| 261 | } |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | return EXIT_SUCCESS; |
Michal Vasko | c8ef47f | 2015-06-29 14:56:19 +0200 | [diff] [blame] | 265 | |
| 266 | error: |
| 267 | return EXIT_FAILURE; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 268 | } |
| 269 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 270 | /* logs directly, returns EXIT_SUCCESS, EXIT_FAILURE, -1 */ |
| 271 | int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 272 | fill_yin_type(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_type *type, |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 273 | int tpdftype, struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 274 | { |
Michal Vasko | 0aee5c1 | 2016-06-17 14:27:26 +0200 | [diff] [blame] | 275 | const char *value, *name; |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 276 | struct lys_node *siter; |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 277 | struct lyxml_elem *next, *next2, *node, *child; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 278 | struct lys_restr **restr; |
Radek Krejci | 1c5890d | 2016-08-02 13:15:42 +0200 | [diff] [blame] | 279 | struct lys_type_bit bit, *bits_sc = NULL; |
| 280 | struct lys_type_enum *enms_sc = NULL; /* shortcut */ |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 281 | struct lys_type *dertype; |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 282 | int i, j, rc, val_set, c_ftrs; |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 283 | int ret = -1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 284 | int64_t v, v_; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 285 | int64_t p, p_; |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 286 | size_t len; |
| 287 | char *buf, modifier; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 288 | |
Radek Krejci | 8de7b0f | 2015-07-02 11:43:42 +0200 | [diff] [blame] | 289 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 290 | value = transform_schema2json(module, value); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 291 | if (!value) { |
| 292 | goto error; |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 293 | } |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 294 | |
| 295 | i = parse_identifier(value); |
| 296 | if (i < 1) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 297 | LOGVAL(LYE_INCHAR, LY_VLOG_NONE, NULL, value[-i], &value[-i]); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 298 | lydict_remove(module->ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 299 | goto error; |
| 300 | } |
| 301 | /* module name */ |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 302 | name = value; |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 303 | if (value[i]) { |
| 304 | type->module_name = lydict_insert(module->ctx, value, i); |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 305 | name += i; |
| 306 | if ((name[0] != ':') || (parse_identifier(name + 1) < 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 307 | LOGVAL(LYE_INCHAR, LY_VLOG_NONE, NULL, name[0], name); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 308 | lydict_remove(module->ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 309 | goto error; |
| 310 | } |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 311 | /* name is in dictionary, but moved */ |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 312 | ++name; |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 313 | } |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 314 | |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 315 | rc = resolve_superior_type(name, type->module_name, module, parent, &type->der); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 316 | if (rc == -1) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 317 | LOGVAL(LYE_INMOD, LY_VLOG_NONE, NULL, type->module_name); |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 318 | lydict_remove(module->ctx, value); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 319 | goto error; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 320 | |
| 321 | /* 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] | 322 | } else if (rc == EXIT_FAILURE) { |
Michal Vasko | 01c6fd2 | 2016-05-20 11:43:05 +0200 | [diff] [blame] | 323 | LOGVAL(LYE_NORESOLV, LY_VLOG_NONE, NULL, "type", name); |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 324 | lydict_remove(module->ctx, value); |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 325 | ret = EXIT_FAILURE; |
| 326 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 327 | } |
Michal Vasko | 5b61c6d | 2016-06-06 15:15:30 +0200 | [diff] [blame] | 328 | lydict_remove(module->ctx, value); |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 329 | |
| 330 | if (type->base == LY_TYPE_INGRP) { |
| 331 | /* resolved type in grouping, decrease the grouping's nacm number to indicate that one less |
| 332 | * unresolved item left inside the grouping */ |
| 333 | for (siter = parent; siter && (siter->nodetype != LYS_GROUPING); siter = lys_parent(siter)); |
| 334 | if (siter) { |
| 335 | if (!((struct lys_node_grp *)siter)->nacm) { |
| 336 | LOGINT; |
| 337 | goto error; |
| 338 | } |
| 339 | ((struct lys_node_grp *)siter)->nacm--; |
| 340 | } else { |
| 341 | LOGINT; |
| 342 | goto error; |
| 343 | } |
| 344 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 345 | type->base = type->der->type.base; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 346 | |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 347 | /* check status */ |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 348 | 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] | 349 | type->der->flags, type->der->module, type->der->name, parent)) { |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 350 | return -1; |
| 351 | } |
| 352 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 353 | switch (type->base) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 354 | case LY_TYPE_BITS: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 355 | /* RFC 6020 9.7.4 - bit */ |
| 356 | |
| 357 | /* get bit specifications, at least one must be present */ |
| 358 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 359 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 360 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 361 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 362 | continue; |
| 363 | } |
| 364 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 365 | if (!strcmp(node->name, "bit")) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 366 | type->info.bits.count++; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 367 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 368 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 369 | type->info.bits.count = 0; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 370 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 371 | } |
| 372 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 373 | dertype = &type->der->type; |
| 374 | if (!dertype->der) { |
| 375 | if (!type->info.bits.count) { |
| 376 | /* type is derived directly from buit-in bits type and bit statement is required */ |
| 377 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "bit", "type"); |
| 378 | goto error; |
| 379 | } |
| 380 | } else { |
| 381 | for (; !dertype->info.enums.count; dertype = &dertype->der->type); |
| 382 | if (module->version < 2 && type->info.bits.count) { |
| 383 | /* type is not directly derived from buit-in bits type and bit statement is prohibited, |
| 384 | * since YANG 1.1 the bit statements can be used to restrict the base bits type */ |
| 385 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "bit"); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 386 | type->info.bits.count = 0; |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 387 | goto error; |
| 388 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 389 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 390 | |
| 391 | type->info.bits.bit = calloc(type->info.bits.count, sizeof *type->info.bits.bit); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 392 | if (!type->info.bits.bit) { |
| 393 | LOGMEM; |
| 394 | goto error; |
| 395 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 396 | p = 0; |
| 397 | i = -1; |
| 398 | LY_TREE_FOR(yin->child, next) { |
| 399 | i++; |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 400 | c_ftrs = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 401 | |
| 402 | GETVAL(value, next, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 403 | if (lyp_check_identifier(value, LY_IDENT_SIMPLE, NULL, NULL)) { |
Michal Vasko | 2d26a02 | 2015-12-07 09:27:21 +0100 | [diff] [blame] | 404 | goto error; |
| 405 | } |
| 406 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 407 | type->info.bits.bit[i].name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 408 | if (read_yin_common(module, NULL, (struct lys_node *)&type->info.bits.bit[i], next, 0)) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 409 | type->info.bits.count = i + 1; |
| 410 | goto error; |
| 411 | } |
| 412 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 413 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 414 | /* check the name uniqueness */ |
| 415 | for (j = 0; j < i; j++) { |
| 416 | if (!strcmp(type->info.bits.bit[j].name, type->info.bits.bit[i].name)) { |
| 417 | LOGVAL(LYE_BITS_DUPNAME, LY_VLOG_NONE, NULL, type->info.bits.bit[i].name); |
| 418 | type->info.bits.count = i + 1; |
| 419 | goto error; |
| 420 | } |
| 421 | } |
| 422 | } else { |
| 423 | /* restricted bits type - the name MUST be used in the base type */ |
| 424 | bits_sc = dertype->info.bits.bit; |
| 425 | for (j = 0; j < dertype->info.bits.count; j++) { |
| 426 | if (ly_strequal(bits_sc[j].name, value, 1)) { |
| 427 | break; |
| 428 | } |
| 429 | } |
| 430 | if (j == dertype->info.bits.count) { |
| 431 | LOGVAL(LYE_BITS_INNAME, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 432 | type->info.bits.count = i + 1; |
| 433 | goto error; |
| 434 | } |
| 435 | } |
| 436 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 437 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 438 | p_ = -1; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 439 | LY_TREE_FOR(next->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 440 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 441 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 442 | continue; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 443 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 444 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 445 | if (!strcmp(node->name, "position")) { |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 446 | if (p_ != -1) { |
| 447 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, next->name); |
| 448 | type->info.bits.count = i + 1; |
| 449 | goto error; |
| 450 | } |
| 451 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 452 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 453 | p_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 454 | |
| 455 | /* range check */ |
Radek Krejci | b8ca108 | 2015-07-10 11:24:11 +0200 | [diff] [blame] | 456 | if (p_ < 0 || p_ > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 457 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "bit/position"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 458 | type->info.bits.count = i + 1; |
| 459 | goto error; |
| 460 | } |
| 461 | type->info.bits.bit[i].pos = (uint32_t)p_; |
| 462 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 463 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 464 | /* keep the highest enum value for automatic increment */ |
| 465 | if (type->info.bits.bit[i].pos >= p) { |
| 466 | p = type->info.bits.bit[i].pos; |
| 467 | p++; |
| 468 | } else { |
| 469 | /* check that the value is unique */ |
| 470 | for (j = 0; j < i; j++) { |
| 471 | if (type->info.bits.bit[j].pos == type->info.bits.bit[i].pos) { |
| 472 | LOGVAL(LYE_BITS_DUPVAL, LY_VLOG_NONE, NULL, |
| 473 | type->info.bits.bit[i].pos, type->info.bits.bit[i].name, |
| 474 | type->info.bits.bit[j].name); |
| 475 | type->info.bits.count = i + 1; |
| 476 | goto error; |
| 477 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 478 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 479 | } |
| 480 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 481 | |
| 482 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
| 483 | c_ftrs++; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 484 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 485 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 486 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 487 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 488 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 489 | |
| 490 | if (!dertype->der) { /* directly derived type from bits built-in type */ |
| 491 | if (p_ == -1) { |
| 492 | /* assign value automatically */ |
| 493 | if (p > UINT32_MAX) { |
| 494 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "4294967295", "bit/position"); |
| 495 | type->info.bits.count = i + 1; |
| 496 | goto error; |
| 497 | } |
| 498 | type->info.bits.bit[i].pos = (uint32_t)p; |
| 499 | type->info.bits.bit[i].flags |= LYS_AUTOASSIGNED; |
| 500 | p++; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 501 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 502 | } else { /* restricted bits type */ |
| 503 | if (p_ == -1) { |
| 504 | /* automatically assign position from base type */ |
| 505 | type->info.bits.bit[i].pos = bits_sc[j].pos; |
| 506 | type->info.bits.bit[i].flags |= LYS_AUTOASSIGNED; |
| 507 | } else { |
| 508 | /* check that the assigned position corresponds to the original |
| 509 | * position of the bit in the base type */ |
| 510 | if (p_ != bits_sc[j].pos) { |
| 511 | /* p_ - assigned position in restricted bits |
| 512 | * bits_sc[j].pos - position assigned to the corresponding bit (detected above) in base type */ |
| 513 | 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] | 514 | type->info.bits.bit[i].name, bits_sc[j].pos); |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 515 | type->info.bits.count = i + 1; |
| 516 | goto error; |
| 517 | } |
| 518 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 519 | } |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 520 | |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 521 | /* if-features */ |
| 522 | if (c_ftrs) { |
| 523 | bits_sc = &type->info.bits.bit[i]; |
| 524 | bits_sc->iffeature = calloc(c_ftrs, sizeof *bits_sc->iffeature); |
| 525 | if (!bits_sc->iffeature) { |
| 526 | LOGMEM; |
| 527 | type->info.bits.count = i + 1; |
| 528 | goto error; |
| 529 | } |
| 530 | |
| 531 | LY_TREE_FOR(next->child, node) { |
| 532 | if (!strcmp(node->name, "if-feature")) { |
| 533 | rc = fill_yin_iffeature((struct lys_node *)type->parent, node, |
| 534 | &bits_sc->iffeature[bits_sc->iffeature_size], unres); |
| 535 | bits_sc->iffeature_size++; |
| 536 | if (rc) { |
| 537 | type->info.bits.count = i + 1; |
| 538 | goto error; |
| 539 | } |
| 540 | } |
| 541 | } |
| 542 | } |
| 543 | |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 544 | /* keep them ordered by position */ |
| 545 | j = i; |
| 546 | while (j && type->info.bits.bit[j - 1].pos > type->info.bits.bit[j].pos) { |
| 547 | /* switch them */ |
| 548 | memcpy(&bit, &type->info.bits.bit[j], sizeof bit); |
| 549 | memcpy(&type->info.bits.bit[j], &type->info.bits.bit[j - 1], sizeof bit); |
| 550 | memcpy(&type->info.bits.bit[j - 1], &bit, sizeof bit); |
| 551 | j--; |
| 552 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 553 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 554 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 555 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 556 | case LY_TYPE_DEC64: |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 557 | /* RFC 6020 9.2.4 - range and 9.3.4 - fraction-digits */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 558 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 559 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 560 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 561 | continue; |
| 562 | } |
| 563 | |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 564 | if (!strcmp(node->name, "range")) { |
| 565 | if (type->info.dec64.range) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 566 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 567 | goto error; |
| 568 | } |
| 569 | |
| 570 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 571 | if (lyp_check_length_range(value, type)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 572 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "range"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 573 | goto error; |
| 574 | } |
| 575 | type->info.dec64.range = calloc(1, sizeof *type->info.dec64.range); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 576 | if (!type->info.dec64.range) { |
| 577 | LOGMEM; |
| 578 | goto error; |
| 579 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 580 | type->info.dec64.range->expr = lydict_insert(module->ctx, value, 0); |
| 581 | |
| 582 | /* get possible substatements */ |
| 583 | if (read_restr_substmt(module->ctx, type->info.dec64.range, node)) { |
| 584 | goto error; |
| 585 | } |
| 586 | } else if (!strcmp(node->name, "fraction-digits")) { |
| 587 | if (type->info.dec64.dig) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 588 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 589 | goto error; |
| 590 | } |
| 591 | GETVAL(value, node, "value"); |
| 592 | v = strtol(value, NULL, 10); |
| 593 | |
| 594 | /* range check */ |
| 595 | if (v < 1 || v > 18) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 596 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 597 | goto error; |
| 598 | } |
| 599 | type->info.dec64.dig = (uint8_t)v; |
Radek Krejci | 8c3b4b6 | 2016-06-17 14:32:12 +0200 | [diff] [blame] | 600 | type->info.dec64.div = 10; |
| 601 | for (i = 1; i < v; i++) { |
| 602 | type->info.dec64.div *= 10; |
| 603 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 604 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 605 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 606 | goto error; |
| 607 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | /* mandatory sub-statement(s) check */ |
| 611 | if (!type->info.dec64.dig && !type->der->type.der) { |
| 612 | /* decimal64 type directly derived from built-in type requires fraction-digits */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 613 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "fraction-digits", "type"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 614 | goto error; |
| 615 | } |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 616 | if (type->info.dec64.dig && type->der->type.der) { |
| 617 | /* 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] | 618 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "fraction-digits"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 619 | goto error; |
| 620 | } |
Radek Krejci | b51d593 | 2016-09-08 14:02:52 +0200 | [diff] [blame] | 621 | |
| 622 | /* copy fraction-digits specification from parent type for easier internal use */ |
| 623 | if (type->der->type.der) { |
| 624 | type->info.dec64.dig = type->der->type.info.dec64.dig; |
| 625 | type->info.dec64.div = type->der->type.info.dec64.div; |
| 626 | } |
| 627 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 628 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 629 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 630 | case LY_TYPE_ENUM: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 631 | /* RFC 6020 9.6 - enum */ |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 632 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 633 | /* get enum specifications, at least one must be present */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 634 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 635 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 636 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 637 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 638 | continue; |
| 639 | } |
| 640 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 641 | if (!strcmp(node->name, "enum")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 642 | type->info.enums.count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 643 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 644 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 645 | type->info.enums.count = 0; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 646 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 647 | } |
| 648 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 649 | dertype = &type->der->type; |
| 650 | if (!dertype->der) { |
| 651 | if (!type->info.enums.count) { |
| 652 | /* type is derived directly from buit-in enumeartion type and enum statement is required */ |
| 653 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "enum", "type"); |
| 654 | goto error; |
| 655 | } |
| 656 | } else { |
| 657 | for (; !dertype->info.enums.count; dertype = &dertype->der->type); |
| 658 | if (module->version < 2 && type->info.enums.count) { |
| 659 | /* type is not directly derived from built-in enumeration type and enum statement is prohibited |
| 660 | * in YANG 1.0, since YANG 1.1 enum statements can be used to restrict the base enumeration type */ |
| 661 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "enum"); |
Radek Krejci | 69794c6 | 2016-08-02 11:01:21 +0200 | [diff] [blame] | 662 | type->info.enums.count = 0; |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 663 | goto error; |
| 664 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 665 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 666 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 667 | type->info.enums.enm = calloc(type->info.enums.count, sizeof *type->info.enums.enm); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 668 | if (!type->info.enums.enm) { |
| 669 | LOGMEM; |
| 670 | goto error; |
| 671 | } |
Radek Krejci | fc8d832 | 2016-06-24 11:23:23 +0200 | [diff] [blame] | 672 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 673 | v = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 674 | i = -1; |
| 675 | LY_TREE_FOR(yin->child, next) { |
| 676 | i++; |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 677 | c_ftrs = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 678 | |
| 679 | GETVAL(value, next, "name"); |
Michal Vasko | 0fb58e9 | 2015-12-07 09:27:44 +0100 | [diff] [blame] | 680 | if (!value[0]) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 681 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "enum name"); |
| 682 | 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] | 683 | goto error; |
| 684 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 685 | type->info.enums.enm[i].name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 686 | if (read_yin_common(module, NULL, (struct lys_node *)&type->info.enums.enm[i], next, 0)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 687 | type->info.enums.count = i + 1; |
| 688 | goto error; |
| 689 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 690 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 691 | /* the assigned name MUST NOT have any leading or trailing whitespace characters */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 692 | value = type->info.enums.enm[i].name; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 693 | if (isspace(value[0]) || isspace(value[strlen(value) - 1])) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 694 | LOGVAL(LYE_ENUM_WS, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 695 | type->info.enums.count = i + 1; |
| 696 | goto error; |
| 697 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 698 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 699 | if (!dertype->der) { /* directly derived type from enumeration built-in type */ |
| 700 | /* check the name uniqueness */ |
| 701 | for (j = 0; j < i; j++) { |
| 702 | if (ly_strequal(type->info.enums.enm[j].name, value, 1)) { |
| 703 | LOGVAL(LYE_ENUM_DUPNAME, LY_VLOG_NONE, NULL, value); |
| 704 | type->info.enums.count = i + 1; |
| 705 | goto error; |
| 706 | } |
| 707 | } |
| 708 | } else { |
| 709 | /* restricted enumeration type - the name MUST be used in the base type */ |
| 710 | enms_sc = dertype->info.enums.enm; |
| 711 | for (j = 0; j < dertype->info.enums.count; j++) { |
| 712 | if (ly_strequal(enms_sc[j].name, value, 1)) { |
| 713 | break; |
| 714 | } |
| 715 | } |
| 716 | if (j == dertype->info.enums.count) { |
| 717 | LOGVAL(LYE_ENUM_INNAME, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 718 | type->info.enums.count = i + 1; |
| 719 | goto error; |
| 720 | } |
| 721 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 722 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 723 | val_set = 0; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 724 | LY_TREE_FOR(next->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 725 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 726 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 727 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 728 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 729 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 730 | if (!strcmp(node->name, "value")) { |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 731 | if (val_set) { |
| 732 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, next->name); |
| 733 | type->info.enums.count = i + 1; |
| 734 | goto error; |
| 735 | } |
| 736 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 737 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 738 | v_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 739 | |
| 740 | /* range check */ |
| 741 | if (v_ < INT32_MIN || v_ > INT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 742 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "enum/value"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 743 | type->info.enums.count = i + 1; |
| 744 | goto error; |
| 745 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 746 | type->info.enums.enm[i].value = v_; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 747 | |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 748 | if (!dertype->der) { /* directly derived type from enumeration built-in type */ |
Pavol Vican | 5de389c | 2016-08-30 08:55:15 +0200 | [diff] [blame] | 749 | if (!i) { |
| 750 | /* change value, which is assigned automatically, if first enum has value. */ |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 751 | v = type->info.enums.enm[i].value; |
| 752 | v++; |
| 753 | } else { |
Pavol Vican | 5de389c | 2016-08-30 08:55:15 +0200 | [diff] [blame] | 754 | /* keep the highest enum value for automatic increment */ |
| 755 | if (type->info.enums.enm[i].value >= v) { |
| 756 | v = type->info.enums.enm[i].value; |
| 757 | v++; |
| 758 | } else { |
| 759 | /* check that the value is unique */ |
| 760 | for (j = 0; j < i; j++) { |
| 761 | if (type->info.enums.enm[j].value == type->info.enums.enm[i].value) { |
| 762 | LOGVAL(LYE_ENUM_DUPVAL, LY_VLOG_NONE, NULL, |
| 763 | type->info.enums.enm[i].value, type->info.enums.enm[i].name, |
| 764 | type->info.enums.enm[j].name); |
| 765 | type->info.enums.count = i + 1; |
| 766 | goto error; |
| 767 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 768 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 769 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 770 | } |
| 771 | } |
Radek Krejci | fc8d832 | 2016-06-24 11:23:23 +0200 | [diff] [blame] | 772 | val_set = 1; |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 773 | |
| 774 | } else if ((module->version >= 2) && !strcmp(node->name, "if-feature")) { |
| 775 | c_ftrs++; |
| 776 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 777 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 778 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 779 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 780 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 781 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 782 | |
| 783 | if (!dertype->der) { /* directly derived type from enumeration */ |
| 784 | if (!val_set) { |
| 785 | /* assign value automatically */ |
| 786 | if (v > INT32_MAX) { |
| 787 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "2147483648", "enum/value"); |
| 788 | type->info.enums.count = i + 1; |
| 789 | goto error; |
| 790 | } |
| 791 | type->info.enums.enm[i].value = v; |
| 792 | type->info.enums.enm[i].flags |= LYS_AUTOASSIGNED; |
| 793 | v++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 794 | } |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 795 | } else { /* restricted enum type */ |
| 796 | if (!val_set) { |
| 797 | /* automatically assign value from base type */ |
| 798 | type->info.enums.enm[i].value = enms_sc[j].value; |
| 799 | type->info.enums.enm[i].flags |= LYS_AUTOASSIGNED; |
| 800 | } else { |
| 801 | /* check that the assigned value corresponds to the original |
| 802 | * value of the enum in the base type */ |
| 803 | if (v_ != enms_sc[j].value) { |
| 804 | /* v_ - assigned value in restricted enum |
| 805 | * enms_sc[j].value - value assigned to the corresponding enum (detected above) in base type */ |
| 806 | LOGVAL(LYE_ENUM_INVAL, LY_VLOG_NONE, NULL, |
Radek Krejci | 541a45d | 2016-08-02 13:12:07 +0200 | [diff] [blame] | 807 | 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] | 808 | type->info.enums.count = i + 1; |
| 809 | goto error; |
| 810 | } |
| 811 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 812 | } |
Radek Krejci | f1ee2e2 | 2016-08-02 16:36:48 +0200 | [diff] [blame] | 813 | |
| 814 | /* if-features */ |
| 815 | if (c_ftrs) { |
| 816 | enms_sc = &type->info.enums.enm[i]; |
| 817 | enms_sc->iffeature = calloc(c_ftrs, sizeof *enms_sc->iffeature); |
| 818 | if (!enms_sc->iffeature) { |
| 819 | LOGMEM; |
| 820 | type->info.enums.count = i + 1; |
| 821 | goto error; |
| 822 | } |
| 823 | |
| 824 | LY_TREE_FOR(next->child, node) { |
| 825 | if (!strcmp(node->name, "if-feature")) { |
| 826 | rc = fill_yin_iffeature((struct lys_node *)type->parent, node, |
| 827 | &enms_sc->iffeature[enms_sc->iffeature_size], unres); |
| 828 | enms_sc->iffeature_size++; |
| 829 | if (rc) { |
| 830 | type->info.enums.count = i + 1; |
| 831 | goto error; |
| 832 | } |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 837 | } |
| 838 | break; |
| 839 | |
| 840 | case LY_TYPE_IDENT: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 841 | /* RFC 6020 9.10 - base */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 842 | |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 843 | /* get base specification, at least one must be present */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 844 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 845 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 846 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 847 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 848 | continue; |
| 849 | } |
| 850 | |
Michal Vasko | e29c662 | 2015-11-27 15:02:31 +0100 | [diff] [blame] | 851 | if (strcmp(node->name, "base")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 852 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 853 | goto error; |
| 854 | } |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 855 | |
| 856 | GETVAL(value, yin->child, "name"); |
| 857 | /* store in the JSON format */ |
| 858 | value = transform_schema2json(module, value); |
| 859 | if (!value) { |
| 860 | goto error; |
| 861 | } |
| 862 | rc = unres_schema_add_str(module, unres, type, UNRES_TYPE_IDENTREF, value); |
| 863 | lydict_remove(module->ctx, value); |
| 864 | |
| 865 | if (rc == -1) { |
| 866 | goto error; |
| 867 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 868 | } |
| 869 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 870 | if (!yin->child) { |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 871 | if (type->der->type.der) { |
Michal Vasko | f2d4396 | 2016-09-02 11:10:16 +0200 | [diff] [blame] | 872 | /* this is just a derived type with no base required */ |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 873 | break; |
| 874 | } |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 875 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "base", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 876 | goto error; |
Pavol Vican | f0046f4 | 2016-09-07 15:11:09 +0200 | [diff] [blame] | 877 | } else { |
| 878 | if (type->der->type.der) { |
| 879 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "base"); |
| 880 | goto error; |
| 881 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 882 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 883 | if (yin->child->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 884 | 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] | 885 | goto error; |
| 886 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 887 | break; |
| 888 | |
| 889 | case LY_TYPE_INST: |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 890 | /* RFC 6020 9.13.2 - require-instance */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 891 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 892 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 893 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 894 | continue; |
| 895 | } |
| 896 | |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 897 | if (!strcmp(node->name, "require-instance")) { |
| 898 | if (type->info.inst.req) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 899 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 900 | goto error; |
| 901 | } |
| 902 | GETVAL(value, node, "value"); |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 903 | if (!strcmp(value, "true")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 904 | type->info.inst.req = 1; |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 905 | } else if (!strcmp(value, "false")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 906 | type->info.inst.req = -1; |
| 907 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 908 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 909 | goto error; |
| 910 | } |
| 911 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 912 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 913 | goto error; |
| 914 | } |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 915 | } |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 916 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 917 | break; |
| 918 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 919 | case LY_TYPE_BINARY: |
| 920 | /* 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] | 921 | case LY_TYPE_INT8: |
| 922 | case LY_TYPE_INT16: |
| 923 | case LY_TYPE_INT32: |
| 924 | case LY_TYPE_INT64: |
| 925 | case LY_TYPE_UINT8: |
| 926 | case LY_TYPE_UINT16: |
| 927 | case LY_TYPE_UINT32: |
| 928 | case LY_TYPE_UINT64: |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 929 | /* RFC 6020 9.2.4 - range */ |
| 930 | |
| 931 | /* length and range are actually the same restriction, so process |
| 932 | * them by this common code, we just need to differ the name and |
| 933 | * structure where the information will be stored |
| 934 | */ |
| 935 | if (type->base == LY_TYPE_BINARY) { |
| 936 | restr = &type->info.binary.length; |
| 937 | name = "length"; |
| 938 | } else { |
| 939 | restr = &type->info.num.range; |
| 940 | name = "range"; |
| 941 | } |
| 942 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 943 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 944 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 945 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 946 | continue; |
| 947 | } |
| 948 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 949 | if (!strcmp(node->name, name)) { |
| 950 | if (*restr) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 951 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 952 | goto error; |
| 953 | } |
| 954 | |
| 955 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 956 | if (lyp_check_length_range(value, type)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 957 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 958 | goto error; |
| 959 | } |
| 960 | *restr = calloc(1, sizeof **restr); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 961 | if (!(*restr)) { |
| 962 | LOGMEM; |
| 963 | goto error; |
| 964 | } |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 965 | (*restr)->expr = lydict_insert(module->ctx, value, 0); |
| 966 | |
| 967 | /* get possible substatements */ |
| 968 | if (read_restr_substmt(module->ctx, *restr, node)) { |
| 969 | goto error; |
| 970 | } |
| 971 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 972 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 973 | goto error; |
| 974 | } |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 975 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 976 | break; |
| 977 | |
| 978 | case LY_TYPE_LEAFREF: |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 979 | /* flag resolving for later use */ |
| 980 | if (!tpdftype) { |
| 981 | for (siter = parent; siter && siter->nodetype != LYS_GROUPING; siter = lys_parent(siter)); |
| 982 | if (siter) { |
| 983 | /* just a flag - do not resolve */ |
| 984 | tpdftype = 1; |
| 985 | } |
| 986 | } |
| 987 | |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 988 | /* RFC 6020 9.9.2 - path */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 989 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 990 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 991 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 992 | continue; |
| 993 | } |
| 994 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 995 | if (!strcmp(node->name, "path") && !type->der->type.der) { |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 996 | if (type->info.lref.path) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 997 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 998 | goto error; |
| 999 | } |
| 1000 | |
| 1001 | GETVAL(value, node, "value"); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 1002 | /* store in the JSON format */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1003 | type->info.lref.path = transform_schema2json(module, value); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 1004 | if (!type->info.lref.path) { |
| 1005 | goto error; |
| 1006 | } |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1007 | |
| 1008 | /* try to resolve leafref path only when this is instantiated |
| 1009 | * leaf, so it is not: |
| 1010 | * - typedef's type, |
| 1011 | * - in grouping definition, |
| 1012 | * - just instantiated in a grouping definition, |
| 1013 | * because in those cases the nodes referenced in path might not be present |
| 1014 | * and it is not a bug. */ |
| 1015 | if (!tpdftype && unres_schema_add_node(module, unres, type, UNRES_TYPE_LEAFREF, parent) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1016 | goto error; |
| 1017 | } |
Michal Vasko | 08ae53e | 2016-09-02 12:40:04 +0200 | [diff] [blame] | 1018 | } else if (!strcmp(node->name, "require-instance")) { |
| 1019 | if (type->info.lref.req) { |
| 1020 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
| 1021 | goto error; |
| 1022 | } |
| 1023 | GETVAL(value, node, "value"); |
| 1024 | if (!strcmp(value, "true")) { |
| 1025 | type->info.lref.req = 1; |
| 1026 | } else if (!strcmp(value, "false")) { |
| 1027 | type->info.lref.req = -1; |
| 1028 | } else { |
| 1029 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
| 1030 | goto error; |
| 1031 | } |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1032 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1033 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1034 | goto error; |
| 1035 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1036 | } |
| 1037 | |
Radek Krejci | 742be35 | 2016-07-17 12:18:54 +0200 | [diff] [blame] | 1038 | if (!type->info.lref.path) { |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1039 | if (!type->der->type.der) { |
| 1040 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "path", "type"); |
Michal Vasko | 01c6fd2 | 2016-05-20 11:43:05 +0200 | [diff] [blame] | 1041 | goto error; |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1042 | } else { |
| 1043 | /* copy leafref definition into the derived type */ |
| 1044 | type->info.lref.path = lydict_insert(module->ctx, type->der->type.info.lref.path, 0); |
| 1045 | /* and resolve the path at the place we are (if not in grouping/typedef) */ |
| 1046 | if (!tpdftype && unres_schema_add_node(module, unres, type, UNRES_TYPE_LEAFREF, parent) == -1) { |
| 1047 | goto error; |
| 1048 | } |
| 1049 | |
| 1050 | /* add pointer to leafref target, only on leaves (not in typedefs) */ |
| 1051 | if (type->info.lref.target && lys_leaf_add_leafref_target(type->info.lref.target, (struct lys_node *)type->parent)) { |
| 1052 | goto error; |
| 1053 | } |
Michal Vasko | 01c6fd2 | 2016-05-20 11:43:05 +0200 | [diff] [blame] | 1054 | } |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1055 | } |
Radek Krejci | 742be35 | 2016-07-17 12:18:54 +0200 | [diff] [blame] | 1056 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1057 | break; |
| 1058 | |
| 1059 | case LY_TYPE_STRING: |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1060 | /* RFC 6020 9.4.4 - length */ |
| 1061 | /* RFC 6020 9.4.6 - pattern */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1062 | i = 0; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1063 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1064 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 1065 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1066 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1067 | continue; |
| 1068 | } |
| 1069 | |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1070 | if (!strcmp(node->name, "length")) { |
| 1071 | if (type->info.str.length) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1072 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1073 | goto error; |
| 1074 | } |
| 1075 | |
| 1076 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 1077 | if (lyp_check_length_range(value, type)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1078 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "length"); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1079 | goto error; |
| 1080 | } |
| 1081 | type->info.str.length = calloc(1, sizeof *type->info.str.length); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1082 | if (!type->info.str.length) { |
| 1083 | LOGMEM; |
| 1084 | goto error; |
| 1085 | } |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1086 | type->info.str.length->expr = lydict_insert(module->ctx, value, 0); |
| 1087 | |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1088 | /* get possible sub-statements */ |
| 1089 | if (read_restr_substmt(module->ctx, type->info.str.length, node)) { |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1090 | goto error; |
| 1091 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1092 | lyxml_free(module->ctx, node); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1093 | } else if (!strcmp(node->name, "pattern")) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1094 | i++; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1095 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1096 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1097 | goto error; |
| 1098 | } |
| 1099 | } |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1100 | /* store patterns in array */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1101 | if (i) { |
| 1102 | type->info.str.patterns = calloc(i, sizeof *type->info.str.patterns); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1103 | if (!type->info.str.patterns) { |
| 1104 | LOGMEM; |
| 1105 | goto error; |
| 1106 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1107 | LY_TREE_FOR(yin->child, node) { |
Michal Vasko | 5b64da2 | 2015-11-23 15:22:30 +0100 | [diff] [blame] | 1108 | GETVAL(value, node, "value"); |
Michal Vasko | 0aee5c1 | 2016-06-17 14:27:26 +0200 | [diff] [blame] | 1109 | if (lyp_check_pattern(value, NULL)) { |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1110 | free(type->info.str.patterns); |
Radek Krejci | 9f1e853 | 2016-06-16 11:18:21 +0200 | [diff] [blame] | 1111 | type->info.str.patterns = NULL; |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1112 | goto error; |
| 1113 | } |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1114 | |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1115 | modifier = 0x06; /* ACK */ |
| 1116 | name = NULL; |
| 1117 | LY_TREE_FOR_SAFE(node->child, next2, child) { |
| 1118 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1119 | /* garbage */ |
| 1120 | lyxml_free(module->ctx, child); |
| 1121 | continue; |
| 1122 | } |
| 1123 | |
| 1124 | if (module->version >= 2 && !strcmp(child->name, "modifier")) { |
| 1125 | if (name) { |
| 1126 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "modifier", node->name); |
| 1127 | goto error; |
| 1128 | } |
| 1129 | |
| 1130 | GETVAL(name, child, "value"); |
| 1131 | if (!strcmp(name, "invert-match")) { |
| 1132 | modifier = 0x15; /* NACK */ |
| 1133 | } else { |
| 1134 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, name, "modifier"); |
| 1135 | goto error; |
| 1136 | } |
| 1137 | lyxml_free(module->ctx, child); |
| 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | len = strlen(value); |
| 1142 | buf = malloc((len + 2) * sizeof *buf); /* modifier byte + value + terminating NULL byte */ |
| 1143 | buf[0] = modifier; |
| 1144 | strcpy(&buf[1], value); |
| 1145 | |
| 1146 | type->info.str.patterns[type->info.str.pat_count].expr = lydict_insert_zc(module->ctx, buf); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1147 | |
| 1148 | /* get possible sub-statements */ |
Michal Vasko | 5b64da2 | 2015-11-23 15:22:30 +0100 | [diff] [blame] | 1149 | if (read_restr_substmt(module->ctx, &type->info.str.patterns[type->info.str.pat_count], node)) { |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1150 | free(type->info.str.patterns); |
Pavol Vican | 9fc5d64 | 2016-08-30 15:23:19 +0200 | [diff] [blame] | 1151 | type->info.str.patterns = NULL; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1152 | goto error; |
| 1153 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1154 | type->info.str.pat_count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1155 | } |
| 1156 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1157 | break; |
| 1158 | |
| 1159 | case LY_TYPE_UNION: |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1160 | /* RFC 6020 7.4 - type */ |
| 1161 | /* count number of types in union */ |
| 1162 | i = 0; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1163 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 1164 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 1165 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1166 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1167 | continue; |
| 1168 | } |
| 1169 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1170 | if (!strcmp(node->name, "type")) { |
Radek Krejci | 038d5d9 | 2016-09-12 15:07:15 +0200 | [diff] [blame] | 1171 | if (type->der->type.der) { |
| 1172 | /* type can be a substatement only in "union" type, not in derived types */ |
| 1173 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "derived type"); |
| 1174 | goto error; |
| 1175 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1176 | i++; |
| 1177 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1178 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1179 | goto error; |
| 1180 | } |
| 1181 | } |
| 1182 | |
Radek Krejci | 038d5d9 | 2016-09-12 15:07:15 +0200 | [diff] [blame] | 1183 | if (!i && !type->der->type.der) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1184 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", "(union) type"); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1185 | goto error; |
| 1186 | } |
| 1187 | |
| 1188 | /* allocate array for union's types ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1189 | type->info.uni.types = calloc(i, sizeof *type->info.uni.types); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1190 | if (!type->info.uni.types) { |
| 1191 | LOGMEM; |
| 1192 | goto error; |
| 1193 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1194 | /* ... and fill the structures */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1195 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 1196 | type->info.uni.types[type->info.uni.count].parent = type->parent; |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 1197 | rc = fill_yin_type(module, parent, node, &type->info.uni.types[type->info.uni.count], tpdftype, unres); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1198 | if (!rc) { |
| 1199 | type->info.uni.count++; |
| 1200 | |
Radek Krejci | 7de36cf | 2016-09-12 16:18:50 +0200 | [diff] [blame] | 1201 | if (module->version < 2) { |
| 1202 | /* union's type cannot be empty or leafref */ |
| 1203 | if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_EMPTY) { |
| 1204 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "empty", node->name); |
| 1205 | rc = -1; |
| 1206 | } else if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_LEAFREF) { |
| 1207 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "leafref", node->name); |
| 1208 | rc = -1; |
| 1209 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1210 | } |
| 1211 | } |
| 1212 | if (rc) { |
| 1213 | /* even if we got EXIT_FAILURE, throw it all away, too much trouble doing something else */ |
| 1214 | for (i = 0; i < type->info.uni.count; ++i) { |
| 1215 | lys_type_free(module->ctx, &type->info.uni.types[i]); |
| 1216 | } |
| 1217 | free(type->info.uni.types); |
| 1218 | type->info.uni.types = NULL; |
| 1219 | type->info.uni.count = 0; |
Michal Vasko | eac0818 | 2016-07-21 12:16:32 +0200 | [diff] [blame] | 1220 | type->der = NULL; |
| 1221 | type->base = LY_TYPE_DER; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1222 | |
| 1223 | if (rc == EXIT_FAILURE) { |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 1224 | ret = EXIT_FAILURE; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1225 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1226 | goto error; |
| 1227 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1228 | } |
| 1229 | break; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1230 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1231 | case LY_TYPE_BOOL: |
| 1232 | case LY_TYPE_EMPTY: |
| 1233 | /* no sub-statement allowed */ |
| 1234 | LY_TREE_FOR(yin->child, node) { |
| 1235 | if (node->ns && !strcmp(node->ns->value, LY_NSYIN)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1236 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1237 | goto error; |
| 1238 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1239 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1240 | break; |
| 1241 | |
| 1242 | default: |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1243 | LOGINT; |
| 1244 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | return EXIT_SUCCESS; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 1248 | |
| 1249 | error: |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 1250 | if (type->module_name) { |
| 1251 | lydict_remove(module->ctx, type->module_name); |
| 1252 | type->module_name = NULL; |
| 1253 | } |
| 1254 | return ret; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1255 | } |
| 1256 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1257 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1258 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 1259 | fill_yin_typedef(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_tpdf *tpdf, struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1260 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1261 | const char *value; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1262 | struct lyxml_elem *node, *next; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1263 | int has_type = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1264 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1265 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1266 | if (lyp_check_identifier(value, LY_IDENT_TYPE, module, parent)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1267 | goto error; |
| 1268 | } |
| 1269 | tpdf->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1270 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1271 | /* generic part - status, description, reference */ |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 1272 | if (read_yin_common(module, NULL, (struct lys_node *)tpdf, yin, OPT_MODULE)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1273 | goto error; |
| 1274 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1275 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1276 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1277 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 1278 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1279 | continue; |
| 1280 | } |
| 1281 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1282 | if (!strcmp(node->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 1283 | if (has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1284 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1285 | goto error; |
| 1286 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1287 | /* HACK for unres */ |
| 1288 | tpdf->type.der = (struct lys_tpdf *)node; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 1289 | tpdf->type.parent = tpdf; |
Michal Vasko | 5d63140 | 2016-07-21 13:15:15 +0200 | [diff] [blame] | 1290 | 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] | 1291 | goto error; |
| 1292 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1293 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1294 | } else if (!strcmp(node->name, "default")) { |
| 1295 | if (tpdf->dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1296 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1297 | goto error; |
| 1298 | } |
| 1299 | GETVAL(value, node, "value"); |
| 1300 | tpdf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
| 1301 | } else if (!strcmp(node->name, "units")) { |
| 1302 | if (tpdf->units) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1303 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1304 | goto error; |
| 1305 | } |
| 1306 | GETVAL(value, node, "name"); |
| 1307 | tpdf->units = lydict_insert(module->ctx, value, strlen(value)); |
| 1308 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1309 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1310 | goto error; |
| 1311 | } |
| 1312 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 1313 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1314 | /* check mandatory value */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1315 | if (!has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1316 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1317 | goto error; |
| 1318 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1319 | |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 1320 | /* check default value (if not defined, there still could be some restrictions |
| 1321 | * that need to be checked against a default value from a derived type) */ |
| 1322 | if (unres_schema_add_str(module, unres, &tpdf->type, UNRES_TYPE_DFLT, tpdf->dflt) == -1) { |
| 1323 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1324 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1325 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1326 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1327 | |
| 1328 | error: |
| 1329 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1330 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1331 | } |
| 1332 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1333 | /* logs directly */ |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1334 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 1335 | 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] | 1336 | { |
| 1337 | const char *value; |
| 1338 | struct lyxml_elem *child, *next; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 1339 | int c = 0, ret; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1340 | |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1341 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1342 | if (lyp_check_identifier(value, LY_IDENT_FEATURE, module, NULL)) { |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1343 | goto error; |
| 1344 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1345 | f->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 1346 | f->module = module; |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1347 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1348 | if (read_yin_common(module, NULL, (struct lys_node *)f, yin, 0)) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1349 | goto error; |
| 1350 | } |
| 1351 | |
| 1352 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1353 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1354 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1355 | lyxml_free(module->ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1356 | continue; |
| 1357 | } |
| 1358 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1359 | if (!strcmp(child->name, "if-feature")) { |
| 1360 | c++; |
| 1361 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1362 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1363 | goto error; |
| 1364 | } |
| 1365 | } |
| 1366 | |
| 1367 | if (c) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 1368 | f->iffeature = calloc(c, sizeof *f->iffeature); |
| 1369 | if (!f->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1370 | LOGMEM; |
| 1371 | goto error; |
| 1372 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1373 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1374 | LY_TREE_FOR(yin->child, child) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 1375 | ret = fill_yin_iffeature((struct lys_node *)f, child, &f->iffeature[f->iffeature_size], unres); |
| 1376 | f->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 1377 | if (ret) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1378 | goto error; |
| 1379 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1380 | } |
| 1381 | |
Radek Krejci | c79c6b1 | 2016-07-26 15:11:49 +0200 | [diff] [blame] | 1382 | /* check for circular dependencies */ |
| 1383 | if (f->iffeature_size) { |
| 1384 | if (unres_schema_add_node(module, unres, f, UNRES_FEATURE, NULL) == -1) { |
| 1385 | goto error; |
| 1386 | } |
| 1387 | } |
| 1388 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1389 | return EXIT_SUCCESS; |
| 1390 | |
| 1391 | error: |
| 1392 | |
| 1393 | return EXIT_FAILURE; |
| 1394 | } |
| 1395 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1396 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1397 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1398 | fill_yin_must(struct lys_module *module, struct lyxml_elem *yin, struct lys_restr *must) |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1399 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1400 | const char *value; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1401 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1402 | GETVAL(value, yin, "condition"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1403 | must->expr = transform_schema2json(module, value); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 1404 | if (!must->expr) { |
| 1405 | goto error; |
| 1406 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1407 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 1408 | return read_restr_substmt(module->ctx, must, yin); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1409 | |
Michal Vasko | 77dc565 | 2016-02-15 12:32:42 +0100 | [diff] [blame] | 1410 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1411 | return EXIT_FAILURE; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1412 | } |
| 1413 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1414 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1415 | fill_yin_unique(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_unique *unique, |
| 1416 | struct unres_schema *unres) |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1417 | { |
| 1418 | int i, j; |
| 1419 | const char *value, *vaux; |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 1420 | struct unres_list_uniq *unique_info; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1421 | |
| 1422 | /* get unique value (list of leafs supposed to be unique */ |
| 1423 | GETVAL(value, yin, "tag"); |
| 1424 | |
| 1425 | /* count the number of unique leafs in the value */ |
| 1426 | vaux = value; |
| 1427 | while ((vaux = strpbrk(vaux, " \t\n"))) { |
Michal Vasko | 98645db | 2016-03-07 14:38:49 +0100 | [diff] [blame] | 1428 | unique->expr_size++; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1429 | while (isspace(*vaux)) { |
| 1430 | vaux++; |
| 1431 | } |
| 1432 | } |
| 1433 | unique->expr_size++; |
| 1434 | unique->expr = calloc(unique->expr_size, sizeof *unique->expr); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1435 | if (!unique->expr) { |
| 1436 | LOGMEM; |
| 1437 | goto error; |
| 1438 | } |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1439 | |
| 1440 | for (i = 0; i < unique->expr_size; i++) { |
| 1441 | vaux = strpbrk(value, " \t\n"); |
| 1442 | if (!vaux) { |
| 1443 | /* the last token, lydict_insert() will count its size on its own */ |
| 1444 | vaux = value; |
| 1445 | } |
| 1446 | |
| 1447 | /* store token into unique structure */ |
| 1448 | unique->expr[i] = lydict_insert(module->ctx, value, vaux - value); |
| 1449 | |
| 1450 | /* check that the expression does not repeat */ |
| 1451 | for (j = 0; j < i; j++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 1452 | if (ly_strequal(unique->expr[j], unique->expr[i], 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1453 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, unique->expr[i], "unique"); |
| 1454 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "The identifier is not unique"); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1455 | goto error; |
| 1456 | } |
| 1457 | } |
| 1458 | |
| 1459 | /* try to resolve leaf */ |
| 1460 | if (unres) { |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 1461 | unique_info = malloc(sizeof *unique_info); |
| 1462 | unique_info->list = parent; |
| 1463 | unique_info->expr = unique->expr[i]; |
| 1464 | unique_info->trg_type = &unique->trg_type; |
| 1465 | 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] | 1466 | goto error; |
| 1467 | } |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1468 | } else { |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 1469 | if (resolve_unique(parent, unique->expr[i], &unique->trg_type)) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1470 | goto error; |
| 1471 | } |
| 1472 | } |
| 1473 | |
| 1474 | /* move to next token */ |
| 1475 | value = vaux; |
| 1476 | while(isspace(*value)) { |
| 1477 | value++; |
| 1478 | } |
| 1479 | } |
| 1480 | |
| 1481 | return EXIT_SUCCESS; |
| 1482 | |
| 1483 | error: |
| 1484 | return EXIT_FAILURE; |
| 1485 | } |
| 1486 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1487 | /* logs directly |
| 1488 | * |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1489 | * type: 0 - min, 1 - max |
| 1490 | */ |
| 1491 | static int |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1492 | 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] | 1493 | { |
| 1494 | const char *value; |
| 1495 | char *endptr; |
| 1496 | unsigned long val; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1497 | uint32_t *ui32val, *min, *max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1498 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1499 | /* del min/max is forbidden */ |
| 1500 | if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1501 | 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] | 1502 | goto error; |
| 1503 | } |
| 1504 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1505 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1506 | if (target->nodetype == LYS_LEAFLIST) { |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1507 | max = &((struct lys_node_leaflist *)target)->max; |
| 1508 | min = &((struct lys_node_leaflist *)target)->min; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1509 | } else if (target->nodetype == LYS_LIST) { |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1510 | max = &((struct lys_node_list *)target)->max; |
| 1511 | min = &((struct lys_node_list *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1512 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1513 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
| 1514 | 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] | 1515 | goto error; |
| 1516 | } |
| 1517 | |
| 1518 | GETVAL(value, node, "value"); |
| 1519 | while (isspace(value[0])) { |
| 1520 | value++; |
| 1521 | } |
| 1522 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1523 | if (type && !strcmp(value, "unbounded")) { |
| 1524 | d->max = val = 0; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 1525 | d->max_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1526 | ui32val = max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1527 | } else { |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1528 | /* convert it to uint32_t */ |
| 1529 | errno = 0; |
| 1530 | endptr = NULL; |
| 1531 | val = strtoul(value, &endptr, 10); |
| 1532 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1533 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1534 | goto error; |
| 1535 | } |
| 1536 | if (type) { |
| 1537 | d->max = (uint32_t)val; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 1538 | d->max_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1539 | ui32val = max; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1540 | } else { |
| 1541 | d->min = (uint32_t)val; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 1542 | d->min_set = 1; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1543 | ui32val = min; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1544 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | if (d->mod == LY_DEVIATE_ADD) { |
| 1548 | /* check that there is no current value */ |
| 1549 | if (*ui32val) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1550 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
| 1551 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1552 | goto error; |
| 1553 | } |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 1554 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 1555 | /* unfortunately, there is no way to check reliably that there |
| 1556 | * was a value before, it could have been the default */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1557 | } |
| 1558 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1559 | /* add (already checked) and replace */ |
| 1560 | /* set new value specified in deviation */ |
| 1561 | *ui32val = (uint32_t)val; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1562 | |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1563 | /* check min-elements is smaller than max-elements */ |
| 1564 | if (*max && *min > *max) { |
| 1565 | if (type) { |
| 1566 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid value \"%d\" of \"max-elements\".", value); |
| 1567 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"max-elements\" is smaller than \"min-elements\"."); |
| 1568 | } else { |
| 1569 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid value \"%d\" of \"min-elements\".", value); |
| 1570 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"min-elements\" is bigger than \"max-elements\"."); |
| 1571 | } |
| 1572 | goto error; |
| 1573 | } |
| 1574 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1575 | return EXIT_SUCCESS; |
| 1576 | |
| 1577 | error: |
| 1578 | |
| 1579 | return EXIT_FAILURE; |
| 1580 | } |
| 1581 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1582 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1583 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1584 | fill_yin_deviation(struct lys_module *module, struct lyxml_elem *yin, struct lys_deviation *dev, |
| 1585 | struct unres_schema *unres) |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1586 | { |
| 1587 | const char *value, **stritem; |
| 1588 | struct lyxml_elem *next, *child, *develem; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 1589 | int c_dev = 0, c_must, c_uniq, c_dflt; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1590 | int f_min = 0, f_max = 0; /* flags */ |
Michal Vasko | b40b451 | 2016-02-11 11:35:37 +0100 | [diff] [blame] | 1591 | int i, j, rc; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 1592 | unsigned int u; |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1593 | struct ly_ctx *ctx; |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1594 | struct lys_deviate *d = NULL; |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 1595 | struct lys_node *node = NULL, *parent, *dev_target = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1596 | struct lys_node_choice *choice = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 1597 | struct lys_node_leaf *leaf = NULL; |
| 1598 | struct ly_set *dflt_check = ly_set_new(); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1599 | struct lys_node_list *list = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 1600 | struct lys_node_leaflist *llist = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1601 | struct lys_type *t = NULL; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 1602 | uint8_t *trg_must_size = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1603 | struct lys_restr **trg_must = NULL; |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 1604 | struct unres_schema tmp_unres; |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 1605 | struct lys_module *mod; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1606 | |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1607 | ctx = module->ctx; |
| 1608 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1609 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1610 | dev->target_name = transform_schema2json(module, value); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 1611 | if (!dev->target_name) { |
| 1612 | goto error; |
| 1613 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1614 | |
| 1615 | /* resolve target node */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1616 | rc = resolve_augment_schema_nodeid(dev->target_name, NULL, module, (const struct lys_node **)&dev_target); |
| 1617 | if (rc || !dev_target) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1618 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1619 | goto error; |
| 1620 | } |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 1621 | if (dev_target->module == lys_main_module(module)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1622 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, yin->name); |
| 1623 | 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] | 1624 | goto error; |
| 1625 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1626 | |
| 1627 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1628 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1629 | /* garbage */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1630 | lyxml_free(ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1631 | continue; |
| 1632 | } |
| 1633 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1634 | if (!strcmp(child->name, "description")) { |
| 1635 | if (dev->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1636 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1637 | goto error; |
| 1638 | } |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1639 | dev->dsc = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1640 | if (!dev->dsc) { |
| 1641 | goto error; |
| 1642 | } |
| 1643 | } else if (!strcmp(child->name, "reference")) { |
| 1644 | if (dev->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1645 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1646 | goto error; |
| 1647 | } |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1648 | dev->ref = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1649 | if (!dev->ref) { |
| 1650 | goto error; |
| 1651 | } |
| 1652 | } else if (!strcmp(child->name, "deviate")) { |
| 1653 | c_dev++; |
| 1654 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1655 | /* skip lyxml_free() at the end of the loop, node will be |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1656 | * further processed later |
| 1657 | */ |
| 1658 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 1659 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1660 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1661 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1662 | goto error; |
| 1663 | } |
| 1664 | |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1665 | lyxml_free(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1666 | } |
| 1667 | |
| 1668 | if (c_dev) { |
| 1669 | dev->deviate = calloc(c_dev, sizeof *dev->deviate); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1670 | if (!dev->deviate) { |
| 1671 | LOGMEM; |
| 1672 | goto error; |
| 1673 | } |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1674 | } else { |
| 1675 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "deviate", "deviation"); |
| 1676 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1677 | } |
| 1678 | |
| 1679 | LY_TREE_FOR(yin->child, develem) { |
| 1680 | /* init */ |
| 1681 | f_min = 0; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1682 | f_max = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1683 | c_must = 0; |
| 1684 | c_uniq = 0; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 1685 | c_dflt = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1686 | |
| 1687 | /* get deviation type */ |
| 1688 | GETVAL(value, develem, "value"); |
| 1689 | if (!strcmp(value, "not-supported")) { |
| 1690 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_NO; |
| 1691 | /* no property expected in this case */ |
| 1692 | if (develem->child) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1693 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, develem->child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1694 | goto error; |
| 1695 | } |
| 1696 | |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1697 | /* and neither any other deviate statement is expected, |
| 1698 | * not-supported deviation must be the only deviation of the target |
| 1699 | */ |
| 1700 | if (dev->deviate_size || develem->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1701 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
| 1702 | 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] | 1703 | goto error; |
| 1704 | } |
| 1705 | |
Michal Vasko | ad1f7b7 | 2016-02-17 11:13:58 +0100 | [diff] [blame] | 1706 | /* you cannot remove a key leaf */ |
Michal Vasko | 43c9477 | 2016-05-03 11:47:44 +0200 | [diff] [blame] | 1707 | if ((dev_target->nodetype == LYS_LEAF) && lys_parent(dev_target) && (lys_parent(dev_target)->nodetype == LYS_LIST)) { |
| 1708 | for (i = 0; i < ((struct lys_node_list *)lys_parent(dev_target))->keys_size; ++i) { |
| 1709 | 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] | 1710 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
| 1711 | 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] | 1712 | goto error; |
| 1713 | } |
| 1714 | } |
| 1715 | } |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1716 | |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 1717 | /* unlink and store the original node */ |
| 1718 | lys_node_unlink(dev_target); |
| 1719 | dev->orig_node = dev_target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1720 | |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1721 | dev->deviate_size = 1; |
Pavol Vican | 85991ec | 2016-08-16 14:58:12 +0200 | [diff] [blame] | 1722 | ly_set_free(dflt_check); |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1723 | return EXIT_SUCCESS; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1724 | } else if (!strcmp(value, "add")) { |
| 1725 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_ADD; |
| 1726 | } else if (!strcmp(value, "replace")) { |
| 1727 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_RPL; |
| 1728 | } else if (!strcmp(value, "delete")) { |
| 1729 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_DEL; |
| 1730 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1731 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1732 | goto error; |
| 1733 | } |
| 1734 | d = &dev->deviate[dev->deviate_size]; |
Michal Vasko | 0f7d7ee | 2016-03-08 09:20:25 +0100 | [diff] [blame] | 1735 | dev->deviate_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1736 | |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 1737 | /* store a shallow copy of the original node */ |
| 1738 | if (!dev->orig_node) { |
| 1739 | memset(&tmp_unres, 0, sizeof tmp_unres); |
| 1740 | dev->orig_node = lys_node_dup(dev_target->module, NULL, dev_target, 0, 0, &tmp_unres, 1); |
| 1741 | /* just to be safe */ |
| 1742 | if (tmp_unres.count) { |
| 1743 | LOGINT; |
| 1744 | goto error; |
| 1745 | } |
| 1746 | } |
| 1747 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1748 | /* process deviation properties */ |
| 1749 | LY_TREE_FOR_SAFE(develem->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1750 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1751 | /* garbage */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1752 | lyxml_free(ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1753 | continue; |
| 1754 | } |
| 1755 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1756 | if (!strcmp(child->name, "config")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1757 | if (d->flags & LYS_CONFIG_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1758 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1759 | goto error; |
| 1760 | } |
| 1761 | |
| 1762 | /* for we deviate from RFC 6020 and allow config property even it is/is not |
| 1763 | * specified in the target explicitly since config property inherits. So we expect |
| 1764 | * that config is specified in every node. But for delete, we check that the value |
| 1765 | * is the same as here in deviation |
| 1766 | */ |
| 1767 | GETVAL(value, child, "value"); |
| 1768 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1769 | d->flags |= LYS_CONFIG_R; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1770 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1771 | d->flags |= LYS_CONFIG_W; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1772 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1773 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1774 | goto error; |
| 1775 | } |
| 1776 | |
| 1777 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1778 | /* del config is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1779 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "config", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1780 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1781 | } else { /* add and replace are the same in this case */ |
| 1782 | /* remove current config value of the target ... */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1783 | dev_target->flags &= ~LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1784 | |
| 1785 | /* ... and replace it with the value specified in deviation */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1786 | dev_target->flags |= d->flags & LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1787 | } |
| 1788 | } else if (!strcmp(child->name, "default")) { |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 1789 | c_dflt++; |
| 1790 | |
| 1791 | /* check target node type */ |
| 1792 | if (module->version < 2 && dev_target->nodetype == LYS_LEAFLIST) { |
| 1793 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 1794 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"default\" property."); |
| 1795 | goto error; |
| 1796 | } else if (c_dflt > 1 && dev_target->nodetype != LYS_LEAFLIST) { /* from YANG 1.1 */ |
| 1797 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 1798 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow multiple \"default\" properties."); |
| 1799 | goto error; |
| 1800 | } else if (c_dflt == 1 && (!(dev_target->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_CHOICE)))) { |
| 1801 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 1802 | 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] | 1803 | goto error; |
| 1804 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1805 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 1806 | /* skip lyxml_free() at the end of the loop, this node will be processed later */ |
| 1807 | continue; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1808 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1809 | } else if (!strcmp(child->name, "mandatory")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1810 | if (d->flags & LYS_MAND_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1811 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1812 | goto error; |
| 1813 | } |
| 1814 | |
| 1815 | /* check target node type */ |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 1816 | if (!(dev_target->nodetype & (LYS_LEAF | LYS_CHOICE | LYS_ANYDATA))) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1817 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1818 | 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] | 1819 | goto error; |
| 1820 | } |
| 1821 | |
| 1822 | GETVAL(value, child, "value"); |
| 1823 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1824 | d->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1825 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1826 | d->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1827 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1828 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1829 | goto error; |
| 1830 | } |
| 1831 | |
| 1832 | if (d->mod == LY_DEVIATE_ADD) { |
| 1833 | /* check that there is no current value */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1834 | if (dev_target->flags & LYS_MAND_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1835 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1836 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1837 | goto error; |
| 1838 | } |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 1839 | |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 1840 | /* check collision with default-stmt */ |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 1841 | if (d->flags & LYS_MAND_TRUE) { |
| 1842 | if (dev_target->nodetype == LYS_CHOICE) { |
| 1843 | if (((struct lys_node_choice *)(dev_target))->dflt) { |
| 1844 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 1845 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 1846 | "Adding the \"mandatory\" statement is forbidden on choice with the \"default\" statement."); |
| 1847 | goto error; |
| 1848 | } |
| 1849 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 1850 | if (((struct lys_node_leaf *)(dev_target))->dflt) { |
| 1851 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 1852 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 1853 | "Adding the \"mandatory\" statement is forbidden on leaf with the \"default\" statement."); |
| 1854 | goto error; |
| 1855 | } |
| 1856 | } |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 1857 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1858 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 1859 | dev_target->flags |= d->flags & LYS_MAND_MASK; |
| 1860 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 1861 | /* check that there was a value before */ |
| 1862 | if (!(dev_target->flags & LYS_MAND_MASK)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1863 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1864 | 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] | 1865 | goto error; |
| 1866 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1867 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 1868 | dev_target->flags &= ~LYS_MAND_MASK; |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1869 | dev_target->flags |= d->flags & LYS_MAND_MASK; |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 1870 | } else if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1871 | /* del mandatory is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1872 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "mandatory", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1873 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1874 | } |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 1875 | |
| 1876 | /* check for mandatory node in default case, first find the closest parent choice to the changed node */ |
| 1877 | for (parent = dev_target->parent; |
| 1878 | parent && !(parent->nodetype & (LYS_CHOICE | LYS_GROUPING | LYS_ACTION)); |
| 1879 | parent = parent->parent) { |
| 1880 | if (parent->nodetype == LYS_CONTAINER && ((struct lys_node_container *)parent)->presence) { |
| 1881 | /* stop also on presence containers */ |
| 1882 | break; |
| 1883 | } |
| 1884 | } |
| 1885 | /* and if it is a choice with the default case, check it for presence of a mandatory node in it */ |
| 1886 | if (parent && parent->nodetype == LYS_CHOICE && ((struct lys_node_choice *)parent)->dflt) { |
| 1887 | if (lyp_check_mandatory_choice(parent)) { |
| 1888 | goto error; |
| 1889 | } |
| 1890 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1891 | } else if (!strcmp(child->name, "min-elements")) { |
| 1892 | if (f_min) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1893 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1894 | goto error; |
| 1895 | } |
| 1896 | f_min = 1; |
| 1897 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1898 | if (deviate_minmax(dev_target, child, d, 0)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1899 | goto error; |
| 1900 | } |
| 1901 | } else if (!strcmp(child->name, "max-elements")) { |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1902 | if (f_max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1903 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1904 | goto error; |
| 1905 | } |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1906 | f_max = 1; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1907 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1908 | if (deviate_minmax(dev_target, child, d, 1)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1909 | goto error; |
| 1910 | } |
| 1911 | } else if (!strcmp(child->name, "must")) { |
| 1912 | c_must++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1913 | /* 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] | 1914 | continue; |
| 1915 | } else if (!strcmp(child->name, "type")) { |
| 1916 | if (d->type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1917 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1918 | goto error; |
| 1919 | } |
| 1920 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1921 | /* add, del type is forbidden */ |
| 1922 | if (d->mod == LY_DEVIATE_ADD) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1923 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "deviate add"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1924 | goto error; |
| 1925 | } else if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1926 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1927 | goto error; |
| 1928 | } |
| 1929 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1930 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1931 | if (dev_target->nodetype == LYS_LEAF) { |
| 1932 | t = &((struct lys_node_leaf *)dev_target)->type; |
Pavol Vican | 2e32282 | 2016-09-07 15:48:13 +0200 | [diff] [blame] | 1933 | if (((struct lys_node_leaf *)dev_target)->dflt) { |
| 1934 | ly_set_add(dflt_check, dev_target, 0); |
| 1935 | } |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1936 | } else if (dev_target->nodetype == LYS_LEAFLIST) { |
| 1937 | t = &((struct lys_node_leaflist *)dev_target)->type; |
Pavol Vican | 2e32282 | 2016-09-07 15:48:13 +0200 | [diff] [blame] | 1938 | if (((struct lys_node_leaflist *)dev_target)->dflt) { |
| 1939 | ly_set_add(dflt_check, dev_target, 0); |
| 1940 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1941 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1942 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1943 | 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] | 1944 | goto error; |
| 1945 | } |
| 1946 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1947 | /* replace */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1948 | lys_type_free(ctx, t); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1949 | /* HACK for unres */ |
| 1950 | t->der = (struct lys_tpdf *)child; |
Michal Vasko | 3767fb2 | 2016-07-21 12:10:57 +0200 | [diff] [blame] | 1951 | 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] | 1952 | goto error; |
| 1953 | } |
| 1954 | d->type = t; |
| 1955 | } else if (!strcmp(child->name, "unique")) { |
| 1956 | c_uniq++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1957 | /* 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] | 1958 | continue; |
| 1959 | } else if (!strcmp(child->name, "units")) { |
| 1960 | if (d->units) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1961 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1962 | goto error; |
| 1963 | } |
| 1964 | |
| 1965 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1966 | if (dev_target->nodetype == LYS_LEAFLIST) { |
| 1967 | stritem = &((struct lys_node_leaflist *)dev_target)->units; |
| 1968 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 1969 | stritem = &((struct lys_node_leaf *)dev_target)->units; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1970 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1971 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1972 | 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] | 1973 | goto error; |
| 1974 | } |
| 1975 | |
| 1976 | /* get units value */ |
| 1977 | GETVAL(value, child, "name"); |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1978 | d->units = lydict_insert(ctx, value, 0); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1979 | |
| 1980 | /* apply to target */ |
| 1981 | if (d->mod == LY_DEVIATE_ADD) { |
| 1982 | /* check that there is no current value */ |
| 1983 | if (*stritem) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1984 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1985 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1986 | goto error; |
| 1987 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1988 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 1989 | *stritem = lydict_insert(ctx, value, 0); |
| 1990 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 1991 | /* check that there was a value before */ |
| 1992 | if (!*stritem) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1993 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1994 | 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] | 1995 | goto error; |
| 1996 | } |
| 1997 | |
| 1998 | lydict_remove(ctx, *stritem); |
| 1999 | *stritem = lydict_insert(ctx, value, 0); |
| 2000 | } else if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2001 | /* check values */ |
Michal Vasko | b42b697 | 2016-06-06 14:21:30 +0200 | [diff] [blame] | 2002 | if (!ly_strequal(*stritem, d->units, 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2003 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
| 2004 | 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] | 2005 | goto error; |
| 2006 | } |
| 2007 | /* remove current units value of the target */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2008 | lydict_remove(ctx, *stritem); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2009 | } |
| 2010 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2011 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2012 | goto error; |
| 2013 | } |
| 2014 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 2015 | /* 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] | 2016 | } |
| 2017 | |
| 2018 | if (c_must) { |
| 2019 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2020 | switch (dev_target->nodetype) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2021 | case LYS_LEAF: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2022 | trg_must = &((struct lys_node_leaf *)dev_target)->must; |
| 2023 | trg_must_size = &((struct lys_node_leaf *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2024 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2025 | case LYS_CONTAINER: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2026 | trg_must = &((struct lys_node_container *)dev_target)->must; |
| 2027 | trg_must_size = &((struct lys_node_container *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2028 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2029 | case LYS_LEAFLIST: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2030 | trg_must = &((struct lys_node_leaflist *)dev_target)->must; |
| 2031 | trg_must_size = &((struct lys_node_leaflist *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2032 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2033 | case LYS_LIST: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2034 | trg_must = &((struct lys_node_list *)dev_target)->must; |
| 2035 | trg_must_size = &((struct lys_node_list *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2036 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2037 | case LYS_ANYXML: |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2038 | case LYS_ANYDATA: |
| 2039 | trg_must = &((struct lys_node_anydata *)dev_target)->must; |
| 2040 | trg_must_size = &((struct lys_node_anydata *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2041 | break; |
| 2042 | default: |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2043 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "must"); |
| 2044 | 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] | 2045 | goto error; |
| 2046 | } |
| 2047 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 2048 | dev_target->flags &= ~LYS_XPATH_DEP; |
| 2049 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2050 | if (d->mod == LY_DEVIATE_RPL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2051 | /* replace must is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2052 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "must", "deviate replace"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2053 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2054 | } else if (d->mod == LY_DEVIATE_ADD) { |
| 2055 | /* reallocate the must array of the target */ |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2056 | d->must = ly_realloc(*trg_must, (c_must + *trg_must_size) * sizeof *d->must); |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2057 | if (!d->must) { |
| 2058 | LOGMEM; |
| 2059 | goto error; |
| 2060 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2061 | *trg_must = d->must; |
Michal Vasko | 979ad5b | 2015-10-23 10:12:55 +0200 | [diff] [blame] | 2062 | d->must = &((*trg_must)[*trg_must_size]); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2063 | d->must_size = c_must; |
| 2064 | } else { /* LY_DEVIATE_DEL */ |
| 2065 | d->must = calloc(c_must, sizeof *d->must); |
| 2066 | } |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2067 | if (!d->must) { |
| 2068 | LOGMEM; |
| 2069 | goto error; |
| 2070 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2071 | } |
| 2072 | if (c_uniq) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2073 | /* replace unique is forbidden */ |
| 2074 | if (d->mod == LY_DEVIATE_RPL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2075 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "unique", "deviate replace"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2076 | goto error; |
| 2077 | } |
| 2078 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2079 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2080 | if (dev_target->nodetype != LYS_LIST) { |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2081 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "unique"); |
| 2082 | 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] | 2083 | goto error; |
| 2084 | } |
| 2085 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2086 | list = (struct lys_node_list *)dev_target; |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 2087 | if (d->mod == LY_DEVIATE_ADD) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2088 | /* reallocate the unique array of the target */ |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2089 | d->unique = ly_realloc(list->unique, (c_uniq + list->unique_size) * sizeof *d->unique); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2090 | list->unique = d->unique; |
| 2091 | d->unique = &list->unique[list->unique_size]; |
| 2092 | d->unique_size = c_uniq; |
| 2093 | } else { /* LY_DEVIATE_DEL */ |
| 2094 | d->unique = calloc(c_uniq, sizeof *d->unique); |
| 2095 | } |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2096 | if (!d->unique) { |
| 2097 | LOGMEM; |
| 2098 | goto error; |
| 2099 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2100 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2101 | if (c_dflt) { |
| 2102 | if (d->mod == LY_DEVIATE_ADD) { |
| 2103 | /* check that there is no current value */ |
| 2104 | if ((dev_target->nodetype == LYS_LEAF && ((struct lys_node_leaf *)dev_target)->dflt) || |
| 2105 | (dev_target->nodetype == LYS_CHOICE && ((struct lys_node_choice *)dev_target)->dflt)) { |
| 2106 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 2107 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
| 2108 | goto error; |
| 2109 | } |
| 2110 | |
| 2111 | /* check collision with mandatory/min-elements */ |
| 2112 | if ((dev_target->flags & LYS_MAND_TRUE) || |
| 2113 | (dev_target->nodetype == LYS_LEAFLIST && ((struct lys_node_leaflist *)dev_target)->min)) { |
| 2114 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 2115 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2116 | "Adding the \"default\" statement is forbidden on %s statement.", |
| 2117 | (dev_target->flags & LYS_MAND_TRUE) ? "nodes with the \"mandatory\"" : "leaflists with non-zero \"min-elements\""); |
| 2118 | goto error; |
| 2119 | } |
| 2120 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2121 | /* check that there was a value before */ |
| 2122 | if (((dev_target->nodetype & (LYS_LEAF | LYS_LEAFLIST)) && !((struct lys_node_leaf *)dev_target)->dflt) || |
| 2123 | (dev_target->nodetype == LYS_CHOICE && !((struct lys_node_choice *)dev_target)->dflt)) { |
| 2124 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 2125 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Replacing a property that does not exist."); |
| 2126 | goto error; |
| 2127 | } |
| 2128 | } |
| 2129 | |
| 2130 | if (dev_target->nodetype == LYS_LEAFLIST) { |
| 2131 | /* reallocate default list in the target */ |
| 2132 | llist = (struct lys_node_leaflist *)dev_target; |
| 2133 | if (d->mod == LY_DEVIATE_ADD) { |
| 2134 | /* reallocate (enlarge) the unique array of the target */ |
| 2135 | llist->dflt = ly_realloc(llist->dflt, (c_dflt + llist->dflt_size) * sizeof *d->dflt); |
| 2136 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 2137 | /* reallocate (replace) the unique array of the target */ |
| 2138 | for (i = 0; i < llist->dflt_size; i++) { |
| 2139 | lydict_remove(llist->module->ctx, llist->dflt[i]); |
| 2140 | } |
| 2141 | llist->dflt = ly_realloc(llist->dflt, c_dflt * sizeof *d->dflt); |
| 2142 | llist->dflt_size = 0; |
| 2143 | } |
| 2144 | } |
| 2145 | d->dflt = calloc(c_dflt, sizeof *d->dflt); |
| 2146 | if (!d->dflt) { |
| 2147 | LOGMEM; |
| 2148 | goto error; |
| 2149 | } |
| 2150 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2151 | |
| 2152 | /* process deviation properties with 0..n cardinality */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2153 | LY_TREE_FOR(develem->child, child) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2154 | if (!strcmp(child->name, "must")) { |
| 2155 | if (d->mod == LY_DEVIATE_DEL) { |
| 2156 | if (fill_yin_must(module, child, &d->must[d->must_size])) { |
| 2157 | goto error; |
| 2158 | } |
| 2159 | |
| 2160 | /* find must to delete, we are ok with just matching conditions */ |
| 2161 | for (i = 0; i < *trg_must_size; i++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 2162 | 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] | 2163 | /* we have a match, free the must structure ... */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2164 | lys_restr_free(ctx, &((*trg_must)[i])); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2165 | /* ... and maintain the array */ |
| 2166 | (*trg_must_size)--; |
| 2167 | if (i != *trg_must_size) { |
| 2168 | (*trg_must)[i].expr = (*trg_must)[*trg_must_size].expr; |
| 2169 | (*trg_must)[i].dsc = (*trg_must)[*trg_must_size].dsc; |
| 2170 | (*trg_must)[i].ref = (*trg_must)[*trg_must_size].ref; |
| 2171 | (*trg_must)[i].eapptag = (*trg_must)[*trg_must_size].eapptag; |
| 2172 | (*trg_must)[i].emsg = (*trg_must)[*trg_must_size].emsg; |
| 2173 | } |
| 2174 | if (!(*trg_must_size)) { |
| 2175 | free(*trg_must); |
| 2176 | *trg_must = NULL; |
| 2177 | } else { |
| 2178 | (*trg_must)[*trg_must_size].expr = NULL; |
| 2179 | (*trg_must)[*trg_must_size].dsc = NULL; |
| 2180 | (*trg_must)[*trg_must_size].ref = NULL; |
| 2181 | (*trg_must)[*trg_must_size].eapptag = NULL; |
| 2182 | (*trg_must)[*trg_must_size].emsg = NULL; |
| 2183 | } |
| 2184 | |
| 2185 | i = -1; /* set match flag */ |
| 2186 | break; |
| 2187 | } |
| 2188 | } |
| 2189 | d->must_size++; |
| 2190 | if (i != -1) { |
| 2191 | /* no match found */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2192 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, |
Radek Krejci | adb5761 | 2016-02-16 13:34:34 +0100 | [diff] [blame] | 2193 | d->must[d->must_size - 1].expr, child->name); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2194 | 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] | 2195 | goto error; |
| 2196 | } |
| 2197 | } else { /* replace or add */ |
Michal Vasko | f92a728 | 2016-02-11 12:35:57 +0100 | [diff] [blame] | 2198 | memset(&((*trg_must)[*trg_must_size]), 0, sizeof **trg_must); |
| 2199 | if (fill_yin_must(module, child, &((*trg_must)[*trg_must_size]))) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2200 | goto error; |
| 2201 | } |
| 2202 | (*trg_must_size)++; |
| 2203 | } |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 2204 | |
| 2205 | /* check XPath dependencies again */ |
| 2206 | if (*trg_must_size && unres_schema_add_node(dev_target->module, unres, dev_target, UNRES_XPATH, NULL)) { |
| 2207 | goto error; |
| 2208 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2209 | } else if (!strcmp(child->name, "unique")) { |
| 2210 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | a0a10ab | 2016-03-07 14:41:23 +0100 | [diff] [blame] | 2211 | memset(&d->unique[d->unique_size], 0, sizeof *d->unique); |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2212 | 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] | 2213 | d->unique_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2214 | goto error; |
| 2215 | } |
| 2216 | |
| 2217 | /* find unique structures to delete */ |
| 2218 | for (i = 0; i < list->unique_size; i++) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2219 | 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] | 2220 | continue; |
| 2221 | } |
| 2222 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2223 | for (j = 0; j < d->unique[d->unique_size].expr_size; j++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 2224 | 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] | 2225 | break; |
| 2226 | } |
| 2227 | } |
| 2228 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2229 | if (j == d->unique[d->unique_size].expr_size) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2230 | /* we have a match, free the unique structure ... */ |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2231 | for (j = 0; j < list->unique[i].expr_size; j++) { |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 2232 | lydict_remove(ctx, list->unique[i].expr[j]); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2233 | } |
| 2234 | free(list->unique[i].expr); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2235 | /* ... and maintain the array */ |
| 2236 | list->unique_size--; |
| 2237 | if (i != list->unique_size) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2238 | list->unique[i].expr_size = list->unique[list->unique_size].expr_size; |
| 2239 | list->unique[i].expr = list->unique[list->unique_size].expr; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2240 | } |
| 2241 | |
| 2242 | if (!list->unique_size) { |
| 2243 | free(list->unique); |
| 2244 | list->unique = NULL; |
| 2245 | } else { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 2246 | list->unique[list->unique_size].expr_size = 0; |
| 2247 | list->unique[list->unique_size].expr = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2248 | } |
| 2249 | |
| 2250 | i = -1; /* set match flag */ |
| 2251 | break; |
| 2252 | } |
| 2253 | } |
| 2254 | |
| 2255 | d->unique_size++; |
| 2256 | if (i != -1) { |
| 2257 | /* no match found */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2258 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, lyxml_get_attr(child, "tag", NULL), child->name); |
| 2259 | 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] | 2260 | goto error; |
| 2261 | } |
| 2262 | } else { /* replace or add */ |
Michal Vasko | a0a10ab | 2016-03-07 14:41:23 +0100 | [diff] [blame] | 2263 | memset(&list->unique[list->unique_size], 0, sizeof *list->unique); |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 2264 | 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] | 2265 | list->unique_size++; |
| 2266 | if (i) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2267 | goto error; |
| 2268 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2269 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2270 | } else if (!strcmp(child->name, "default")) { |
| 2271 | GETVAL(value, child, "value"); |
| 2272 | u = strlen(value); |
| 2273 | d->dflt[d->dflt_size++] = lydict_insert(module->ctx, value, u); |
| 2274 | |
| 2275 | if (dev_target->nodetype == LYS_CHOICE) { |
| 2276 | choice = (struct lys_node_choice *)dev_target; |
| 2277 | rc = resolve_choice_default_schema_nodeid(value, choice->child, (const struct lys_node **)&node); |
| 2278 | if (rc || !node) { |
| 2279 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2280 | goto error; |
| 2281 | } |
| 2282 | if (d->mod == LY_DEVIATE_DEL) { |
| 2283 | if (!choice->dflt || (choice->dflt != node)) { |
| 2284 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2285 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
| 2286 | goto error; |
| 2287 | } |
| 2288 | } else { /* add or replace */ |
| 2289 | choice->dflt = node; |
| 2290 | if (!choice->dflt) { |
| 2291 | /* default branch not found */ |
| 2292 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2293 | goto error; |
| 2294 | } |
| 2295 | } |
| 2296 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 2297 | leaf = (struct lys_node_leaf *)dev_target; |
| 2298 | if (d->mod == LY_DEVIATE_DEL) { |
| 2299 | if (!leaf->dflt || !ly_strequal(leaf->dflt, value, 1)) { |
| 2300 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2301 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
| 2302 | goto error; |
| 2303 | } |
| 2304 | /* remove value */ |
| 2305 | lydict_remove(ctx, leaf->dflt); |
| 2306 | leaf->dflt = NULL; |
| 2307 | } else { /* add (already checked) and replace */ |
| 2308 | /* remove value */ |
| 2309 | lydict_remove(ctx, leaf->dflt); |
| 2310 | |
| 2311 | /* set new value */ |
| 2312 | leaf->dflt = lydict_insert(ctx, value, u); |
| 2313 | |
| 2314 | /* remember to check it later (it may not fit now, but the type can be deviated too) */ |
| 2315 | ly_set_add(dflt_check, dev_target, 0); |
| 2316 | } |
| 2317 | } else { /* LYS_LEAFLIST */ |
| 2318 | llist = (struct lys_node_leaflist *)dev_target; |
| 2319 | if (d->mod == LY_DEVIATE_DEL) { |
| 2320 | /* find and remove the value in target list */ |
| 2321 | for (i = 0; i < llist->dflt_size; i++) { |
| 2322 | if (llist->dflt[i] && ly_strequal(llist->dflt[i], value, 1)) { |
| 2323 | /* match, remove the value */ |
| 2324 | lydict_remove(llist->module->ctx, llist->dflt[i]); |
| 2325 | llist->dflt[i] = NULL; |
| 2326 | break; |
| 2327 | } |
| 2328 | } |
| 2329 | if (i == llist->dflt_size) { |
| 2330 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2331 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "The default value to delete not found in the target node."); |
| 2332 | goto error; |
| 2333 | } |
| 2334 | } else { |
| 2335 | /* add or replace, anyway we place items into the deviate's list |
| 2336 | which propagates to the target */ |
| 2337 | /* we just want to check that the value isn't already in the list */ |
| 2338 | for (i = 0; i < llist->dflt_size; i++) { |
| 2339 | if (ly_strequal(llist->dflt[i], value, 1)) { |
| 2340 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2341 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Duplicated default value \"%s\".", value); |
| 2342 | goto error; |
| 2343 | } |
| 2344 | } |
| 2345 | /* store it in target node */ |
| 2346 | llist->dflt[llist->dflt_size++] = lydict_insert(module->ctx, value, u); |
| 2347 | |
| 2348 | /* remember to check it later (it may not fit now, but the type can be deviated too) */ |
| 2349 | ly_set_add(dflt_check, dev_target, 0); |
| 2350 | } |
| 2351 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2352 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2353 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2354 | |
| 2355 | if (c_dflt && dev_target->nodetype == LYS_LEAFLIST && d->mod == LY_DEVIATE_DEL) { |
| 2356 | /* consolidate the final list in the target after removing items from it */ |
| 2357 | llist = (struct lys_node_leaflist *)dev_target; |
| 2358 | for (i = j = 0; j < llist->dflt_size; j++) { |
| 2359 | llist->dflt[i] = llist->dflt[j]; |
| 2360 | if (llist->dflt[i]) { |
| 2361 | i++; |
| 2362 | } |
| 2363 | } |
| 2364 | llist->dflt_size = i + 1; |
| 2365 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2366 | } |
| 2367 | |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2368 | /* now check whether default value, if any, matches the type */ |
Pavol Vican | 85991ec | 2016-08-16 14:58:12 +0200 | [diff] [blame] | 2369 | for (u = 0; u < dflt_check->number; ++u) { |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2370 | value = NULL; |
| 2371 | rc = EXIT_SUCCESS; |
| 2372 | if (dflt_check->set.s[u]->nodetype == LYS_LEAF) { |
| 2373 | leaf = (struct lys_node_leaf *)dflt_check->set.s[u]; |
| 2374 | rc = unres_schema_add_str(module, unres, &leaf->type, UNRES_TYPE_DFLT, value = leaf->dflt); |
| 2375 | } else { /* LYS_LEAFLIST */ |
| 2376 | llist = (struct lys_node_leaflist *)dflt_check->set.s[u]; |
| 2377 | for (j = 0; j < llist->dflt_size; j++) { |
| 2378 | rc = unres_schema_add_str(module, unres, &llist->type, UNRES_TYPE_DFLT, value = llist->dflt[j]); |
| 2379 | if (rc == -1) { |
| 2380 | break; |
| 2381 | } |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2382 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2383 | |
| 2384 | } |
| 2385 | if (rc == -1) { |
| 2386 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2387 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 2388 | "The default value \"%s\" of the deviated node \"%s\"no longer matches its type.", |
| 2389 | dev->target_name); |
| 2390 | goto error; |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2391 | } |
| 2392 | } |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 2393 | |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 2394 | /* mark all the affected modules as deviated and implemented */ |
| 2395 | for(parent = dev_target; parent; parent = lys_parent(parent)) { |
| 2396 | mod = lys_node_module(parent); |
| 2397 | if (module != mod) { |
| 2398 | mod->deviated = 1; |
| 2399 | lys_set_implemented(mod); |
| 2400 | } |
| 2401 | } |
| 2402 | |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2403 | ly_set_free(dflt_check); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2404 | return EXIT_SUCCESS; |
| 2405 | |
| 2406 | error: |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 2407 | ly_set_free(dflt_check); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2408 | return EXIT_FAILURE; |
| 2409 | } |
| 2410 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2411 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2412 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2413 | fill_yin_augment(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_node_augment *aug, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 2414 | struct unres_schema *unres) |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2415 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2416 | const char *value; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2417 | struct lyxml_elem *child, *next; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2418 | struct lys_node *node; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 2419 | int c = 0, ret; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2420 | |
Michal Vasko | 591e0b2 | 2015-08-13 13:53:43 +0200 | [diff] [blame] | 2421 | aug->nodetype = LYS_AUGMENT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2422 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2423 | aug->target_name = transform_schema2json(module, value); |
Michal Vasko | 488c19e | 2015-10-20 15:21:00 +0200 | [diff] [blame] | 2424 | if (!aug->target_name) { |
| 2425 | goto error; |
| 2426 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2427 | aug->parent = parent; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2428 | |
Michal Vasko | 1d87a92 | 2015-08-21 12:57:16 +0200 | [diff] [blame] | 2429 | if (read_yin_common(module, NULL, (struct lys_node *)aug, yin, OPT_MODULE | OPT_NACMEXT)) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2430 | goto error; |
| 2431 | } |
| 2432 | |
| 2433 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2434 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2435 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2436 | lyxml_free(module->ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2437 | continue; |
| 2438 | } |
| 2439 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2440 | if (!strcmp(child->name, "if-feature")) { |
| 2441 | c++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2442 | continue; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2443 | } else if (!strcmp(child->name, "when")) { |
| 2444 | if (aug->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2445 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2446 | goto error; |
| 2447 | } |
| 2448 | |
| 2449 | aug->when = read_yin_when(module, child); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2450 | if (!aug->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2451 | lyxml_free(module->ctx, child); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2452 | goto error; |
| 2453 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2454 | lyxml_free(module->ctx, child); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2455 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2456 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2457 | /* check allowed data sub-statements */ |
| 2458 | } else if (!strcmp(child->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2459 | node = read_yin_container(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2460 | } else if (!strcmp(child->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2461 | node = read_yin_leaflist(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2462 | } else if (!strcmp(child->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2463 | node = read_yin_leaf(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2464 | } else if (!strcmp(child->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2465 | node = read_yin_list(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2466 | } else if (!strcmp(child->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 2467 | node = read_yin_uses(module, (struct lys_node *)aug, child, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2468 | } else if (!strcmp(child->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2469 | node = read_yin_case(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2470 | } else if (!strcmp(child->name, "case")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2471 | node = read_yin_case(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2472 | } else if (!strcmp(child->name, "anyxml")) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2473 | node = read_yin_anydata(module, (struct lys_node *)aug, child, LYS_ANYXML, 0, unres); |
| 2474 | } else if (!strcmp(child->name, "anydata")) { |
| 2475 | node = read_yin_anydata(module, (struct lys_node *)aug, child, LYS_ANYDATA, 0, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 2476 | } else if (!strcmp(child->name, "action")) { |
| 2477 | node = read_yin_rpc_action(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2478 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2479 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2480 | goto error; |
| 2481 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2482 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2483 | if (!node) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2484 | goto error; |
| 2485 | } |
| 2486 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2487 | node = NULL; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2488 | lyxml_free(module->ctx, child); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2489 | } |
| 2490 | |
| 2491 | if (c) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 2492 | aug->iffeature = calloc(c, sizeof *aug->iffeature); |
| 2493 | if (!aug->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2494 | LOGMEM; |
| 2495 | goto error; |
| 2496 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2497 | } |
| 2498 | |
| 2499 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 2500 | if (!strcmp(child->name, "if-feature")) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 2501 | ret = fill_yin_iffeature((struct lys_node *)aug, child, &aug->iffeature[aug->iffeature_size], unres); |
| 2502 | aug->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 2503 | if (ret) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2504 | goto error; |
| 2505 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2506 | lyxml_free(module->ctx, child); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2507 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2508 | } |
| 2509 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2510 | /* aug->child points to the parsed nodes, they must now be |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 2511 | * connected to the tree and adjusted (if possible right now). |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 2512 | * 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] | 2513 | * when the uses does and cannot be resolved now for sure |
| 2514 | * (the grouping was not yet copied into uses). |
| 2515 | */ |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 2516 | if (!parent) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2517 | if (unres_schema_add_node(module, unres, aug, UNRES_AUGMENT, NULL) == -1) { |
Michal Vasko | 4adc10f | 2015-08-11 15:26:17 +0200 | [diff] [blame] | 2518 | goto error; |
| 2519 | } |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 2520 | } |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2521 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 2522 | /* check XPath dependencies */ |
| 2523 | if (aug->when && (unres_schema_add_node(module, unres, (struct lys_node *)aug, UNRES_XPATH, NULL) == -1)) { |
| 2524 | goto error; |
| 2525 | } |
| 2526 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2527 | return EXIT_SUCCESS; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2528 | |
| 2529 | error: |
| 2530 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2531 | return EXIT_FAILURE; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2532 | } |
| 2533 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2534 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2535 | static int |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 2536 | 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] | 2537 | { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 2538 | struct lys_module *module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2539 | struct lyxml_elem *sub, *next; |
| 2540 | const char *value; |
| 2541 | char *endptr; |
| 2542 | int f_mand = 0, f_min = 0, f_max = 0; |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 2543 | int c_must = 0, c_ftrs = 0, c_dflt = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2544 | int r; |
| 2545 | unsigned long int val; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2546 | |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 2547 | assert(uses); |
| 2548 | module = uses->module; /* shorthand */ |
| 2549 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2550 | if (read_yin_common(module, NULL, (struct lys_node *)rfn, yin, OPT_CONFIG)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2551 | goto error; |
| 2552 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2553 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2554 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2555 | rfn->target_name = transform_schema2json(module, value); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 2556 | if (!rfn->target_name) { |
| 2557 | goto error; |
| 2558 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2559 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2560 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2561 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2562 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2563 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2564 | continue; |
| 2565 | } |
| 2566 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2567 | /* limited applicability */ |
| 2568 | if (!strcmp(sub->name, "default")) { |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 2569 | /* leaf, leaf-list or choice */ |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2570 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2571 | /* check possibility of statements combination */ |
| 2572 | if (rfn->target_type) { |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 2573 | if (c_dflt) { |
| 2574 | /* multiple defaults are allowed only in leaf-list */ |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 2575 | if (module->version < 2) { |
| 2576 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 2577 | goto error; |
| 2578 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 2579 | rfn->target_type &= LYS_LEAFLIST; |
| 2580 | } else { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 2581 | if (module->version < 2) { |
| 2582 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE); |
| 2583 | } else { |
| 2584 | /* YANG 1.1 */ |
| 2585 | rfn->target_type &= (LYS_LEAFLIST | LYS_LEAF | LYS_CHOICE); |
| 2586 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 2587 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2588 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2589 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 2590 | 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] | 2591 | goto error; |
| 2592 | } |
| 2593 | } else { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 2594 | if (module->version < 2) { |
| 2595 | rfn->target_type = LYS_LEAF | LYS_CHOICE; |
| 2596 | } else { |
| 2597 | /* YANG 1.1 */ |
| 2598 | rfn->target_type = LYS_LEAFLIST | LYS_LEAF | LYS_CHOICE; |
| 2599 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2600 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2601 | |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 2602 | c_dflt++; |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 2603 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2604 | } else if (!strcmp(sub->name, "mandatory")) { |
| 2605 | /* leaf, choice or anyxml */ |
| 2606 | if (f_mand) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2607 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2608 | goto error; |
| 2609 | } |
| 2610 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2611 | * multiple mandatory statements with the "false" value |
| 2612 | */ |
| 2613 | f_mand = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2614 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2615 | /* check possibility of statements combination */ |
| 2616 | if (rfn->target_type) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2617 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE | LYS_ANYDATA); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2618 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2619 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 2620 | 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] | 2621 | goto error; |
| 2622 | } |
| 2623 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2624 | rfn->target_type = LYS_LEAF | LYS_CHOICE | LYS_ANYDATA; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2625 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2626 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2627 | GETVAL(value, sub, "value"); |
| 2628 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2629 | rfn->flags |= LYS_MAND_TRUE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2630 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2631 | rfn->flags |= LYS_MAND_FALSE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2632 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2633 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2634 | goto error; |
| 2635 | } |
| 2636 | } else if (!strcmp(sub->name, "min-elements")) { |
| 2637 | /* list or leaf-list */ |
| 2638 | if (f_min) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2639 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2640 | goto error; |
| 2641 | } |
| 2642 | f_min = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2643 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2644 | /* check possibility of statements combination */ |
| 2645 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2646 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2647 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2648 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 2649 | 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] | 2650 | goto error; |
| 2651 | } |
| 2652 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2653 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2654 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2655 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2656 | GETVAL(value, sub, "value"); |
| 2657 | while (isspace(value[0])) { |
| 2658 | value++; |
| 2659 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2660 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2661 | /* convert it to uint32_t */ |
| 2662 | errno = 0; |
| 2663 | endptr = NULL; |
| 2664 | val = strtoul(value, &endptr, 10); |
| 2665 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2666 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2667 | goto error; |
| 2668 | } |
| 2669 | rfn->mod.list.min = (uint32_t) val; |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 2670 | rfn->flags |= LYS_RFN_MINSET; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2671 | } else if (!strcmp(sub->name, "max-elements")) { |
| 2672 | /* list or leaf-list */ |
| 2673 | if (f_max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2674 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2675 | goto error; |
| 2676 | } |
| 2677 | f_max = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2678 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2679 | /* check possibility of statements combination */ |
| 2680 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2681 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2682 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2683 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 2684 | 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] | 2685 | goto error; |
| 2686 | } |
| 2687 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2688 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2689 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2690 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2691 | GETVAL(value, sub, "value"); |
| 2692 | while (isspace(value[0])) { |
| 2693 | value++; |
| 2694 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2695 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2696 | if (!strcmp(value, "unbounded")) { |
| 2697 | rfn->mod.list.max = 0; |
| 2698 | } else { |
| 2699 | /* convert it to uint32_t */ |
| 2700 | errno = 0; |
| 2701 | endptr = NULL; |
| 2702 | val = strtoul(value, &endptr, 10); |
| 2703 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2704 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2705 | goto error; |
| 2706 | } |
| 2707 | rfn->mod.list.max = (uint32_t) val; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2708 | } |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 2709 | rfn->flags |= LYS_RFN_MAXSET; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2710 | } else if (!strcmp(sub->name, "presence")) { |
| 2711 | /* container */ |
| 2712 | if (rfn->mod.presence) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2713 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2714 | goto error; |
| 2715 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2716 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2717 | /* check possibility of statements combination */ |
| 2718 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2719 | rfn->target_type &= LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2720 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2721 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 2722 | 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] | 2723 | goto error; |
| 2724 | } |
| 2725 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2726 | rfn->target_type = LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2727 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2728 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2729 | GETVAL(value, sub, "value"); |
| 2730 | rfn->mod.presence = lydict_insert(module->ctx, value, strlen(value)); |
| 2731 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 2732 | /* leafm leaf-list, list, container or anyxml */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2733 | /* check possibility of statements combination */ |
| 2734 | if (rfn->target_type) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2735 | 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] | 2736 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2737 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 2738 | 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] | 2739 | goto error; |
| 2740 | } |
| 2741 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2742 | 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] | 2743 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2744 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2745 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 2746 | continue; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2747 | |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 2748 | } else if ((module->version >= 2) && !strcmp(sub->name, "if-feature")) { |
| 2749 | /* leaf, leaf-list, list, container or anyxml */ |
| 2750 | /* check possibility of statements combination */ |
| 2751 | if (rfn->target_type) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2752 | 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] | 2753 | if (!rfn->target_type) { |
| 2754 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 2755 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid refine target nodetype for the substatements."); |
| 2756 | goto error; |
| 2757 | } |
| 2758 | } else { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 2759 | 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] | 2760 | } |
| 2761 | |
| 2762 | c_ftrs++; |
| 2763 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2764 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2765 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2766 | goto error; |
| 2767 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2768 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2769 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2770 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2771 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2772 | /* process nodes with cardinality of 0..n */ |
| 2773 | if (c_must) { |
| 2774 | rfn->must = calloc(c_must, sizeof *rfn->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2775 | if (!rfn->must) { |
| 2776 | LOGMEM; |
| 2777 | goto error; |
| 2778 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2779 | } |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 2780 | if (c_ftrs) { |
Radek Krejci | 947e034 | 2016-08-15 09:42:56 +0200 | [diff] [blame] | 2781 | rfn->iffeature = calloc(c_ftrs, sizeof *rfn->iffeature); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 2782 | if (!rfn->iffeature) { |
| 2783 | LOGMEM; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2784 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2785 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2786 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 2787 | if (c_dflt) { |
Pavol Vican | 35aa9ea | 2016-08-17 10:27:43 +0200 | [diff] [blame] | 2788 | rfn->dflt = calloc(c_dflt, sizeof *rfn->dflt); |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 2789 | if (!rfn->dflt) { |
| 2790 | LOGMEM; |
| 2791 | goto error; |
| 2792 | } |
| 2793 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2794 | |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 2795 | LY_TREE_FOR(yin->child, sub) { |
| 2796 | if (!strcmp(sub->name, "if-feature")) { |
| 2797 | r = fill_yin_iffeature(uses, sub, &rfn->iffeature[rfn->iffeature_size], unres); |
| 2798 | rfn->iffeature_size++; |
| 2799 | if (r) { |
| 2800 | goto error; |
| 2801 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 2802 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 2803 | r = fill_yin_must(module, sub, &rfn->must[rfn->must_size]); |
| 2804 | rfn->must_size++; |
| 2805 | if (r) { |
| 2806 | goto error; |
| 2807 | } |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 2808 | } else { /* default */ |
| 2809 | GETVAL(value, sub, "value"); |
| 2810 | |
| 2811 | /* check for duplicity */ |
| 2812 | for (r = 0; r < rfn->dflt_size; r++) { |
| 2813 | if (ly_strequal(rfn->dflt[r], value, 1)) { |
| 2814 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 2815 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Duplicated default value \"%s\".", value); |
| 2816 | goto error; |
| 2817 | } |
| 2818 | } |
| 2819 | rfn->dflt[rfn->dflt_size++] = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 2820 | } |
| 2821 | } |
| 2822 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2823 | return EXIT_SUCCESS; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2824 | |
| 2825 | error: |
| 2826 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2827 | return EXIT_FAILURE; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2828 | } |
| 2829 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2830 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2831 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2832 | fill_yin_import(struct lys_module *module, struct lyxml_elem *yin, struct lys_import *imp) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2833 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2834 | struct lyxml_elem *child; |
| 2835 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2836 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2837 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2838 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2839 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2840 | continue; |
| 2841 | } |
| 2842 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2843 | if (!strcmp(child->name, "prefix")) { |
| 2844 | GETVAL(value, child, "value"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2845 | if (lyp_check_identifier(value, LY_IDENT_PREFIX, module, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2846 | goto error; |
| 2847 | } |
| 2848 | imp->prefix = lydict_insert(module->ctx, value, strlen(value)); |
| 2849 | } else if (!strcmp(child->name, "revision-date")) { |
| 2850 | if (imp->rev[0]) { |
Radek Krejci | d52195b | 2016-06-22 11:18:49 +0200 | [diff] [blame] | 2851 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 2852 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2853 | } |
| 2854 | GETVAL(value, child, "date"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2855 | if (lyp_check_date(value)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2856 | goto error; |
| 2857 | } |
| 2858 | memcpy(imp->rev, value, LY_REV_SIZE - 1); |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 2859 | } else if ((module->version >= 2) && !strcmp(child->name, "description")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 2860 | if (imp->dsc) { |
| 2861 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 2862 | goto error; |
| 2863 | } |
| 2864 | imp->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 2865 | if (!imp->dsc) { |
| 2866 | goto error; |
| 2867 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 2868 | } else if ((module->version >= 2) && !strcmp(child->name, "reference")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 2869 | if (imp->ref) { |
| 2870 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 2871 | goto error; |
| 2872 | } |
| 2873 | imp->ref = read_yin_subnode(module->ctx, child, "text"); |
| 2874 | if (!imp->ref) { |
| 2875 | goto error; |
| 2876 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2877 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2878 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2879 | goto error; |
| 2880 | } |
| 2881 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2882 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2883 | /* check mandatory information */ |
| 2884 | if (!imp->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2885 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2886 | goto error; |
| 2887 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2888 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2889 | GETVAL(value, yin, "module"); |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2890 | |
Pavol Vican | e994fda | 2016-03-22 10:47:58 +0100 | [diff] [blame] | 2891 | return lyp_check_import(module, value, imp); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2892 | |
| 2893 | error: |
| 2894 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2895 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2896 | } |
| 2897 | |
Radek Krejci | 5b2c8a8 | 2016-06-17 15:36:03 +0200 | [diff] [blame] | 2898 | /* logs directly |
| 2899 | * returns: |
| 2900 | * 0 - inc successfully filled |
| 2901 | * -1 - error, inc is cleaned |
| 2902 | * 1 - duplication, ignore the inc structure, inc is cleaned |
| 2903 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2904 | static int |
Michal Vasko | 5ff7882 | 2016-02-12 09:33:31 +0100 | [diff] [blame] | 2905 | fill_yin_include(struct lys_module *module, struct lys_submodule *submodule, struct lyxml_elem *yin, |
| 2906 | struct lys_include *inc, struct unres_schema *unres) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2907 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2908 | struct lyxml_elem *child; |
| 2909 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2910 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2911 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2912 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2913 | /* garbage */ |
| 2914 | continue; |
| 2915 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2916 | if (!strcmp(child->name, "revision-date")) { |
| 2917 | if (inc->rev[0]) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2918 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2919 | goto error; |
| 2920 | } |
| 2921 | GETVAL(value, child, "date"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2922 | if (lyp_check_date(value)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2923 | goto error; |
| 2924 | } |
| 2925 | memcpy(inc->rev, value, LY_REV_SIZE - 1); |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 2926 | } else if ((module->version >= 2) && !strcmp(child->name, "description")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 2927 | if (inc->dsc) { |
| 2928 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 2929 | goto error; |
| 2930 | } |
| 2931 | inc->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 2932 | if (!inc->dsc) { |
| 2933 | goto error; |
| 2934 | } |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 2935 | } else if ((module->version >= 2) && !strcmp(child->name, "reference")) { |
Michal Vasko | 8bfe381 | 2016-07-27 13:37:52 +0200 | [diff] [blame] | 2936 | if (inc->ref) { |
| 2937 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
| 2938 | goto error; |
| 2939 | } |
| 2940 | inc->ref = read_yin_subnode(module->ctx, child, "text"); |
| 2941 | if (!inc->ref) { |
| 2942 | goto error; |
| 2943 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2944 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2945 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2946 | goto error; |
| 2947 | } |
| 2948 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2949 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2950 | GETVAL(value, yin, "module"); |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2951 | |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 2952 | return lyp_check_include(module, submodule, value, inc, unres); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2953 | |
| 2954 | error: |
| 2955 | |
Radek Krejci | 83e3f5b | 2016-06-24 14:55:25 +0200 | [diff] [blame] | 2956 | return -1; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2957 | } |
| 2958 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2959 | /* logs directly |
| 2960 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2961 | * Covers: |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 2962 | * description, reference, status, optionaly config |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 2963 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2964 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2965 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2966 | read_yin_common(struct lys_module *module, struct lys_node *parent, |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2967 | struct lys_node *node, struct lyxml_elem *xmlnode, int opt) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2968 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2969 | const char *value; |
| 2970 | struct lyxml_elem *sub, *next; |
| 2971 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2972 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2973 | if (opt & OPT_MODULE) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2974 | node->module = module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2975 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2976 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2977 | if (opt & OPT_IDENT) { |
| 2978 | GETVAL(value, xmlnode, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2979 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2980 | goto error; |
| 2981 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2982 | node->name = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2983 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2984 | |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2985 | /* inherit NACM flags */ |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2986 | if ((opt & OPT_NACMEXT) && parent) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2987 | node->nacm = parent->nacm; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2988 | } |
| 2989 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2990 | /* process local parameters */ |
| 2991 | LY_TREE_FOR_SAFE(xmlnode->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2992 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2993 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2994 | lyxml_free(ctx, sub); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2995 | continue; |
| 2996 | } |
| 2997 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 2998 | /* NACM extensions */ |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2999 | if ((opt & OPT_NACMEXT) && !strcmp(sub->ns->value, LY_NSNACM)) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3000 | if (!strcmp(sub->name, "default-deny-write")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3001 | node->nacm |= LYS_NACM_DENYW; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3002 | } else if (!strcmp(sub->name, "default-deny-all")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3003 | node->nacm |= LYS_NACM_DENYA; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3004 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3005 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3006 | goto error; |
| 3007 | } |
| 3008 | } |
| 3009 | |
| 3010 | /* else garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3011 | lyxml_free(ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3012 | continue; |
| 3013 | } |
| 3014 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3015 | if (!strcmp(sub->name, "description")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3016 | if (node->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3017 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3018 | goto error; |
| 3019 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3020 | node->dsc = read_yin_subnode(ctx, sub, "text"); |
| 3021 | if (!node->dsc) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3022 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3023 | } |
| 3024 | } else if (!strcmp(sub->name, "reference")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3025 | if (node->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3026 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3027 | goto error; |
| 3028 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3029 | node->ref = read_yin_subnode(ctx, sub, "text"); |
| 3030 | if (!node->ref) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3031 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3032 | } |
| 3033 | } else if (!strcmp(sub->name, "status")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3034 | if (node->flags & LYS_STATUS_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3035 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3036 | goto error; |
| 3037 | } |
| 3038 | GETVAL(value, sub, "value"); |
| 3039 | if (!strcmp(value, "current")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3040 | node->flags |= LYS_STATUS_CURR; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3041 | } else if (!strcmp(value, "deprecated")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3042 | node->flags |= LYS_STATUS_DEPRC; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3043 | } else if (!strcmp(value, "obsolete")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3044 | node->flags |= LYS_STATUS_OBSLT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3045 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3046 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3047 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3048 | } |
| 3049 | } else if ((opt & OPT_CONFIG) && !strcmp(sub->name, "config")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3050 | if (node->flags & LYS_CONFIG_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3051 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3052 | goto error; |
| 3053 | } |
| 3054 | GETVAL(value, sub, "value"); |
| 3055 | if (!strcmp(value, "false")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3056 | node->flags |= LYS_CONFIG_R; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3057 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3058 | node->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3059 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3060 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3061 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3062 | } |
Radek Krejci | 32c7bd6 | 2016-04-14 17:47:04 +0200 | [diff] [blame] | 3063 | node->flags |= LYS_CONFIG_SET; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3064 | } else { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3065 | /* skip the lyxml_free */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3066 | continue; |
| 3067 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3068 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3069 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3070 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3071 | if ((opt & OPT_INHERIT) && !(node->flags & LYS_CONFIG_MASK)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3072 | /* get config flag from parent */ |
Radek Krejci | 32c7bd6 | 2016-04-14 17:47:04 +0200 | [diff] [blame] | 3073 | if (parent && (parent->flags & LYS_CONFIG_R)) { |
| 3074 | node->flags |= LYS_CONFIG_R; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3075 | } else { |
| 3076 | /* default config is true */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3077 | node->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3078 | } |
| 3079 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3080 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3081 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 3082 | |
| 3083 | error: |
| 3084 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3085 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3086 | } |
| 3087 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3088 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3089 | static struct lys_when * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3090 | read_yin_when(struct lys_module *module, struct lyxml_elem *yin) |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3091 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3092 | struct lys_when *retval = NULL; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3093 | struct lyxml_elem *child; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3094 | const char *value; |
| 3095 | |
| 3096 | retval = calloc(1, sizeof *retval); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3097 | if (!retval) { |
| 3098 | LOGMEM; |
| 3099 | return NULL; |
| 3100 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3101 | |
| 3102 | GETVAL(value, yin, "condition"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3103 | retval->cond = transform_schema2json(module, value); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 3104 | if (!retval->cond) { |
| 3105 | goto error; |
| 3106 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3107 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3108 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3109 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 3110 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3111 | continue; |
| 3112 | } |
| 3113 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3114 | if (!strcmp(child->name, "description")) { |
| 3115 | if (retval->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3116 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3117 | goto error; |
| 3118 | } |
| 3119 | retval->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 3120 | if (!retval->dsc) { |
| 3121 | goto error; |
| 3122 | } |
| 3123 | } else if (!strcmp(child->name, "reference")) { |
| 3124 | if (retval->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3125 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3126 | goto error; |
| 3127 | } |
| 3128 | retval->ref = read_yin_subnode(module->ctx, child, "text"); |
| 3129 | if (!retval->ref) { |
| 3130 | goto error; |
| 3131 | } |
| 3132 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3133 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3134 | goto error; |
| 3135 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3136 | } |
| 3137 | |
| 3138 | return retval; |
| 3139 | |
| 3140 | error: |
| 3141 | |
Michal Vasko | 0308dd6 | 2015-10-07 09:14:40 +0200 | [diff] [blame] | 3142 | lys_when_free(module->ctx, retval); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3143 | return NULL; |
| 3144 | } |
| 3145 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3146 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3147 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3148 | read_yin_case(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 3149 | struct unres_schema *unres) |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3150 | { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3151 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3152 | struct lys_node_case *cs; |
| 3153 | struct lys_node *retval, *node = NULL; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3154 | int c_ftrs = 0, ret; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3155 | |
Radek Krejci | e867c85 | 2015-08-27 09:52:34 +0200 | [diff] [blame] | 3156 | /* init */ |
| 3157 | memset(&root, 0, sizeof root); |
| 3158 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3159 | cs = calloc(1, sizeof *cs); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3160 | if (!cs) { |
| 3161 | LOGMEM; |
| 3162 | return NULL; |
| 3163 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3164 | cs->nodetype = LYS_CASE; |
| 3165 | cs->prev = (struct lys_node *)cs; |
| 3166 | retval = (struct lys_node *)cs; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3167 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 3168 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_INHERIT | OPT_NACMEXT)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3169 | goto error; |
| 3170 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3171 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3172 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3173 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3174 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 3175 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3176 | goto error; |
| 3177 | } |
| 3178 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3179 | /* process choice's specific children */ |
| 3180 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3181 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3182 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3183 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3184 | continue; |
| 3185 | } |
| 3186 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3187 | if (!strcmp(sub->name, "container") || |
| 3188 | !strcmp(sub->name, "leaf-list") || |
| 3189 | !strcmp(sub->name, "leaf") || |
| 3190 | !strcmp(sub->name, "list") || |
| 3191 | !strcmp(sub->name, "uses") || |
| 3192 | !strcmp(sub->name, "choice") || |
| 3193 | !strcmp(sub->name, "anyxml")) { |
| 3194 | |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 3195 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3196 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3197 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3198 | c_ftrs++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3199 | /* skip lyxml_free() at the end of the loop, sub is processed later */ |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3200 | continue; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3201 | } else if (!strcmp(sub->name, "when")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3202 | if (cs->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3203 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3204 | goto error; |
| 3205 | } |
| 3206 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3207 | cs->when = read_yin_when(module, sub); |
| 3208 | if (!cs->when) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3209 | goto error; |
| 3210 | } |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3211 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3212 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3213 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3214 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3215 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3216 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3217 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3218 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3219 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 3220 | cs->iffeature = calloc(c_ftrs, sizeof *cs->iffeature); |
| 3221 | if (!cs->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3222 | LOGMEM; |
| 3223 | goto error; |
| 3224 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3225 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3226 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 3227 | ret = fill_yin_iffeature(retval, sub, &cs->iffeature[cs->iffeature_size], unres); |
| 3228 | cs->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3229 | if (ret) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3230 | goto error; |
| 3231 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3232 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 3233 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3234 | /* last part - process data nodes */ |
| 3235 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3236 | if (!strcmp(sub->name, "container")) { |
| 3237 | node = read_yin_container(module, retval, sub, resolve, unres); |
| 3238 | } else if (!strcmp(sub->name, "leaf-list")) { |
| 3239 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
| 3240 | } else if (!strcmp(sub->name, "leaf")) { |
| 3241 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
| 3242 | } else if (!strcmp(sub->name, "list")) { |
| 3243 | node = read_yin_list(module, retval, sub, resolve, unres); |
| 3244 | } else if (!strcmp(sub->name, "choice")) { |
| 3245 | node = read_yin_choice(module, retval, sub, resolve, unres); |
| 3246 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 3247 | node = read_yin_uses(module, retval, sub, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3248 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3249 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, resolve, unres); |
| 3250 | } else if (!strcmp(sub->name, "anydata")) { |
| 3251 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, resolve, unres); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3252 | } |
| 3253 | if (!node) { |
| 3254 | goto error; |
| 3255 | } |
| 3256 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3257 | lyxml_free(module->ctx, sub); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3258 | } |
| 3259 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 3260 | /* check XPath dependencies */ |
| 3261 | if (cs->when && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 3262 | goto error; |
| 3263 | } |
| 3264 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3265 | return retval; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3266 | |
| 3267 | error: |
| 3268 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3269 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3270 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 3271 | } |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 3272 | lys_node_free(retval, NULL, 0); |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3273 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3274 | return NULL; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3275 | } |
| 3276 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3277 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3278 | static struct lys_node * |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3279 | read_yin_choice(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3280 | { |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 3281 | struct lyxml_elem *sub, *next, *dflt = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3282 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3283 | struct lys_node *retval, *node = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3284 | struct lys_node_choice *choice; |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 3285 | const char *value; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3286 | int f_mand = 0, c_ftrs = 0, ret; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3287 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3288 | choice = calloc(1, sizeof *choice); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3289 | if (!choice) { |
| 3290 | LOGMEM; |
| 3291 | return NULL; |
| 3292 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3293 | choice->nodetype = LYS_CHOICE; |
| 3294 | choice->prev = (struct lys_node *)choice; |
| 3295 | retval = (struct lys_node *)choice; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3296 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3297 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3298 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3299 | goto error; |
| 3300 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3301 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3302 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3303 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3304 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 3305 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3306 | goto error; |
| 3307 | } |
| 3308 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3309 | /* process choice's specific children */ |
| 3310 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3311 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3312 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3313 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3314 | continue; |
| 3315 | } |
| 3316 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3317 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3318 | if (!(node = read_yin_container(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3319 | goto error; |
| 3320 | } |
| 3321 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3322 | if (!(node = read_yin_leaflist(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3323 | goto error; |
| 3324 | } |
| 3325 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3326 | if (!(node = read_yin_leaf(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3327 | goto error; |
| 3328 | } |
| 3329 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3330 | if (!(node = read_yin_list(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3331 | goto error; |
| 3332 | } |
| 3333 | } else if (!strcmp(sub->name, "case")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3334 | if (!(node = read_yin_case(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3335 | goto error; |
| 3336 | } |
| 3337 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3338 | if (!(node = read_yin_anydata(module, retval, sub, LYS_ANYXML, resolve, unres))) { |
| 3339 | goto error; |
| 3340 | } |
| 3341 | } else if (!strcmp(sub->name, "anydata")) { |
| 3342 | if (!(node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3343 | goto error; |
| 3344 | } |
| 3345 | } else if (!strcmp(sub->name, "default")) { |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 3346 | if (dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3347 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3348 | goto error; |
| 3349 | } |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 3350 | dflt = sub; |
| 3351 | lyxml_unlink_elem(ctx, dflt, 0); |
| 3352 | |
Radek Krejci | f9a312c | 2016-06-06 15:14:30 +0200 | [diff] [blame] | 3353 | continue; |
| 3354 | /* skip lyxml_free() at the end of the loop, the sub node is processed later as dflt */ |
| 3355 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3356 | } else if (!strcmp(sub->name, "mandatory")) { |
| 3357 | if (f_mand) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3358 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3359 | goto error; |
| 3360 | } |
| 3361 | /* just checking the flags in leaf is not sufficient, we would allow |
| 3362 | * multiple mandatory statements with the "false" value |
| 3363 | */ |
| 3364 | f_mand = 1; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3365 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3366 | GETVAL(value, sub, "value"); |
| 3367 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3368 | choice->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3369 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3370 | choice->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3371 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3372 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3373 | goto error; |
| 3374 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3375 | } else if (!strcmp(sub->name, "when")) { |
| 3376 | if (choice->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3377 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3378 | goto error; |
| 3379 | } |
| 3380 | |
| 3381 | choice->when = read_yin_when(module, sub); |
| 3382 | if (!choice->when) { |
| 3383 | goto error; |
| 3384 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3385 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3386 | c_ftrs++; |
| 3387 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3388 | /* 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] | 3389 | continue; |
Radek Krejci | 2f792db | 2016-09-12 10:52:33 +0200 | [diff] [blame] | 3390 | } else if (module->version >= 2 && !strcmp(sub->name, "choice")) { |
| 3391 | if (!(node = read_yin_choice(module, retval, sub, resolve, unres))) { |
| 3392 | goto error; |
| 3393 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3394 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3395 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3396 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3397 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3398 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3399 | node = NULL; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3400 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3401 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3402 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3403 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 3404 | choice->iffeature = calloc(c_ftrs, sizeof *choice->iffeature); |
| 3405 | if (!choice->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3406 | LOGMEM; |
| 3407 | goto error; |
| 3408 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3409 | } |
| 3410 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3411 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 3412 | ret = fill_yin_iffeature(retval, sub, &choice->iffeature[choice->iffeature_size], unres); |
| 3413 | choice->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3414 | if (ret) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3415 | goto error; |
| 3416 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3417 | } |
| 3418 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3419 | /* check - default is prohibited in combination with mandatory */ |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 3420 | if (dflt && (choice->flags & LYS_MAND_TRUE)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3421 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "default", "choice"); |
| 3422 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "The \"default\" statement is forbidden on choices with \"mandatory\"."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3423 | goto error; |
| 3424 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 3425 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3426 | /* link default with the case */ |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 3427 | if (dflt) { |
| 3428 | GETVAL(value, dflt, "value"); |
| 3429 | 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] | 3430 | goto error; |
| 3431 | } |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 3432 | lyxml_free(ctx, dflt); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3433 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3434 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 3435 | /* check XPath dependencies */ |
| 3436 | if (choice->when && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 3437 | goto error; |
| 3438 | } |
| 3439 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3440 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3441 | |
| 3442 | error: |
| 3443 | |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 3444 | lyxml_free(ctx, dflt); |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 3445 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3446 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3447 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3448 | } |
| 3449 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3450 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3451 | static struct lys_node * |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3452 | read_yin_anydata(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, LYS_NODE type, int resolve, |
| 3453 | struct unres_schema *unres) |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3454 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3455 | struct lys_node *retval; |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3456 | struct lys_node_anydata *anyxml; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3457 | struct lyxml_elem *sub, *next; |
| 3458 | const char *value; |
| 3459 | int r; |
| 3460 | int f_mand = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3461 | int c_must = 0, c_ftrs = 0; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3462 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3463 | anyxml = calloc(1, sizeof *anyxml); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3464 | if (!anyxml) { |
| 3465 | LOGMEM; |
| 3466 | return NULL; |
| 3467 | } |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 3468 | anyxml->nodetype = type; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3469 | anyxml->prev = (struct lys_node *)anyxml; |
| 3470 | retval = (struct lys_node *)anyxml; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3471 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3472 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3473 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3474 | goto error; |
| 3475 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3476 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3477 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3478 | |
Radek Krejci | adb3065 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 3479 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 3480 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3481 | goto error; |
| 3482 | } |
| 3483 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3484 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3485 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3486 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3487 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3488 | continue; |
| 3489 | } |
| 3490 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3491 | if (!strcmp(sub->name, "mandatory")) { |
| 3492 | if (f_mand) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3493 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3494 | goto error; |
| 3495 | } |
| 3496 | /* just checking the flags in leaf is not sufficient, we would allow |
| 3497 | * multiple mandatory statements with the "false" value |
| 3498 | */ |
| 3499 | f_mand = 1; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3500 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3501 | GETVAL(value, sub, "value"); |
| 3502 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3503 | anyxml->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3504 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3505 | anyxml->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3506 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3507 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3508 | goto error; |
| 3509 | } |
| 3510 | /* else false is the default value, so we can ignore it */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3511 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3512 | } else if (!strcmp(sub->name, "when")) { |
| 3513 | if (anyxml->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3514 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3515 | goto error; |
| 3516 | } |
| 3517 | |
| 3518 | anyxml->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3519 | if (!anyxml->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3520 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3521 | goto error; |
| 3522 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3523 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3524 | } else if (!strcmp(sub->name, "must")) { |
| 3525 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3526 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3527 | c_ftrs++; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3528 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3529 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3530 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3531 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3532 | } |
| 3533 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3534 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3535 | /* middle part - process nodes with cardinality of 0..n */ |
| 3536 | if (c_must) { |
| 3537 | anyxml->must = calloc(c_must, sizeof *anyxml->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3538 | if (!anyxml->must) { |
| 3539 | LOGMEM; |
| 3540 | goto error; |
| 3541 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3542 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3543 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 3544 | anyxml->iffeature = calloc(c_ftrs, sizeof *anyxml->iffeature); |
| 3545 | if (!anyxml->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3546 | LOGMEM; |
| 3547 | goto error; |
| 3548 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3549 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3550 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3551 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3552 | if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3553 | r = fill_yin_must(module, sub, &anyxml->must[anyxml->must_size]); |
| 3554 | anyxml->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3555 | if (r) { |
| 3556 | goto error; |
| 3557 | } |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 3558 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 3559 | r = fill_yin_iffeature(retval, sub, &anyxml->iffeature[anyxml->iffeature_size], unres); |
| 3560 | anyxml->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3561 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3562 | goto error; |
| 3563 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3564 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3565 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3566 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 3567 | /* check XPath dependencies */ |
| 3568 | if ((anyxml->when || anyxml->must_size) && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 3569 | goto error; |
| 3570 | } |
| 3571 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3572 | return retval; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3573 | |
| 3574 | error: |
| 3575 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 3576 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3577 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3578 | return NULL; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3579 | } |
| 3580 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3581 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3582 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3583 | read_yin_leaf(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3584 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3585 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3586 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3587 | struct lys_node_leaf *leaf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3588 | struct lyxml_elem *sub, *next; |
| 3589 | const char *value; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3590 | int r, has_type = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3591 | int c_must = 0, c_ftrs = 0, f_mand = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3592 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3593 | leaf = calloc(1, sizeof *leaf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3594 | if (!leaf) { |
| 3595 | LOGMEM; |
| 3596 | return NULL; |
| 3597 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3598 | leaf->nodetype = LYS_LEAF; |
| 3599 | leaf->prev = (struct lys_node *)leaf; |
| 3600 | retval = (struct lys_node *)leaf; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3601 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3602 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3603 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3604 | goto error; |
| 3605 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3606 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3607 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3608 | |
Radek Krejci | adb3065 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 3609 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 3610 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3611 | goto error; |
| 3612 | } |
| 3613 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3614 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3615 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3616 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3617 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3618 | continue; |
| 3619 | } |
| 3620 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3621 | if (!strcmp(sub->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 3622 | if (has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3623 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3624 | goto error; |
| 3625 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3626 | /* HACK for unres */ |
| 3627 | leaf->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3628 | leaf->type.parent = (struct lys_tpdf *)leaf; |
Michal Vasko | 3767fb2 | 2016-07-21 12:10:57 +0200 | [diff] [blame] | 3629 | if (unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DER, retval) == -1) { |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3630 | leaf->type.der = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3631 | goto error; |
| 3632 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3633 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3634 | } else if (!strcmp(sub->name, "default")) { |
| 3635 | if (leaf->dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3636 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3637 | goto error; |
| 3638 | } |
| 3639 | GETVAL(value, sub, "value"); |
| 3640 | leaf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
| 3641 | } else if (!strcmp(sub->name, "units")) { |
| 3642 | if (leaf->units) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3643 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3644 | goto error; |
| 3645 | } |
| 3646 | GETVAL(value, sub, "name"); |
| 3647 | leaf->units = lydict_insert(module->ctx, value, strlen(value)); |
| 3648 | } else if (!strcmp(sub->name, "mandatory")) { |
| 3649 | if (f_mand) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3650 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3651 | goto error; |
| 3652 | } |
| 3653 | /* just checking the flags in leaf is not sufficient, we would allow |
| 3654 | * multiple mandatory statements with the "false" value |
| 3655 | */ |
| 3656 | f_mand = 1; |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3657 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3658 | GETVAL(value, sub, "value"); |
| 3659 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3660 | leaf->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3661 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3662 | leaf->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3663 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3664 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3665 | goto error; |
| 3666 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3667 | } else if (!strcmp(sub->name, "when")) { |
| 3668 | if (leaf->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3669 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3670 | goto error; |
| 3671 | } |
| 3672 | |
| 3673 | leaf->when = read_yin_when(module, sub); |
| 3674 | if (!leaf->when) { |
| 3675 | goto error; |
| 3676 | } |
| 3677 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3678 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3679 | c_must++; |
| 3680 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3681 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3682 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3683 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3684 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3685 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3686 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3687 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3688 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3689 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3690 | /* 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] | 3691 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3692 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3693 | /* check mandatory parameters */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3694 | if (!has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3695 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3696 | goto error; |
| 3697 | } |
Michal Vasko | 478c465 | 2016-07-21 12:55:01 +0200 | [diff] [blame] | 3698 | if (leaf->dflt && (leaf->flags & LYS_MAND_TRUE)) { |
| 3699 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "mandatory", "leaf"); |
| 3700 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 3701 | "The \"mandatory\" statement is forbidden on leaf with the \"default\" statement."); |
| 3702 | goto error; |
| 3703 | } |
| 3704 | |
| 3705 | /* check default value (if not defined, there still could be some restrictions |
| 3706 | * that need to be checked against a default value from a derived type) */ |
| 3707 | if (unres_schema_add_str(module, unres, &leaf->type, UNRES_TYPE_DFLT, leaf->dflt) == -1) { |
| 3708 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3709 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3710 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3711 | /* middle part - process nodes with cardinality of 0..n */ |
| 3712 | if (c_must) { |
| 3713 | leaf->must = calloc(c_must, sizeof *leaf->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3714 | if (!leaf->must) { |
| 3715 | LOGMEM; |
| 3716 | goto error; |
| 3717 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3718 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3719 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 3720 | leaf->iffeature = calloc(c_ftrs, sizeof *leaf->iffeature); |
| 3721 | if (!leaf->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3722 | LOGMEM; |
| 3723 | goto error; |
| 3724 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3725 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3726 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3727 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3728 | if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3729 | r = fill_yin_must(module, sub, &leaf->must[leaf->must_size]); |
| 3730 | leaf->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3731 | if (r) { |
| 3732 | goto error; |
| 3733 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3734 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 3735 | r = fill_yin_iffeature(retval, sub, &leaf->iffeature[leaf->iffeature_size], unres); |
| 3736 | leaf->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3737 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3738 | goto error; |
| 3739 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3740 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3741 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3742 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 3743 | /* check XPath dependencies */ |
| 3744 | if ((leaf->when || leaf->must_size) && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 3745 | goto error; |
| 3746 | } |
| 3747 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3748 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3749 | |
| 3750 | error: |
| 3751 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 3752 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3753 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3754 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3755 | } |
| 3756 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3757 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3758 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3759 | read_yin_leaflist(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3760 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3761 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3762 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3763 | struct lys_node_leaflist *llist; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3764 | struct lyxml_elem *sub, *next; |
| 3765 | const char *value; |
| 3766 | char *endptr; |
| 3767 | unsigned long val; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3768 | int r, has_type = 0; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3769 | int c_must = 0, c_ftrs = 0, c_dflt = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3770 | int f_ordr = 0, f_min = 0, f_max = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3771 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3772 | llist = calloc(1, sizeof *llist); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3773 | if (!llist) { |
| 3774 | LOGMEM; |
| 3775 | return NULL; |
| 3776 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3777 | llist->nodetype = LYS_LEAFLIST; |
| 3778 | llist->prev = (struct lys_node *)llist; |
| 3779 | retval = (struct lys_node *)llist; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3780 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3781 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3782 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3783 | goto error; |
| 3784 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3785 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3786 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3787 | |
Radek Krejci | adb3065 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 3788 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 3789 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3790 | goto error; |
| 3791 | } |
| 3792 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3793 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3794 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3795 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3796 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3797 | continue; |
| 3798 | } |
| 3799 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3800 | if (!strcmp(sub->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 3801 | if (has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3802 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3803 | goto error; |
| 3804 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3805 | /* HACK for unres */ |
| 3806 | llist->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3807 | llist->type.parent = (struct lys_tpdf *)llist; |
Michal Vasko | 3767fb2 | 2016-07-21 12:10:57 +0200 | [diff] [blame] | 3808 | if (unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DER, retval) == -1) { |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3809 | llist->type.der = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3810 | goto error; |
| 3811 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3812 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3813 | } else if (!strcmp(sub->name, "units")) { |
| 3814 | if (llist->units) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3815 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3816 | goto error; |
| 3817 | } |
| 3818 | GETVAL(value, sub, "name"); |
| 3819 | llist->units = lydict_insert(module->ctx, value, strlen(value)); |
| 3820 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 3821 | if (f_ordr) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3822 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3823 | goto error; |
| 3824 | } |
| 3825 | /* just checking the flags in llist is not sufficient, we would |
| 3826 | * allow multiple ordered-by statements with the "system" value |
| 3827 | */ |
| 3828 | f_ordr = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3829 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3830 | if (llist->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3831 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 3832 | * state data |
| 3833 | */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3834 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3835 | continue; |
| 3836 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3837 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3838 | GETVAL(value, sub, "value"); |
| 3839 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3840 | llist->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3841 | } else if (strcmp(value, "system")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3842 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3843 | goto error; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3844 | } /* else system is the default value, so we can ignore it */ |
| 3845 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3846 | } else if (!strcmp(sub->name, "must")) { |
| 3847 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3848 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3849 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3850 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3851 | continue; |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3852 | } else if ((module->version >= 2) && !strcmp(sub->name, "default")) { |
| 3853 | c_dflt++; |
| 3854 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3855 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3856 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3857 | if (f_min) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3858 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3859 | goto error; |
| 3860 | } |
| 3861 | f_min = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3862 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3863 | GETVAL(value, sub, "value"); |
| 3864 | while (isspace(value[0])) { |
| 3865 | value++; |
| 3866 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3867 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3868 | /* convert it to uint32_t */ |
| 3869 | errno = 0; |
| 3870 | endptr = NULL; |
| 3871 | val = strtoul(value, &endptr, 10); |
| 3872 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3873 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3874 | goto error; |
| 3875 | } |
| 3876 | llist->min = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 3877 | if (llist->max && (llist->min > llist->max)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3878 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
| 3879 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"min-elements\" is bigger than \"max-elements\"."); |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 3880 | goto error; |
| 3881 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3882 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3883 | if (f_max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3884 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3885 | goto error; |
| 3886 | } |
| 3887 | f_max = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3888 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3889 | GETVAL(value, sub, "value"); |
| 3890 | while (isspace(value[0])) { |
| 3891 | value++; |
| 3892 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3893 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 3894 | if (!strcmp(value, "unbounded")) { |
| 3895 | llist->max = 0; |
| 3896 | } else { |
| 3897 | /* convert it to uint32_t */ |
| 3898 | errno = 0; |
| 3899 | endptr = NULL; |
| 3900 | val = strtoul(value, &endptr, 10); |
| 3901 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3902 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 3903 | goto error; |
| 3904 | } |
| 3905 | llist->max = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 3906 | if (llist->min > llist->max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3907 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
| 3908 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"max-elements\" is smaller than \"min-elements\"."); |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 3909 | goto error; |
| 3910 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3911 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3912 | } else if (!strcmp(sub->name, "when")) { |
| 3913 | if (llist->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3914 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3915 | goto error; |
| 3916 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3917 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3918 | llist->when = read_yin_when(module, sub); |
| 3919 | if (!llist->when) { |
| 3920 | goto error; |
| 3921 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3922 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3923 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3924 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3925 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3926 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3927 | /* 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] | 3928 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3929 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3930 | /* check constraints */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3931 | if (!has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3932 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3933 | goto error; |
| 3934 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3935 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3936 | /* middle part - process nodes with cardinality of 0..n */ |
| 3937 | if (c_must) { |
| 3938 | llist->must = calloc(c_must, sizeof *llist->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3939 | if (!llist->must) { |
| 3940 | LOGMEM; |
| 3941 | goto error; |
| 3942 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3943 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3944 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 3945 | llist->iffeature = calloc(c_ftrs, sizeof *llist->iffeature); |
| 3946 | if (!llist->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3947 | LOGMEM; |
| 3948 | goto error; |
| 3949 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3950 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3951 | if (c_dflt) { |
| 3952 | llist->dflt = calloc(c_dflt, sizeof *llist->dflt); |
| 3953 | if (!llist->dflt) { |
| 3954 | LOGMEM; |
| 3955 | goto error; |
| 3956 | } |
| 3957 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3958 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3959 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3960 | if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3961 | r = fill_yin_must(module, sub, &llist->must[llist->must_size]); |
| 3962 | llist->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3963 | if (r) { |
| 3964 | goto error; |
| 3965 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3966 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 3967 | r = fill_yin_iffeature(retval, sub, &llist->iffeature[llist->iffeature_size], unres); |
| 3968 | llist->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3969 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3970 | goto error; |
| 3971 | } |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3972 | } else if (!strcmp(sub->name, "default")) { |
| 3973 | GETVAL(value, sub, "value"); |
| 3974 | |
| 3975 | /* check for duplicity */ |
| 3976 | for (r = 0; r < llist->dflt_size; r++) { |
| 3977 | if (ly_strequal(llist->dflt[r], value, 1)) { |
| 3978 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 3979 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Duplicated default value \"%s\".", value); |
| 3980 | goto error; |
| 3981 | } |
| 3982 | } |
| 3983 | llist->dflt[llist->dflt_size++] = lydict_insert(module->ctx, value, strlen(value)); |
| 3984 | } |
| 3985 | } |
| 3986 | |
| 3987 | if (llist->dflt_size && llist->min) { |
Radek Krejci | 200bf71 | 2016-08-16 17:11:04 +0200 | [diff] [blame] | 3988 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "min-elements", "leaf-list"); |
Radek Krejci | d5a5c28 | 2016-08-15 15:38:08 +0200 | [diff] [blame] | 3989 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 3990 | "The \"min-elements\" statement with non-zero value is forbidden on leaf-lists with the \"default\" statement."); |
| 3991 | goto error; |
| 3992 | } |
| 3993 | |
| 3994 | /* check default value (if not defined, there still could be some restrictions |
| 3995 | * that need to be checked against a default value from a derived type) */ |
| 3996 | for (r = 0; r < llist->dflt_size; r++) { |
| 3997 | if (unres_schema_add_str(module, unres, &llist->type, UNRES_TYPE_DFLT, llist->dflt[r]) == -1) { |
| 3998 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3999 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4000 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4001 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4002 | /* check XPath dependencies */ |
| 4003 | if ((llist->when || llist->must_size) && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 4004 | goto error; |
| 4005 | } |
| 4006 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4007 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4008 | |
| 4009 | error: |
| 4010 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4011 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4012 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4013 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4014 | } |
| 4015 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4016 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4017 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4018 | read_yin_list(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 4019 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4020 | { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4021 | struct lys_node *retval, *node; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4022 | struct lys_node_list *list; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4023 | struct lyxml_elem *sub, *next, root, uniq; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4024 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4025 | int c_tpdf = 0, c_must = 0, c_uniq = 0, c_ftrs = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4026 | int f_ordr = 0, f_max = 0, f_min = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4027 | const char *key_str = NULL, *value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4028 | char *auxs; |
| 4029 | unsigned long val; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4030 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4031 | /* init */ |
| 4032 | memset(&root, 0, sizeof root); |
| 4033 | memset(&uniq, 0, sizeof uniq); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4034 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4035 | list = calloc(1, sizeof *list); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4036 | if (!list) { |
| 4037 | LOGMEM; |
| 4038 | return NULL; |
| 4039 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4040 | list->nodetype = LYS_LIST; |
| 4041 | list->prev = (struct lys_node *)list; |
| 4042 | retval = (struct lys_node *)list; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4043 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 4044 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 4045 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4046 | goto error; |
| 4047 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4048 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4049 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4050 | |
Radek Krejci | adb3065 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4051 | /* insert the node into the schema tree */ |
| 4052 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 4053 | goto error; |
| 4054 | } |
| 4055 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4056 | /* process list's specific children */ |
| 4057 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4058 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4059 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4060 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4061 | continue; |
| 4062 | } |
| 4063 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4064 | /* data statements */ |
| 4065 | if (!strcmp(sub->name, "container") || |
| 4066 | !strcmp(sub->name, "leaf-list") || |
| 4067 | !strcmp(sub->name, "leaf") || |
| 4068 | !strcmp(sub->name, "list") || |
| 4069 | !strcmp(sub->name, "choice") || |
| 4070 | !strcmp(sub->name, "uses") || |
| 4071 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 4072 | !strcmp(sub->name, "anyxml") || |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 4073 | !strcmp(sub->name, "action") || |
| 4074 | !strcmp(sub->name, "notification")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4075 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4076 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4077 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4078 | /* array counters */ |
| 4079 | } else if (!strcmp(sub->name, "key")) { |
| 4080 | /* check cardinality 0..1 */ |
| 4081 | if (list->keys_size) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4082 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, list->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4083 | goto error; |
| 4084 | } |
Radek Krejci | d7f0d01 | 2015-05-25 15:04:52 +0200 | [diff] [blame] | 4085 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4086 | /* count the number of keys */ |
| 4087 | GETVAL(value, sub, "value"); |
| 4088 | key_str = value; |
| 4089 | while ((value = strpbrk(value, " \t\n"))) { |
| 4090 | list->keys_size++; |
| 4091 | while (isspace(*value)) { |
| 4092 | value++; |
| 4093 | } |
| 4094 | } |
| 4095 | list->keys_size++; |
| 4096 | list->keys = calloc(list->keys_size, sizeof *list->keys); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4097 | if (!list->keys) { |
| 4098 | LOGMEM; |
| 4099 | goto error; |
| 4100 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4101 | } else if (!strcmp(sub->name, "unique")) { |
| 4102 | c_uniq++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4103 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4104 | lyxml_add_child(module->ctx, &uniq, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4105 | } else if (!strcmp(sub->name, "typedef")) { |
| 4106 | c_tpdf++; |
| 4107 | } else if (!strcmp(sub->name, "must")) { |
| 4108 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4109 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4110 | c_ftrs++; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 4111 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4112 | /* optional stetments */ |
| 4113 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 4114 | if (f_ordr) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4115 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4116 | goto error; |
| 4117 | } |
| 4118 | /* just checking the flags in llist is not sufficient, we would |
| 4119 | * allow multiple ordered-by statements with the "system" value |
| 4120 | */ |
| 4121 | f_ordr = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 4122 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4123 | if (list->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4124 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 4125 | * state data |
| 4126 | */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4127 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4128 | continue; |
| 4129 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 4130 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4131 | GETVAL(value, sub, "value"); |
| 4132 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4133 | list->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4134 | } else if (strcmp(value, "system")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4135 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4136 | goto error; |
| 4137 | } |
| 4138 | /* else system is the default value, so we can ignore it */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4139 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4140 | } else if (!strcmp(sub->name, "min-elements")) { |
| 4141 | if (f_min) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4142 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4143 | goto error; |
| 4144 | } |
| 4145 | f_min = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 4146 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4147 | GETVAL(value, sub, "value"); |
| 4148 | while (isspace(value[0])) { |
| 4149 | value++; |
| 4150 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 4151 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4152 | /* convert it to uint32_t */ |
| 4153 | errno = 0; |
| 4154 | auxs = NULL; |
| 4155 | val = strtoul(value, &auxs, 10); |
| 4156 | if (*auxs || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4157 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4158 | goto error; |
| 4159 | } |
| 4160 | list->min = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 4161 | if (list->max && (list->min > list->max)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4162 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
| 4163 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"min-elements\" is bigger than \"max-elements\"."); |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 4164 | lyxml_free(module->ctx, sub); |
| 4165 | goto error; |
| 4166 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4167 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4168 | } else if (!strcmp(sub->name, "max-elements")) { |
| 4169 | if (f_max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4170 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4171 | goto error; |
| 4172 | } |
| 4173 | f_max = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 4174 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4175 | GETVAL(value, sub, "value"); |
| 4176 | while (isspace(value[0])) { |
| 4177 | value++; |
| 4178 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 4179 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 4180 | if (!strcmp(value, "unbounded")) { |
| 4181 | list->max = 0;; |
| 4182 | } else { |
| 4183 | /* convert it to uint32_t */ |
| 4184 | errno = 0; |
| 4185 | auxs = NULL; |
| 4186 | val = strtoul(value, &auxs, 10); |
| 4187 | if (*auxs || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4188 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 4189 | goto error; |
| 4190 | } |
| 4191 | list->max = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 4192 | if (list->min > list->max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4193 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
| 4194 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "\"max-elements\" is smaller than \"min-elements\"."); |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 4195 | goto error; |
| 4196 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4197 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4198 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4199 | } else if (!strcmp(sub->name, "when")) { |
| 4200 | if (list->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4201 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4202 | goto error; |
| 4203 | } |
| 4204 | |
| 4205 | list->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4206 | if (!list->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4207 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4208 | goto error; |
| 4209 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4210 | lyxml_free(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4211 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4212 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4213 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4214 | } |
| 4215 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 4216 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4217 | /* check - if list is configuration, key statement is mandatory */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4218 | if ((list->flags & LYS_CONFIG_W) && !key_str) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4219 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "key", "list"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4220 | goto error; |
| 4221 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4222 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4223 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4224 | if (c_tpdf) { |
| 4225 | list->tpdf = calloc(c_tpdf, sizeof *list->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4226 | if (!list->tpdf) { |
| 4227 | LOGMEM; |
| 4228 | goto error; |
| 4229 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4230 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4231 | if (c_must) { |
| 4232 | list->must = calloc(c_must, sizeof *list->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4233 | if (!list->must) { |
| 4234 | LOGMEM; |
| 4235 | goto error; |
| 4236 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4237 | } |
| 4238 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4239 | list->iffeature = calloc(c_ftrs, sizeof *list->iffeature); |
| 4240 | if (!list->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4241 | LOGMEM; |
| 4242 | goto error; |
| 4243 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4244 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4245 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4246 | if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4247 | r = fill_yin_typedef(module, retval, sub, &list->tpdf[list->tpdf_size], unres); |
| 4248 | list->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4249 | if (r) { |
| 4250 | goto error; |
| 4251 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4252 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4253 | r = fill_yin_iffeature(retval, sub, &list->iffeature[list->iffeature_size], unres); |
| 4254 | list->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4255 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4256 | goto error; |
| 4257 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4258 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4259 | r = fill_yin_must(module, sub, &list->must[list->must_size]); |
| 4260 | list->must_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4261 | if (r) { |
| 4262 | goto error; |
| 4263 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4264 | } |
| 4265 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 4266 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4267 | /* last part - process data nodes */ |
| 4268 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4269 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4270 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4271 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4272 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4273 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4274 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4275 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4276 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4277 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4278 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4279 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 4280 | node = read_yin_uses(module, retval, sub, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4281 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4282 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4283 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4284 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, resolve, unres); |
| 4285 | } else if (!strcmp(sub->name, "anydata")) { |
| 4286 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, resolve, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 4287 | } else if (!strcmp(sub->name, "action")) { |
| 4288 | node = read_yin_rpc_action(module, retval, sub, resolve, unres); |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 4289 | } else if (!strcmp(sub->name, "notification")) { |
| 4290 | node = read_yin_notif(module, retval, sub, resolve, unres); |
Michal Vasko | c07187d | 2015-08-13 15:20:57 +0200 | [diff] [blame] | 4291 | } else { |
| 4292 | LOGINT; |
| 4293 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4294 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4295 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4296 | goto error; |
| 4297 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4298 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4299 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4300 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4301 | |
Radek Krejci | 461efb9 | 2016-02-12 15:52:18 +0100 | [diff] [blame] | 4302 | if (key_str) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4303 | if (unres_schema_add_str(module, unres, list, UNRES_LIST_KEYS, key_str) == -1) { |
Radek Krejci | 461efb9 | 2016-02-12 15:52:18 +0100 | [diff] [blame] | 4304 | goto error; |
| 4305 | } |
| 4306 | } /* 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] | 4307 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4308 | /* process unique statements */ |
| 4309 | if (c_uniq) { |
| 4310 | list->unique = calloc(c_uniq, sizeof *list->unique); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4311 | if (!list->unique) { |
| 4312 | LOGMEM; |
| 4313 | goto error; |
| 4314 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 4315 | |
Radek Krejci | 461efb9 | 2016-02-12 15:52:18 +0100 | [diff] [blame] | 4316 | LY_TREE_FOR_SAFE(uniq.child, next, sub) { |
| 4317 | r = fill_yin_unique(module, retval, sub, &list->unique[list->unique_size], unres); |
| 4318 | list->unique_size++; |
| 4319 | if (r) { |
| 4320 | goto error; |
| 4321 | } |
| 4322 | |
| 4323 | lyxml_free(module->ctx, sub); |
| 4324 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4325 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 4326 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4327 | /* check XPath dependencies */ |
| 4328 | if ((list->when || list->must_size) && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 4329 | goto error; |
| 4330 | } |
| 4331 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4332 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4333 | |
| 4334 | error: |
| 4335 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4336 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4337 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4338 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4339 | } |
| 4340 | while (uniq.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4341 | lyxml_free(module->ctx, uniq.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4342 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4343 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4344 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4345 | } |
| 4346 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4347 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4348 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4349 | read_yin_container(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 4350 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4351 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4352 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4353 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4354 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4355 | struct lys_node_container *cont; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4356 | const char *value; |
| 4357 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4358 | int c_tpdf = 0, c_must = 0, c_ftrs = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4359 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4360 | /* init */ |
| 4361 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4362 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4363 | cont = calloc(1, sizeof *cont); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4364 | if (!cont) { |
| 4365 | LOGMEM; |
| 4366 | return NULL; |
| 4367 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4368 | cont->nodetype = LYS_CONTAINER; |
| 4369 | cont->prev = (struct lys_node *)cont; |
| 4370 | retval = (struct lys_node *)cont; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4371 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 4372 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 4373 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4374 | goto error; |
| 4375 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4376 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4377 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4378 | |
Radek Krejci | adb3065 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4379 | /* insert the node into the schema tree */ |
| 4380 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 4381 | goto error; |
| 4382 | } |
| 4383 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4384 | /* process container's specific children */ |
| 4385 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 4386 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4387 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4388 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4389 | continue; |
| 4390 | } |
| 4391 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4392 | if (!strcmp(sub->name, "presence")) { |
| 4393 | if (cont->presence) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4394 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4395 | goto error; |
| 4396 | } |
| 4397 | GETVAL(value, sub, "value"); |
| 4398 | cont->presence = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 4399 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4400 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4401 | } else if (!strcmp(sub->name, "when")) { |
| 4402 | if (cont->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4403 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4404 | goto error; |
| 4405 | } |
| 4406 | |
| 4407 | cont->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4408 | if (!cont->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4409 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4410 | goto error; |
| 4411 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4412 | lyxml_free(module->ctx, sub); |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 4413 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4414 | /* data statements */ |
| 4415 | } else if (!strcmp(sub->name, "container") || |
| 4416 | !strcmp(sub->name, "leaf-list") || |
| 4417 | !strcmp(sub->name, "leaf") || |
| 4418 | !strcmp(sub->name, "list") || |
| 4419 | !strcmp(sub->name, "choice") || |
| 4420 | !strcmp(sub->name, "uses") || |
| 4421 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 4422 | !strcmp(sub->name, "anyxml") || |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 4423 | !strcmp(sub->name, "action") || |
| 4424 | !strcmp(sub->name, "notification")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4425 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4426 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4427 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4428 | /* array counters */ |
| 4429 | } else if (!strcmp(sub->name, "typedef")) { |
| 4430 | c_tpdf++; |
| 4431 | } else if (!strcmp(sub->name, "must")) { |
| 4432 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4433 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4434 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4435 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4436 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4437 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4438 | } |
| 4439 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4440 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4441 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4442 | if (c_tpdf) { |
| 4443 | cont->tpdf = calloc(c_tpdf, sizeof *cont->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4444 | if (!cont->tpdf) { |
| 4445 | LOGMEM; |
| 4446 | goto error; |
| 4447 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4448 | } |
| 4449 | if (c_must) { |
| 4450 | cont->must = calloc(c_must, sizeof *cont->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4451 | if (!cont->must) { |
| 4452 | LOGMEM; |
| 4453 | goto error; |
| 4454 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4455 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4456 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4457 | cont->iffeature = calloc(c_ftrs, sizeof *cont->iffeature); |
| 4458 | if (!cont->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4459 | LOGMEM; |
| 4460 | goto error; |
| 4461 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4462 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 4463 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4464 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4465 | if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4466 | r = fill_yin_typedef(module, retval, sub, &cont->tpdf[cont->tpdf_size], unres); |
| 4467 | cont->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4468 | if (r) { |
| 4469 | goto error; |
| 4470 | } |
| 4471 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4472 | r = fill_yin_must(module, sub, &cont->must[cont->must_size]); |
| 4473 | cont->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4474 | if (r) { |
| 4475 | goto error; |
| 4476 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4477 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4478 | r = fill_yin_iffeature(retval, sub, &cont->iffeature[cont->iffeature_size], unres); |
| 4479 | cont->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4480 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4481 | goto error; |
| 4482 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4483 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4484 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4485 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4486 | /* last part - process data nodes */ |
| 4487 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4488 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4489 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4490 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4491 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4492 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4493 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4494 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4495 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4496 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4497 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4498 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 4499 | node = read_yin_uses(module, retval, sub, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4500 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4501 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4502 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4503 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, resolve, unres); |
| 4504 | } else if (!strcmp(sub->name, "anydata")) { |
| 4505 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, resolve, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 4506 | } else if (!strcmp(sub->name, "action")) { |
| 4507 | node = read_yin_rpc_action(module, retval, sub, resolve, unres); |
Michal Vasko | b4c608c | 2016-09-15 09:36:20 +0200 | [diff] [blame] | 4508 | } else if (!strcmp(sub->name, "notification")) { |
| 4509 | node = read_yin_notif(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4510 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4511 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4512 | goto error; |
| 4513 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4514 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4515 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4516 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4517 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4518 | /* check XPath dependencies */ |
| 4519 | if ((cont->when || cont->must_size) && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 4520 | goto error; |
| 4521 | } |
| 4522 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4523 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4524 | |
| 4525 | error: |
| 4526 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4527 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4528 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4529 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4530 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4531 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4532 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4533 | } |
| 4534 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4535 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4536 | static struct lys_node * |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4537 | read_yin_grouping(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4538 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4539 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4540 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4541 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4542 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4543 | struct lys_node_grp *grp; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4544 | int r; |
| 4545 | int c_tpdf = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4546 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4547 | /* init */ |
| 4548 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4549 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4550 | grp = calloc(1, sizeof *grp); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4551 | if (!grp) { |
| 4552 | LOGMEM; |
| 4553 | return NULL; |
| 4554 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4555 | grp->nodetype = LYS_GROUPING; |
| 4556 | grp->prev = (struct lys_node *)grp; |
| 4557 | retval = (struct lys_node *)grp; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4558 | |
Michal Vasko | 71e1aa8 | 2015-08-12 12:17:51 +0200 | [diff] [blame] | 4559 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4560 | goto error; |
| 4561 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4562 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4563 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4564 | |
Radek Krejci | adb3065 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4565 | /* insert the node into the schema tree */ |
| 4566 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 4567 | goto error; |
| 4568 | } |
| 4569 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4570 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4571 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4572 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4573 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4574 | continue; |
| 4575 | } |
| 4576 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4577 | /* data statements */ |
| 4578 | if (!strcmp(sub->name, "container") || |
| 4579 | !strcmp(sub->name, "leaf-list") || |
| 4580 | !strcmp(sub->name, "leaf") || |
| 4581 | !strcmp(sub->name, "list") || |
| 4582 | !strcmp(sub->name, "choice") || |
| 4583 | !strcmp(sub->name, "uses") || |
| 4584 | !strcmp(sub->name, "grouping") || |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 4585 | !strcmp(sub->name, "anyxml") || |
| 4586 | !strcmp(sub->name, "action")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4587 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4588 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4589 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4590 | /* array counters */ |
| 4591 | } else if (!strcmp(sub->name, "typedef")) { |
| 4592 | c_tpdf++; |
| 4593 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4594 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4595 | goto error; |
| 4596 | } |
| 4597 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4598 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4599 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4600 | if (c_tpdf) { |
| 4601 | grp->tpdf = calloc(c_tpdf, sizeof *grp->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4602 | if (!grp->tpdf) { |
| 4603 | LOGMEM; |
| 4604 | goto error; |
| 4605 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4606 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4607 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4608 | r = fill_yin_typedef(module, retval, sub, &grp->tpdf[grp->tpdf_size], unres); |
| 4609 | grp->tpdf_size++; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4610 | if (r) { |
| 4611 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4612 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4613 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4614 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4615 | /* last part - process data nodes */ |
Michal Vasko | 919dbbc | 2016-05-19 15:22:45 +0200 | [diff] [blame] | 4616 | if (!root.child) { |
| 4617 | LOGWRN("Grouping \"%s\" without children.", retval->name); |
| 4618 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4619 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4620 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4621 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4622 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4623 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4624 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4625 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4626 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4627 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4628 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4629 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4630 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 4631 | node = read_yin_uses(module, retval, sub, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4632 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4633 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4634 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4635 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, resolve, unres); |
| 4636 | } else if (!strcmp(sub->name, "anydata")) { |
| 4637 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, resolve, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 4638 | } else if (!strcmp(sub->name, "action")) { |
| 4639 | node = read_yin_rpc_action(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4640 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4641 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4642 | goto error; |
| 4643 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4644 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4645 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4646 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4647 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4648 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4649 | |
| 4650 | error: |
| 4651 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4652 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4653 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4654 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4655 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4656 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4657 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4658 | } |
| 4659 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4660 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4661 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4662 | read_yin_input_output(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 4663 | struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4664 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4665 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4666 | struct lys_node *node = NULL; |
Radek Krejci | 31fc30d | 2015-08-13 08:27:38 +0200 | [diff] [blame] | 4667 | struct lys_node *retval = NULL; |
Michal Vasko | 44fb638 | 2016-06-29 11:12:27 +0200 | [diff] [blame] | 4668 | struct lys_node_inout *inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4669 | int r; |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 4670 | int c_tpdf = 0, c_must = 0; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4671 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4672 | /* init */ |
| 4673 | memset(&root, 0, sizeof root); |
| 4674 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4675 | inout = calloc(1, sizeof *inout); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4676 | if (!inout) { |
| 4677 | LOGMEM; |
| 4678 | return NULL; |
| 4679 | } |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 4680 | inout->prev = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4681 | |
| 4682 | if (!strcmp(yin->name, "input")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4683 | inout->nodetype = LYS_INPUT; |
Michal Vasko | 0a1aaa4 | 2016-04-19 09:48:25 +0200 | [diff] [blame] | 4684 | inout->name = lydict_insert(module->ctx, "input", 0); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4685 | } else if (!strcmp(yin->name, "output")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4686 | inout->nodetype = LYS_OUTPUT; |
Michal Vasko | 0a1aaa4 | 2016-04-19 09:48:25 +0200 | [diff] [blame] | 4687 | inout->name = lydict_insert(module->ctx, "output", 0); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4688 | } else { |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 4689 | LOGINT; |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 4690 | free(inout); |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 4691 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4692 | } |
| 4693 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4694 | retval = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4695 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4696 | if (read_yin_common(module, parent, retval, yin, OPT_MODULE | OPT_NACMEXT)) { |
Michal Vasko | ebeac94 | 2015-06-15 12:11:50 +0200 | [diff] [blame] | 4697 | goto error; |
| 4698 | } |
| 4699 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4700 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4701 | |
Radek Krejci | adb3065 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4702 | /* insert the node into the schema tree */ |
| 4703 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 4704 | goto error; |
| 4705 | } |
| 4706 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4707 | /* data statements */ |
| 4708 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4709 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4710 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4711 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4712 | continue; |
| 4713 | } |
| 4714 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4715 | if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4716 | !strcmp(sub->name, "leaf-list") || |
| 4717 | !strcmp(sub->name, "leaf") || |
| 4718 | !strcmp(sub->name, "list") || |
| 4719 | !strcmp(sub->name, "choice") || |
| 4720 | !strcmp(sub->name, "uses") || |
| 4721 | !strcmp(sub->name, "grouping") || |
| 4722 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4723 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4724 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4725 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4726 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4727 | } else if (!strcmp(sub->name, "typedef")) { |
| 4728 | c_tpdf++; |
Radek Krejci | d2bfa79 | 2015-07-02 16:45:29 +0200 | [diff] [blame] | 4729 | |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 4730 | } else if ((module->version >= 2) && !strcmp(sub->name, "must")) { |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 4731 | c_must++; |
| 4732 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4733 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4734 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4735 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4736 | } |
| 4737 | } |
| 4738 | |
| 4739 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4740 | if (c_tpdf) { |
| 4741 | inout->tpdf = calloc(c_tpdf, sizeof *inout->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4742 | if (!inout->tpdf) { |
| 4743 | LOGMEM; |
| 4744 | goto error; |
| 4745 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4746 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 4747 | if (c_must) { |
| 4748 | inout->must = calloc(c_must, sizeof *inout->must); |
| 4749 | if (!inout->must) { |
| 4750 | LOGMEM; |
| 4751 | goto error; |
| 4752 | } |
| 4753 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4754 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4755 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 4756 | if (!strcmp(sub->name, "must")) { |
| 4757 | r = fill_yin_must(module, sub, &inout->must[inout->must_size]); |
| 4758 | inout->must_size++; |
| 4759 | if (r) { |
| 4760 | goto error; |
| 4761 | } |
| 4762 | } else { /* typedef */ |
| 4763 | r = fill_yin_typedef(module, retval, sub, &inout->tpdf[inout->tpdf_size], unres); |
| 4764 | inout->tpdf_size++; |
| 4765 | if (r) { |
| 4766 | goto error; |
| 4767 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4768 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4769 | } |
| 4770 | |
| 4771 | /* last part - process data nodes */ |
| 4772 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4773 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4774 | node = read_yin_container(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4775 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4776 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4777 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4778 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4779 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4780 | node = read_yin_list(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4781 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4782 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4783 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 4784 | node = read_yin_uses(module, retval, sub, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4785 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4786 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4787 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4788 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, resolve, unres); |
| 4789 | } else if (!strcmp(sub->name, "anydata")) { |
| 4790 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4791 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4792 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4793 | goto error; |
| 4794 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4795 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4796 | lyxml_free(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4797 | } |
| 4798 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4799 | /* check XPath dependencies */ |
| 4800 | if (inout->must_size && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 4801 | goto error; |
| 4802 | } |
| 4803 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4804 | return retval; |
| 4805 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4806 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4807 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4808 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 4809 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4810 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4811 | } |
| 4812 | |
| 4813 | return NULL; |
| 4814 | } |
| 4815 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4816 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4817 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4818 | read_yin_notif(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 4819 | struct unres_schema *unres) |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4820 | { |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 4821 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4822 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4823 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4824 | struct lys_node_notif *notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4825 | int r; |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 4826 | int c_tpdf = 0, c_ftrs = 0, c_must = 0; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4827 | |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 4828 | memset(&root, 0, sizeof root); |
| 4829 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4830 | notif = calloc(1, sizeof *notif); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4831 | if (!notif) { |
| 4832 | LOGMEM; |
| 4833 | return NULL; |
| 4834 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4835 | notif->nodetype = LYS_NOTIF; |
| 4836 | notif->prev = (struct lys_node *)notif; |
| 4837 | retval = (struct lys_node *)notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4838 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4839 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_NACMEXT)) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4840 | goto error; |
| 4841 | } |
| 4842 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4843 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4844 | |
Radek Krejci | adb3065 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 4845 | /* insert the node into the schema tree */ |
| 4846 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 4847 | goto error; |
| 4848 | } |
| 4849 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4850 | /* process rpc's specific children */ |
| 4851 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4852 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4853 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4854 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4855 | continue; |
| 4856 | } |
| 4857 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4858 | /* data statements */ |
| 4859 | if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4860 | !strcmp(sub->name, "leaf-list") || |
| 4861 | !strcmp(sub->name, "leaf") || |
| 4862 | !strcmp(sub->name, "list") || |
| 4863 | !strcmp(sub->name, "choice") || |
| 4864 | !strcmp(sub->name, "uses") || |
| 4865 | !strcmp(sub->name, "grouping") || |
| 4866 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4867 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4868 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4869 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4870 | /* array counters */ |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4871 | } else if (!strcmp(sub->name, "typedef")) { |
| 4872 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4873 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4874 | c_ftrs++; |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 4875 | } else if ((module->version >= 2) && !strcmp(sub->name, "must")) { |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 4876 | c_must++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4877 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4878 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4879 | goto error; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4880 | } |
| 4881 | } |
| 4882 | |
| 4883 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4884 | if (c_tpdf) { |
| 4885 | notif->tpdf = calloc(c_tpdf, sizeof *notif->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4886 | if (!notif->tpdf) { |
| 4887 | LOGMEM; |
| 4888 | goto error; |
| 4889 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4890 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4891 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4892 | notif->iffeature = calloc(c_ftrs, sizeof *notif->iffeature); |
| 4893 | if (!notif->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4894 | LOGMEM; |
| 4895 | goto error; |
| 4896 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4897 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 4898 | if (c_must) { |
| 4899 | notif->must = calloc(c_must, sizeof *notif->must); |
| 4900 | if (!notif->must) { |
| 4901 | LOGMEM; |
| 4902 | goto error; |
| 4903 | } |
| 4904 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4905 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4906 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4907 | if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4908 | r = fill_yin_typedef(module, retval, sub, ¬if->tpdf[notif->tpdf_size], unres); |
| 4909 | notif->tpdf_size++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4910 | if (r) { |
| 4911 | goto error; |
| 4912 | } |
Radek Krejci | 9629915 | 2016-06-22 10:17:50 +0200 | [diff] [blame] | 4913 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 4914 | r = fill_yin_iffeature(retval, sub, ¬if->iffeature[notif->iffeature_size], unres); |
| 4915 | notif->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4916 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4917 | goto error; |
| 4918 | } |
Radek Krejci | 1933280 | 2016-07-29 10:39:46 +0200 | [diff] [blame] | 4919 | } else if (!strcmp(sub->name, "must")) { |
| 4920 | r = fill_yin_must(module, sub, ¬if->must[notif->must_size]); |
| 4921 | notif->must_size++; |
| 4922 | if (r) { |
| 4923 | goto error; |
| 4924 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4925 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4926 | } |
| 4927 | |
| 4928 | /* last part - process data nodes */ |
| 4929 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4930 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4931 | node = read_yin_container(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4932 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4933 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4934 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4935 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4936 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4937 | node = read_yin_list(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4938 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4939 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4940 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 4941 | node = read_yin_uses(module, retval, sub, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4942 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4943 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4944 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 4945 | node = read_yin_anydata(module, retval, sub, LYS_ANYXML, resolve, unres); |
| 4946 | } else if (!strcmp(sub->name, "anydata")) { |
| 4947 | node = read_yin_anydata(module, retval, sub, LYS_ANYDATA, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4948 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4949 | if (!node) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4950 | goto error; |
| 4951 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4952 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4953 | lyxml_free(module->ctx, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4954 | } |
| 4955 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 4956 | /* check XPath dependencies */ |
| 4957 | if (notif->must_size && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 4958 | goto error; |
| 4959 | } |
| 4960 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4961 | return retval; |
| 4962 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4963 | error: |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4964 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4965 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4966 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4967 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4968 | } |
| 4969 | |
| 4970 | return NULL; |
| 4971 | } |
| 4972 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4973 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4974 | static struct lys_node * |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 4975 | read_yin_rpc_action(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 4976 | struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4977 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4978 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4979 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4980 | struct lys_node *retval; |
Michal Vasko | 44fb638 | 2016-06-29 11:12:27 +0200 | [diff] [blame] | 4981 | struct lys_node_rpc_action *rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4982 | int r; |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 4983 | int c_tpdf = 0, c_ftrs = 0, c_input = 0, c_output = 0; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4984 | |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 4985 | if (!strcmp(yin->name, "action")) { |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 4986 | if (module->version < 2) { |
Michal Vasko | bb17485 | 2016-07-25 11:00:21 +0200 | [diff] [blame] | 4987 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "action"); |
| 4988 | return NULL; |
| 4989 | } |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 4990 | for (node = parent; node; node = lys_parent(node)) { |
| 4991 | if (node->nodetype & (LYS_RPC | LYS_ACTION | LYS_NOTIF) |
| 4992 | || ((node->nodetype == LYS_LIST) && !((struct lys_node_list *)node)->keys_size)) { |
| 4993 | LOGVAL(LYE_INPAR, LY_VLOG_NONE, NULL, strnodetype(node->nodetype), "action"); |
| 4994 | return NULL; |
| 4995 | } |
| 4996 | } |
| 4997 | } |
| 4998 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4999 | /* init */ |
| 5000 | memset(&root, 0, sizeof root); |
| 5001 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5002 | rpc = calloc(1, sizeof *rpc); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5003 | if (!rpc) { |
| 5004 | LOGMEM; |
| 5005 | return NULL; |
| 5006 | } |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5007 | rpc->nodetype = (!strcmp(yin->name, "rpc") ? LYS_RPC : LYS_ACTION); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5008 | rpc->prev = (struct lys_node *)rpc; |
| 5009 | retval = (struct lys_node *)rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5010 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 5011 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_NACMEXT)) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5012 | goto error; |
| 5013 | } |
| 5014 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5015 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 5016 | |
Radek Krejci | adb3065 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5017 | /* insert the node into the schema tree */ |
| 5018 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5019 | goto error; |
| 5020 | } |
| 5021 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5022 | /* process rpc's specific children */ |
| 5023 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5024 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 5025 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5026 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5027 | continue; |
| 5028 | } |
| 5029 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5030 | if (!strcmp(sub->name, "input")) { |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 5031 | if (c_input) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5032 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5033 | goto error; |
| 5034 | } |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 5035 | c_input++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5036 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5037 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5038 | } else if (!strcmp(sub->name, "output")) { |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 5039 | if (c_output) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5040 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5041 | goto error; |
| 5042 | } |
Pavol Vican | 3cb70c7 | 2016-09-05 11:32:52 +0200 | [diff] [blame] | 5043 | c_output++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5044 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5045 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5046 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5047 | /* data statements */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5048 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 5049 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 5050 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5051 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5052 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5053 | } else if (!strcmp(sub->name, "typedef")) { |
| 5054 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5055 | } else if (!strcmp(sub->name, "if-feature")) { |
| 5056 | c_ftrs++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5057 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5058 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5059 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5060 | } |
| 5061 | } |
| 5062 | |
| 5063 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 5064 | if (c_tpdf) { |
| 5065 | rpc->tpdf = calloc(c_tpdf, sizeof *rpc->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5066 | if (!rpc->tpdf) { |
| 5067 | LOGMEM; |
| 5068 | goto error; |
| 5069 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5070 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5071 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5072 | rpc->iffeature = calloc(c_ftrs, sizeof *rpc->iffeature); |
| 5073 | if (!rpc->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5074 | LOGMEM; |
| 5075 | goto error; |
| 5076 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5077 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5078 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5079 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5080 | if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5081 | r = fill_yin_typedef(module, retval, sub, &rpc->tpdf[rpc->tpdf_size], unres); |
| 5082 | rpc->tpdf_size++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5083 | if (r) { |
| 5084 | goto error; |
| 5085 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5086 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5087 | r = fill_yin_iffeature(retval, sub, &rpc->iffeature[rpc->iffeature_size], unres); |
| 5088 | rpc->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 5089 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 5090 | goto error; |
| 5091 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5092 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5093 | } |
| 5094 | |
| 5095 | /* last part - process data nodes */ |
| 5096 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 5097 | if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5098 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5099 | } else if (!strcmp(sub->name, "input") || !strcmp(sub->name, "output")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5100 | node = read_yin_input_output(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5101 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5102 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5103 | goto error; |
| 5104 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 5105 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5106 | lyxml_free(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5107 | } |
| 5108 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5109 | return retval; |
| 5110 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5111 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5112 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5113 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 5114 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5115 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5116 | } |
| 5117 | |
| 5118 | return NULL; |
| 5119 | } |
| 5120 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5121 | /* logs directly |
| 5122 | * |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 5123 | * resolve - referenced grouping should be bounded to the namespace (resolved) |
| 5124 | * only when uses does not appear in grouping. In a case of grouping's uses, |
| 5125 | * we just get information but we do not apply augment or refine to it. |
| 5126 | */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5127 | static struct lys_node * |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 5128 | read_yin_uses(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct unres_schema *unres) |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 5129 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5130 | struct lyxml_elem *sub, *next; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5131 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5132 | struct lys_node_uses *uses; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5133 | const char *value; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5134 | int c_ref = 0, c_aug = 0, c_ftrs = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5135 | int r; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 5136 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5137 | uses = calloc(1, sizeof *uses); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5138 | if (!uses) { |
| 5139 | LOGMEM; |
| 5140 | return NULL; |
| 5141 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 5142 | uses->nodetype = LYS_USES; |
| 5143 | uses->prev = (struct lys_node *)uses; |
| 5144 | retval = (struct lys_node *)uses; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 5145 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5146 | GETVAL(value, yin, "name"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5147 | uses->name = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 5148 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 5149 | if (read_yin_common(module, parent, retval, yin, OPT_MODULE |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 5150 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5151 | goto error; |
| 5152 | } |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 5153 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5154 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 5155 | |
Radek Krejci | adb3065 | 2016-07-11 15:27:07 +0200 | [diff] [blame] | 5156 | /* insert the node into the schema tree */ |
| 5157 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
| 5158 | goto error; |
| 5159 | } |
| 5160 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5161 | /* get other properties of uses */ |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5162 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5163 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 5164 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5165 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5166 | continue; |
| 5167 | } |
| 5168 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5169 | if (!strcmp(sub->name, "refine")) { |
| 5170 | c_ref++; |
| 5171 | } else if (!strcmp(sub->name, "augment")) { |
| 5172 | c_aug++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5173 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 56e8977 | 2015-06-19 10:00:54 +0200 | [diff] [blame] | 5174 | c_ftrs++; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5175 | } else if (!strcmp(sub->name, "when")) { |
| 5176 | if (uses->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5177 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5178 | goto error; |
| 5179 | } |
| 5180 | |
| 5181 | uses->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5182 | if (!uses->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5183 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 5184 | goto error; |
| 5185 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5186 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5187 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5188 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5189 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5190 | } |
| 5191 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 5192 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5193 | /* process properties with cardinality 0..n */ |
| 5194 | if (c_ref) { |
| 5195 | uses->refine = calloc(c_ref, sizeof *uses->refine); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5196 | if (!uses->refine) { |
| 5197 | LOGMEM; |
| 5198 | goto error; |
| 5199 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5200 | } |
| 5201 | if (c_aug) { |
| 5202 | uses->augment = calloc(c_aug, sizeof *uses->augment); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5203 | if (!uses->augment) { |
| 5204 | LOGMEM; |
| 5205 | goto error; |
| 5206 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5207 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5208 | if (c_ftrs) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5209 | uses->iffeature = calloc(c_ftrs, sizeof *uses->iffeature); |
| 5210 | if (!uses->iffeature) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5211 | LOGMEM; |
| 5212 | goto error; |
| 5213 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5214 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 5215 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 5216 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5217 | if (!strcmp(sub->name, "refine")) { |
Radek Krejci | 363bd4a | 2016-07-29 14:30:20 +0200 | [diff] [blame] | 5218 | r = fill_yin_refine(retval, sub, &uses->refine[uses->refine_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5219 | uses->refine_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 5220 | if (r) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5221 | goto error; |
| 5222 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 5223 | } else if (!strcmp(sub->name, "augment")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 5224 | r = fill_yin_augment(module, retval, sub, &uses->augment[uses->augment_size], unres); |
| 5225 | uses->augment_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 5226 | if (r) { |
| 5227 | goto error; |
| 5228 | } |
| 5229 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | c5c26b0 | 2016-06-29 11:10:29 +0200 | [diff] [blame] | 5230 | r = fill_yin_iffeature(retval, sub, &uses->iffeature[uses->iffeature_size], unres); |
| 5231 | uses->iffeature_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 5232 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 5233 | goto error; |
| 5234 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5235 | } |
| 5236 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 5237 | |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5238 | if (unres_schema_add_node(module, unres, uses, UNRES_USES, NULL) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 5239 | goto error; |
| 5240 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 5241 | |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 5242 | /* check XPath dependencies */ |
| 5243 | if (uses->when && (unres_schema_add_node(module, unres, retval, UNRES_XPATH, NULL) == -1)) { |
| 5244 | goto error; |
| 5245 | } |
| 5246 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5247 | return retval; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 5248 | |
| 5249 | error: |
| 5250 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 5251 | lys_node_free(retval, NULL, 0); |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 5252 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5253 | return NULL; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 5254 | } |
| 5255 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5256 | /* logs directly |
| 5257 | * |
| 5258 | * common code for yin_read_module() and yin_read_submodule() |
| 5259 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5260 | static int |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5261 | read_sub_module(struct lys_module *module, struct lys_submodule *submodule, struct lyxml_elem *yin, |
| 5262 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5263 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5264 | struct ly_ctx *ctx = module->ctx; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5265 | struct lyxml_elem *next, *child, *child2, root, grps, augs; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5266 | struct lys_node *node = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5267 | struct lys_module *trg; |
Pavol Vican | 974377b | 2016-03-23 00:38:53 +0100 | [diff] [blame] | 5268 | struct lys_include inc; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5269 | const char *value; |
Pavol Vican | 974377b | 2016-03-23 00:38:53 +0100 | [diff] [blame] | 5270 | int i, r; |
Radek Krejci | 4dcd339 | 2016-06-22 10:28:40 +0200 | [diff] [blame] | 5271 | size_t size; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5272 | int version_flag = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5273 | /* counters */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 5274 | 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; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5275 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5276 | /* to simplify code, store the module/submodule being processed as trg */ |
Michal Vasko | fe7e5a7 | 2016-05-02 14:49:23 +0200 | [diff] [blame] | 5277 | trg = submodule ? (struct lys_module *)submodule : module; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5278 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5279 | /* init */ |
| 5280 | memset(&root, 0, sizeof root); |
| 5281 | memset(&grps, 0, sizeof grps); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5282 | memset(&augs, 0, sizeof augs); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 5283 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5284 | /* |
| 5285 | * in the first run, we process elements with cardinality of 1 or 0..1 and |
| 5286 | * count elements with cardinality 0..n. Data elements (choices, containers, |
| 5287 | * leafs, lists, leaf-lists) are moved aside to be processed last, since we |
| 5288 | * need have all top-level and groupings already prepared at that time. In |
| 5289 | * the middle loop, we process other elements with carinality of 0..n since |
| 5290 | * we need to allocate arrays to store them. |
| 5291 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5292 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 5293 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 5294 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5295 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5296 | continue; |
| 5297 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5298 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5299 | if (!submodule && !strcmp(child->name, "namespace")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5300 | if (module->ns) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5301 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5302 | goto error; |
| 5303 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5304 | GETVAL(value, child, "uri"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5305 | module->ns = lydict_insert(ctx, value, strlen(value)); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5306 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5307 | } else if (!submodule && !strcmp(child->name, "prefix")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5308 | if (module->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5309 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5310 | goto error; |
| 5311 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5312 | GETVAL(value, child, "value"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5313 | if (lyp_check_identifier(value, LY_IDENT_PREFIX, module, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5314 | goto error; |
| 5315 | } |
| 5316 | module->prefix = lydict_insert(ctx, value, strlen(value)); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5317 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5318 | } else if (submodule && !strcmp(child->name, "belongs-to")) { |
| 5319 | if (submodule->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5320 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5321 | goto error; |
| 5322 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5323 | GETVAL(value, child, "module"); |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 5324 | if (!ly_strequal(value, submodule->belongsto->name, 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5325 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5326 | goto error; |
| 5327 | } |
Radek Krejci | f388693 | 2015-06-04 17:36:06 +0200 | [diff] [blame] | 5328 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5329 | /* get the prefix substatement, start with checks */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5330 | if (!child->child) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5331 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5332 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5333 | } else if (strcmp(child->child->name, "prefix")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5334 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5335 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5336 | } else if (child->child->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5337 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->child->next->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5338 | goto error; |
| 5339 | } |
| 5340 | /* and now finally get the value */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5341 | GETVAL(value, child->child, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5342 | /* check here differs from a generic prefix check, since this prefix |
| 5343 | * don't have to be unique |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5344 | */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5345 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5346 | goto error; |
| 5347 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5348 | submodule->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 0af1387 | 2015-05-30 11:50:52 +0200 | [diff] [blame] | 5349 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5350 | /* we are done with belongs-to */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5351 | lyxml_free(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 5352 | |
| 5353 | /* counters (statements with n..1 cardinality) */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5354 | } else if (!strcmp(child->name, "import")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5355 | c_imp++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5356 | } else if (!strcmp(child->name, "revision")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5357 | c_rev++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5358 | } else if (!strcmp(child->name, "typedef")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5359 | c_tpdf++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5360 | } else if (!strcmp(child->name, "identity")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5361 | c_ident++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5362 | } else if (!strcmp(child->name, "include")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5363 | c_inc++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5364 | } else if (!strcmp(child->name, "augment")) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5365 | c_aug++; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5366 | /* keep augments separated, processed last */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5367 | lyxml_unlink_elem(ctx, child, 2); |
| 5368 | lyxml_add_child(ctx, &augs, child); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5369 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5370 | } else if (!strcmp(child->name, "feature")) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5371 | c_ftrs++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5372 | } else if (!strcmp(child->name, "deviation")) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 5373 | c_dev++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5374 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5375 | /* data statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5376 | } else if (!strcmp(child->name, "container") || |
| 5377 | !strcmp(child->name, "leaf-list") || |
| 5378 | !strcmp(child->name, "leaf") || |
| 5379 | !strcmp(child->name, "list") || |
| 5380 | !strcmp(child->name, "choice") || |
| 5381 | !strcmp(child->name, "uses") || |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 5382 | !strcmp(child->name, "anyxml") || |
| 5383 | !strcmp(child->name, "rpc") || |
| 5384 | !strcmp(child->name, "notification")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5385 | lyxml_unlink_elem(ctx, child, 2); |
| 5386 | lyxml_add_child(ctx, &root, child); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 5387 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5388 | } else if (!strcmp(child->name, "grouping")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5389 | /* keep groupings separated and process them before other data statements */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5390 | lyxml_unlink_elem(ctx, child, 2); |
| 5391 | lyxml_add_child(ctx, &grps, child); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5392 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5393 | /* optional statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5394 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5395 | if (trg->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5396 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5397 | goto error; |
| 5398 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5399 | trg->dsc = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5400 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5401 | if (!trg->dsc) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5402 | goto error; |
| 5403 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5404 | } else if (!strcmp(child->name, "reference")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5405 | if (trg->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5406 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5407 | goto error; |
| 5408 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5409 | trg->ref = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5410 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5411 | if (!trg->ref) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5412 | goto error; |
| 5413 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5414 | } else if (!strcmp(child->name, "organization")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5415 | if (trg->org) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5416 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5417 | goto error; |
| 5418 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5419 | trg->org = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5420 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5421 | if (!trg->org) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5422 | goto error; |
| 5423 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5424 | } else if (!strcmp(child->name, "contact")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5425 | if (trg->contact) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5426 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5427 | goto error; |
| 5428 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5429 | trg->contact = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5430 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5431 | if (!trg->contact) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5432 | goto error; |
| 5433 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5434 | } else if (!strcmp(child->name, "yang-version")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5435 | if (version_flag) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5436 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5437 | goto error; |
| 5438 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5439 | GETVAL(value, child, "value"); |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 5440 | if (strcmp(value, "1") && strcmp(value, "1.1")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5441 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "yang-version"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5442 | goto error; |
| 5443 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5444 | version_flag = 1; |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 5445 | if (!strcmp(value, "1")) { |
| 5446 | if (submodule) { |
| 5447 | if (module->version > 1) { |
| 5448 | LOGVAL(LYE_INVER, LY_VLOG_NONE, NULL); |
| 5449 | goto error; |
| 5450 | } |
| 5451 | } else { |
| 5452 | module->version = 1; |
| 5453 | } |
| 5454 | } else { |
| 5455 | if (submodule) { |
Radek Krejci | 1a31efe | 2016-07-29 11:04:16 +0200 | [diff] [blame] | 5456 | if (module->version < 2) { |
Michal Vasko | 88de3e4 | 2016-06-29 11:05:32 +0200 | [diff] [blame] | 5457 | LOGVAL(LYE_INVER, LY_VLOG_NONE, NULL); |
| 5458 | goto error; |
| 5459 | } |
| 5460 | } else { |
| 5461 | module->version = 2; |
| 5462 | } |
| 5463 | } |
| 5464 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5465 | lyxml_free(ctx, child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5466 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5467 | } else if (!strcmp(child->name, "extension")) { |
| 5468 | GETVAL(value, child, "name"); |
Radek Krejci | 5166a89 | 2015-07-02 16:44:24 +0200 | [diff] [blame] | 5469 | |
Radek Krejci | 3d46812 | 2015-10-02 13:36:12 +0200 | [diff] [blame] | 5470 | /* we have the following supported (hardcoded) extensions: */ |
| 5471 | /* ietf-netconf's get-filter-element-attributes */ |
| 5472 | if (!strcmp(module->ns, LY_NSNC) && |
| 5473 | !strcmp(value, "get-filter-element-attributes")) { |
| 5474 | LOGDBG("NETCONF filter extension found"); |
| 5475 | /* NACM's default-deny-write and default-deny-all */ |
| 5476 | } else if (!strcmp(module->ns, LY_NSNACM) && |
| 5477 | (!strcmp(value, "default-deny-write") || !strcmp(value, "default-deny-all"))) { |
| 5478 | LOGDBG("NACM extension found"); |
| 5479 | /* other extensions are not supported, so inform about such an extension */ |
| 5480 | } else { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 5481 | LOGWRN("Not supported \"%s\" extension statement found, ignoring.", value); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5482 | lyxml_free(ctx, child); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 5483 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5484 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5485 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5486 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5487 | } |
| 5488 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5489 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5490 | /* check for mandatory statements */ |
| 5491 | if (submodule && !submodule->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5492 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "belongs-to", "submodule"); |
Michal Vasko | bdf51ef | 2015-12-10 12:11:21 +0100 | [diff] [blame] | 5493 | goto error; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5494 | } else if (!submodule) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5495 | if (!module->ns) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5496 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "namespace", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5497 | goto error; |
| 5498 | } |
| 5499 | if (!module->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5500 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5501 | goto error; |
| 5502 | } |
| 5503 | } |
Radek Krejci | bb3257d | 2015-05-21 23:03:51 +0200 | [diff] [blame] | 5504 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5505 | /* allocate arrays for elements with cardinality of 0..n */ |
| 5506 | if (c_imp) { |
Radek Krejci | 4dcd339 | 2016-06-22 10:28:40 +0200 | [diff] [blame] | 5507 | size = (c_imp * sizeof *trg->imp) + sizeof(void*); |
| 5508 | trg->imp = calloc(1, size); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5509 | if (!trg->imp) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5510 | LOGMEM; |
| 5511 | goto error; |
| 5512 | } |
Radek Krejci | 4dcd339 | 2016-06-22 10:28:40 +0200 | [diff] [blame] | 5513 | /* set stop block for possible realloc */ |
| 5514 | trg->imp[c_imp].module = (void*)0x1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5515 | } |
| 5516 | if (c_rev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5517 | trg->rev = calloc(c_rev, sizeof *trg->rev); |
| 5518 | if (!trg->rev) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5519 | LOGMEM; |
| 5520 | goto error; |
| 5521 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5522 | } |
| 5523 | if (c_tpdf) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5524 | trg->tpdf = calloc(c_tpdf, sizeof *trg->tpdf); |
| 5525 | if (!trg->tpdf) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5526 | LOGMEM; |
| 5527 | goto error; |
| 5528 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5529 | } |
| 5530 | if (c_ident) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5531 | trg->ident = calloc(c_ident, sizeof *trg->ident); |
| 5532 | if (!trg->ident) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5533 | LOGMEM; |
| 5534 | goto error; |
| 5535 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5536 | } |
| 5537 | if (c_inc) { |
Radek Krejci | 4dcd339 | 2016-06-22 10:28:40 +0200 | [diff] [blame] | 5538 | size = (c_inc * sizeof *trg->inc) + sizeof(void*); |
| 5539 | trg->inc = calloc(1, size); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5540 | if (!trg->inc) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5541 | LOGMEM; |
| 5542 | goto error; |
| 5543 | } |
Radek Krejci | 4dcd339 | 2016-06-22 10:28:40 +0200 | [diff] [blame] | 5544 | /* set stop block for possible realloc */ |
| 5545 | trg->inc[c_inc].submodule = (void*)0x1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5546 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5547 | if (c_aug) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5548 | trg->augment = calloc(c_aug, sizeof *trg->augment); |
| 5549 | if (!trg->augment) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5550 | LOGMEM; |
| 5551 | goto error; |
| 5552 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5553 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5554 | if (c_ftrs) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5555 | trg->features = calloc(c_ftrs, sizeof *trg->features); |
| 5556 | if (!trg->features) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5557 | LOGMEM; |
| 5558 | goto error; |
| 5559 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5560 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 5561 | if (c_dev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5562 | trg->deviation = calloc(c_dev, sizeof *trg->deviation); |
| 5563 | if (!trg->deviation) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5564 | LOGMEM; |
| 5565 | goto error; |
| 5566 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 5567 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5568 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5569 | /* middle part - process nodes with cardinality of 0..n except the data nodes and augments */ |
| 5570 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5571 | if (!strcmp(child->name, "import")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5572 | r = fill_yin_import(trg, child, &trg->imp[trg->imp_size]); |
| 5573 | trg->imp_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5574 | if (r) { |
| 5575 | goto error; |
| 5576 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 5577 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5578 | } else if (!strcmp(child->name, "include")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5579 | memset(&inc, 0, sizeof inc); |
| 5580 | /* 1) pass module, not trg, since we want to pass the main module |
| 5581 | * 2) we cannot pass directly the structure in the array since |
| 5582 | * submodule parser can realloc our array of includes */ |
Michal Vasko | 5ff7882 | 2016-02-12 09:33:31 +0100 | [diff] [blame] | 5583 | r = fill_yin_include(module, submodule, child, &inc, unres); |
Radek Krejci | 5b2c8a8 | 2016-06-17 15:36:03 +0200 | [diff] [blame] | 5584 | if (!r) { |
| 5585 | /* success, copy the filled data into the final array */ |
Radek Krejci | 4dcd339 | 2016-06-22 10:28:40 +0200 | [diff] [blame] | 5586 | memcpy(&trg->inc[trg->inc_size], &inc, sizeof inc); |
| 5587 | trg->inc_size++; |
Radek Krejci | 5b2c8a8 | 2016-06-17 15:36:03 +0200 | [diff] [blame] | 5588 | } else if (r == -1) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5589 | goto error; |
| 5590 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 5591 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5592 | } else if (!strcmp(child->name, "revision")) { |
| 5593 | GETVAL(value, child, "date"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5594 | if (lyp_check_date(value)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5595 | goto error; |
| 5596 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5597 | memcpy(trg->rev[trg->rev_size].date, value, LY_REV_SIZE - 1); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5598 | /* check uniqueness of the revision date - not required by RFC */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5599 | for (i = 0; i < trg->rev_size; i++) { |
| 5600 | if (!strcmp(value, trg->rev[i].date)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5601 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
| 5602 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Revision is not unique."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5603 | } |
| 5604 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 5605 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5606 | LY_TREE_FOR(child->child, child2) { |
| 5607 | if (!strcmp(child2->name, "description")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5608 | if (trg->rev[trg->rev_size].dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5609 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child2->name, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5610 | goto error; |
| 5611 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5612 | trg->rev[trg->rev_size].dsc = read_yin_subnode(ctx, child2, "text"); |
| 5613 | if (!trg->rev[trg->rev_size].dsc) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5614 | goto error; |
| 5615 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5616 | } else if (!strcmp(child2->name, "reference")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5617 | if (trg->rev[trg->rev_size].ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5618 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child2->name, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5619 | goto error; |
| 5620 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5621 | trg->rev[trg->rev_size].ref = read_yin_subnode(ctx, child2, "text"); |
| 5622 | if (!trg->rev[trg->rev_size].ref) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5623 | goto error; |
| 5624 | } |
| 5625 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5626 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child2->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5627 | goto error; |
| 5628 | } |
| 5629 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 5630 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5631 | /* keep the latest revision at position 0 */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5632 | if (trg->rev_size && strcmp(trg->rev[trg->rev_size].date, trg->rev[0].date) > 0) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5633 | /* switch their position */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5634 | value = strdup(trg->rev[0].date); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5635 | if (!value) { |
| 5636 | LOGMEM; |
| 5637 | goto error; |
| 5638 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5639 | memcpy(trg->rev[0].date, trg->rev[trg->rev_size].date, LY_REV_SIZE - 1); |
| 5640 | memcpy(trg->rev[trg->rev_size].date, value, LY_REV_SIZE - 1); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5641 | free((char *)value); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 5642 | |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 5643 | if (!ly_strequal(trg->rev[0].dsc, trg->rev[trg->rev_size].dsc, 1)) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5644 | value = trg->rev[0].dsc; |
| 5645 | trg->rev[0].dsc = trg->rev[trg->rev_size].dsc; |
| 5646 | trg->rev[trg->rev_size].dsc = value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5647 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 5648 | |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 5649 | if (!ly_strequal(trg->rev[0].ref, trg->rev[trg->rev_size].ref, 1)) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5650 | value = trg->rev[0].ref; |
| 5651 | trg->rev[0].ref = trg->rev[trg->rev_size].ref; |
| 5652 | trg->rev[trg->rev_size].ref = value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5653 | } |
| 5654 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 5655 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5656 | trg->rev_size++; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5657 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5658 | } else if (!strcmp(child->name, "typedef")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5659 | r = fill_yin_typedef(trg, NULL, child, &trg->tpdf[trg->tpdf_size], unres); |
| 5660 | trg->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5661 | if (r) { |
| 5662 | goto error; |
| 5663 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5664 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5665 | } else if (!strcmp(child->name, "identity")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5666 | r = fill_yin_identity(trg, child, &trg->ident[trg->ident_size], unres); |
| 5667 | trg->ident_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5668 | if (r) { |
| 5669 | goto error; |
| 5670 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5671 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5672 | } else if (!strcmp(child->name, "feature")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5673 | r = fill_yin_feature(trg, child, &trg->features[trg->features_size], unres); |
| 5674 | trg->features_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5675 | if (r) { |
| 5676 | goto error; |
| 5677 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5678 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5679 | } else if (!strcmp(child->name, "deviation")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5680 | r = fill_yin_deviation(trg, child, &trg->deviation[trg->deviation_size], unres); |
| 5681 | trg->deviation_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 5682 | if (r) { |
| 5683 | goto error; |
| 5684 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5685 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5686 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5687 | |
Radek Krejci | b8f98c1 | 2016-06-24 10:30:46 +0200 | [diff] [blame] | 5688 | if (!submodule) { |
| 5689 | /* update the size of the arrays, they can be smaller due to possible duplicities |
Radek Krejci | 4dcd339 | 2016-06-22 10:28:40 +0200 | [diff] [blame] | 5690 | * found in submodules */ |
Radek Krejci | b8f98c1 | 2016-06-24 10:30:46 +0200 | [diff] [blame] | 5691 | if (module->inc_size) { |
| 5692 | module->inc = ly_realloc(module->inc, module->inc_size * sizeof *module->inc); |
| 5693 | if (!module->inc) { |
| 5694 | LOGMEM; |
| 5695 | goto error; |
| 5696 | } |
| 5697 | } |
| 5698 | if (module->imp_size) { |
| 5699 | module->imp = ly_realloc(module->imp, module->imp_size * sizeof *module->imp); |
| 5700 | if (!module->imp) { |
| 5701 | LOGMEM; |
| 5702 | goto error; |
| 5703 | } |
Radek Krejci | 4dcd339 | 2016-06-22 10:28:40 +0200 | [diff] [blame] | 5704 | } |
| 5705 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5706 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5707 | /* process data nodes. Start with groupings to allow uses |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5708 | * refer to them. Submodule's data nodes are stored in the |
| 5709 | * main module data tree. |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5710 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5711 | LY_TREE_FOR_SAFE(grps.child, next, child) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5712 | node = read_yin_grouping(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5713 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5714 | goto error; |
| 5715 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 5716 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5717 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5718 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 5719 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5720 | /* parse data nodes, ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5721 | LY_TREE_FOR_SAFE(root.child, next, child) { |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5722 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5723 | if (!strcmp(child->name, "container")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 5724 | node = read_yin_container(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5725 | } else if (!strcmp(child->name, "leaf-list")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 5726 | node = read_yin_leaflist(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5727 | } else if (!strcmp(child->name, "leaf")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 5728 | node = read_yin_leaf(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5729 | } else if (!strcmp(child->name, "list")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 5730 | node = read_yin_list(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5731 | } else if (!strcmp(child->name, "choice")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 5732 | node = read_yin_choice(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5733 | } else if (!strcmp(child->name, "uses")) { |
Radek Krejci | 3440cc5 | 2016-06-23 17:03:59 +0200 | [diff] [blame] | 5734 | node = read_yin_uses(trg, NULL, child, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5735 | } else if (!strcmp(child->name, "anyxml")) { |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 5736 | node = read_yin_anydata(trg, NULL, child, LYS_ANYXML, 1, unres); |
| 5737 | } else if (!strcmp(child->name, "anydata")) { |
| 5738 | node = read_yin_anydata(trg, NULL, child, LYS_ANYDATA, 1, unres); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 5739 | } else if (!strcmp(child->name, "rpc")) { |
Michal Vasko | ca7cbc4 | 2016-07-01 11:36:53 +0200 | [diff] [blame] | 5740 | node = read_yin_rpc_action(trg, NULL, child, 0, unres); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 5741 | } else if (!strcmp(child->name, "notification")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 5742 | node = read_yin_notif(trg, NULL, child, 0, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5743 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5744 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5745 | goto error; |
| 5746 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 5747 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5748 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5749 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5750 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5751 | /* ... and finally augments (last, so we can augment our data, for instance) */ |
| 5752 | LY_TREE_FOR_SAFE(augs.child, next, child) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5753 | r = fill_yin_augment(trg, NULL, child, &trg->augment[trg->augment_size], unres); |
| 5754 | trg->augment_size++; |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5755 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5756 | if (r) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5757 | goto error; |
| 5758 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5759 | lyxml_free(ctx, child); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5760 | } |
| 5761 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5762 | return EXIT_SUCCESS; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5763 | |
| 5764 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5765 | /* cleanup */ |
| 5766 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5767 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5768 | } |
| 5769 | while (grps.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5770 | lyxml_free(module->ctx, grps.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5771 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5772 | while (augs.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5773 | lyxml_free(module->ctx, augs.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5774 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5775 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5776 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5777 | } |
| 5778 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5779 | /* logs directly */ |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5780 | struct lys_submodule * |
| 5781 | 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] | 5782 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5783 | struct lyxml_elem *yin; |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5784 | struct lys_submodule *submodule = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5785 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5786 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5787 | assert(module->ctx); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5788 | |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 5789 | yin = lyxml_parse_mem(module->ctx, data, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5790 | if (!yin) { |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5791 | return NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5792 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5793 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5794 | /* check root element */ |
| 5795 | if (!yin->name || strcmp(yin->name, "submodule")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5796 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5797 | goto error; |
| 5798 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5799 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5800 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5801 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5802 | goto error; |
| 5803 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5804 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5805 | submodule = calloc(1, sizeof *submodule); |
| 5806 | if (!submodule) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5807 | LOGMEM; |
| 5808 | goto error; |
| 5809 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5810 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5811 | submodule->ctx = module->ctx; |
| 5812 | submodule->name = lydict_insert(submodule->ctx, value, strlen(value)); |
| 5813 | submodule->type = 1; |
| 5814 | submodule->belongsto = module; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5815 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5816 | LOGVRB("Reading submodule \"%s\".", submodule->name); |
| 5817 | if (read_sub_module(module, submodule, yin, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5818 | goto error; |
| 5819 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5820 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5821 | /* cleanup */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5822 | lyxml_free(module->ctx, yin); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5823 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5824 | LOGVRB("Submodule \"%s\" successfully parsed.", submodule->name); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5825 | return submodule; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5826 | |
| 5827 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5828 | /* cleanup */ |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5829 | unres_schema_free((struct lys_module *)submodule, &unres); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5830 | lyxml_free(module->ctx, yin); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5831 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5832 | if (!submodule) { |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 5833 | LOGERR(ly_errno, "Submodule parsing failed."); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5834 | return NULL; |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 5835 | } |
| 5836 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5837 | LOGERR(ly_errno, "Submodule \"%s\" parsing failed.", submodule->name); |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 5838 | |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 5839 | lys_sub_module_remove_devs_augs((struct lys_module *)submodule); |
| 5840 | lys_submodule_module_data_free(submodule); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5841 | lys_submodule_free(submodule, NULL); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5842 | return NULL; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5843 | } |
| 5844 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5845 | /* logs directly */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5846 | struct lys_module * |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 5847 | yin_read_module(struct ly_ctx *ctx, const char *data, const char *revision, int implement) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5848 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5849 | struct lyxml_elem *yin; |
Pavol Vican | c99b59e | 2016-03-22 15:46:39 +0100 | [diff] [blame] | 5850 | struct lys_module *module = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5851 | struct unres_schema *unres; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5852 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5853 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5854 | unres = calloc(1, sizeof *unres); |
| 5855 | if (!unres) { |
| 5856 | LOGMEM; |
| 5857 | return NULL; |
| 5858 | } |
| 5859 | |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 5860 | yin = lyxml_parse_mem(ctx, data, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5861 | if (!yin) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5862 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5863 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5864 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5865 | /* check root element */ |
| 5866 | if (!yin->name || strcmp(yin->name, "module")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5867 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5868 | goto error; |
| 5869 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5870 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5871 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5872 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5873 | goto error; |
| 5874 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5875 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5876 | module = calloc(1, sizeof *module); |
| 5877 | if (!module) { |
| 5878 | LOGMEM; |
| 5879 | goto error; |
| 5880 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5881 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5882 | module->ctx = ctx; |
| 5883 | module->name = lydict_insert(ctx, value, strlen(value)); |
| 5884 | module->type = 0; |
Michal Vasko | d8aa32d | 2015-07-24 11:50:01 +0200 | [diff] [blame] | 5885 | module->implemented = (implement ? 1 : 0); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5886 | |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5887 | LOGVRB("Reading module \"%s\".", module->name); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5888 | if (read_sub_module(module, NULL, yin, unres)) { |
| 5889 | goto error; |
| 5890 | } |
| 5891 | |
| 5892 | /* resolve rest of unres items */ |
| 5893 | if (unres->count && resolve_unres_schema(module, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5894 | goto error; |
| 5895 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5896 | |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 5897 | if (revision) { |
| 5898 | /* check revision of the parsed model */ |
| 5899 | if (!module->rev_size || strcmp(revision, module->rev[0].date)) { |
Michal Vasko | b24e788 | 2016-03-21 16:13:25 +0100 | [diff] [blame] | 5900 | LOGVRB("Module \"%s\" parsed with the wrong revision (\"%s\" instead \"%s\").", |
| 5901 | module->name, module->rev[0].date, revision); |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 5902 | goto error; |
| 5903 | } |
| 5904 | } |
| 5905 | |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 5906 | if (lyp_ctx_add_module(&module)) { |
Pavol Vican | c99b59e | 2016-03-22 15:46:39 +0100 | [diff] [blame] | 5907 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5908 | } |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 5909 | |
Radek Krejci | 27fe55e | 2016-09-13 17:13:35 +0200 | [diff] [blame] | 5910 | if (module->deviation_size && !module->implemented) { |
| 5911 | LOGVRB("Module \"%s\" includes deviations, changing its conformance to \"implement\".", module->name); |
| 5912 | /* deviations always causes target to be made implemented, |
| 5913 | * but augents and leafrefs not, so we have to apply them now */ |
| 5914 | if (lys_set_implemented(module)) { |
Michal Vasko | 2605575 | 2016-05-03 11:36:31 +0200 | [diff] [blame] | 5915 | goto error; |
| 5916 | } |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 5917 | } |
| 5918 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5919 | lyxml_free(ctx, yin); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5920 | unres_schema_free(NULL, &unres); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5921 | LOGVRB("Module \"%s\" successfully parsed.", module->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5922 | return module; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5923 | |
| 5924 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5925 | /* cleanup */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5926 | lyxml_free(ctx, yin); |
Radek Krejci | b8c07b8 | 2016-02-12 11:11:55 +0100 | [diff] [blame] | 5927 | unres_schema_free(module, &unres); |
| 5928 | |
| 5929 | if (!module) { |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 5930 | LOGERR(ly_errno, "Module parsing failed."); |
Radek Krejci | b8c07b8 | 2016-02-12 11:11:55 +0100 | [diff] [blame] | 5931 | return NULL; |
| 5932 | } |
| 5933 | |
| 5934 | LOGERR(ly_errno, "Module \"%s\" parsing failed.", module->name); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5935 | |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 5936 | lys_sub_module_remove_devs_augs(module); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5937 | lys_free(module, NULL, 1); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5938 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5939 | } |