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> |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 24 | #include <pcre.h> |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 25 | |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 26 | #include "libyang.h" |
| 27 | #include "common.h" |
| 28 | #include "context.h" |
Radek Krejci | 41912fe | 2015-10-22 10:22:12 +0200 | [diff] [blame] | 29 | #include "dict_private.h" |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 30 | #include "xpath.h" |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 31 | #include "parser.h" |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 32 | #include "resolve.h" |
| 33 | #include "tree_internal.h" |
Michal Vasko | fc5744d | 2015-10-22 12:09:34 +0200 | [diff] [blame] | 34 | #include "xml_internal.h" |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 35 | |
Radek Krejci | adb5761 | 2016-02-16 13:34:34 +0100 | [diff] [blame] | 36 | #define GETVAL(value, node, arg) \ |
| 37 | value = lyxml_get_attr(node, arg, NULL); \ |
| 38 | if (!value) { \ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 39 | LOGVAL(LYE_MISSARG, LY_VLOG_NONE, NULL, arg, node->name); \ |
Radek Krejci | adb5761 | 2016-02-16 13:34:34 +0100 | [diff] [blame] | 40 | goto error; \ |
Michal Vasko | 2d710f3 | 2016-02-05 12:29:21 +0100 | [diff] [blame] | 41 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 42 | |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 43 | /* parser.c */ |
| 44 | int dup_prefix_check(const char *prefix, struct lys_module *module); |
| 45 | |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 46 | #define OPT_IDENT 0x01 |
| 47 | #define OPT_CONFIG 0x02 |
| 48 | #define OPT_MODULE 0x04 |
| 49 | #define OPT_INHERIT 0x08 |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 50 | #define OPT_NACMEXT 0x10 |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 51 | 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] | 52 | |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 53 | 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] | 54 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 55 | 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] | 56 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 57 | static struct lys_node *read_yin_anyxml(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 58 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 59 | 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] | 60 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 61 | 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] | 62 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 63 | 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] | 64 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 65 | 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] | 66 | int resolve, struct unres_schema *unres); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 67 | static struct lys_node *read_yin_uses(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 68 | int resolve, struct unres_schema *unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 69 | 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] | 70 | int resolve, struct unres_schema *unres); |
| 71 | 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] | 72 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 73 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 74 | static const char * |
| 75 | 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] | 76 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 77 | int len; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 78 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 79 | /* there should be <text> child */ |
| 80 | if (!node->child || !node->child->name || strcmp(node->child->name, name)) { |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 81 | LOGERR(LY_EVALID, "Expected \"%s\" element in \"%s\" element.", name, node->name); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 82 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, name, node->name); |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 83 | return NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 84 | } else if (node->child->content) { |
| 85 | len = strlen(node->child->content); |
| 86 | return lydict_insert(ctx, node->child->content, len); |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 87 | } else { |
| 88 | return lydict_insert(ctx, "", 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 89 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 92 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 93 | static int |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 94 | fill_yin_iffeature(struct lys_node *parent, struct lyxml_elem *yin, struct lys_feature **iffeat, struct unres_schema *unres) |
| 95 | { |
| 96 | int r; |
| 97 | const char *value; |
| 98 | |
| 99 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 100 | if (!(value = transform_schema2json(parent->module, value))) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 101 | return EXIT_FAILURE; |
| 102 | } |
| 103 | |
| 104 | /* HACK - store pointer to the parent node for later status check */ |
| 105 | *iffeat = (struct lys_feature *)parent; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 106 | r = unres_schema_add_str(parent->module, unres, iffeat, UNRES_IFFEAT, value); |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 107 | lydict_remove(parent->module->ctx, value); |
| 108 | if (!r) { |
| 109 | return EXIT_SUCCESS; |
| 110 | } |
| 111 | |
| 112 | error: |
| 113 | return EXIT_FAILURE; |
| 114 | } |
| 115 | |
| 116 | /* logs directly */ |
| 117 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 118 | 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] | 119 | { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 120 | struct lyxml_elem *node; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 121 | const char *value; |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 122 | int base_flag = 0; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 123 | |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 124 | GETVAL(value, yin, "name"); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 125 | ident->name = value; |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 126 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 127 | 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] | 128 | return EXIT_FAILURE; |
| 129 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 130 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 131 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 132 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 133 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 134 | continue; |
| 135 | } |
| 136 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 137 | if (!strcmp(node->name, "base")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 138 | if (base_flag) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 139 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "base", "identity"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 140 | return EXIT_FAILURE; |
| 141 | } |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 142 | base_flag = 1; |
| 143 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 144 | GETVAL(value, node, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 145 | value = transform_schema2json(module, value); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 146 | if (!value) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 147 | return EXIT_FAILURE; |
| 148 | } |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 149 | |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 150 | if (unres_schema_add_str(module, unres, ident, UNRES_IDENT, value) == -1) { |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 151 | lydict_remove(module->ctx, value); |
| 152 | return EXIT_FAILURE; |
| 153 | } |
| 154 | lydict_remove(module->ctx, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 155 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 156 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name, "identity"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 157 | return EXIT_FAILURE; |
| 158 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 159 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 160 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 161 | return EXIT_SUCCESS; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 162 | |
| 163 | error: |
| 164 | return EXIT_FAILURE; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 165 | } |
| 166 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 167 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 168 | static int |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 169 | 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] | 170 | { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 171 | struct lyxml_elem *child; |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 172 | const char *value; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 173 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 174 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 175 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 176 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 177 | continue; |
| 178 | } |
| 179 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 180 | if (!strcmp(child->name, "description")) { |
| 181 | if (restr->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 182 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 183 | return EXIT_FAILURE; |
| 184 | } |
| 185 | restr->dsc = read_yin_subnode(ctx, child, "text"); |
| 186 | if (!restr->dsc) { |
| 187 | return EXIT_FAILURE; |
| 188 | } |
| 189 | } else if (!strcmp(child->name, "reference")) { |
| 190 | if (restr->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 191 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 192 | return EXIT_FAILURE; |
| 193 | } |
| 194 | restr->ref = read_yin_subnode(ctx, child, "text"); |
| 195 | if (!restr->ref) { |
| 196 | return EXIT_FAILURE; |
| 197 | } |
| 198 | } else if (!strcmp(child->name, "error-app-tag")) { |
| 199 | if (restr->eapptag) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 200 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 201 | return EXIT_FAILURE; |
| 202 | } |
Michal Vasko | 54e426f | 2015-07-07 15:38:02 +0200 | [diff] [blame] | 203 | GETVAL(value, child, "value"); |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 204 | restr->eapptag = lydict_insert(ctx, value, 0); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 205 | } else if (!strcmp(child->name, "error-message")) { |
| 206 | if (restr->emsg) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 207 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 208 | return EXIT_FAILURE; |
| 209 | } |
| 210 | restr->emsg = read_yin_subnode(ctx, child, "value"); |
| 211 | if (!restr->emsg) { |
| 212 | return EXIT_FAILURE; |
| 213 | } |
| 214 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 215 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 216 | return EXIT_FAILURE; |
| 217 | } |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | return EXIT_SUCCESS; |
Michal Vasko | c8ef47f | 2015-06-29 14:56:19 +0200 | [diff] [blame] | 221 | |
| 222 | error: |
| 223 | return EXIT_FAILURE; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 224 | } |
| 225 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 226 | /* logs directly, returns EXIT_SUCCESS, EXIT_FAILURE, -1 */ |
| 227 | int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 228 | fill_yin_type(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_type *type, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 229 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 230 | { |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 231 | const char *value, *name, *err_ptr; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 232 | struct lyxml_elem *next, *node; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 233 | struct lys_restr **restr; |
| 234 | struct lys_type_bit bit; |
Michal Vasko | 01c6fd2 | 2016-05-20 11:43:05 +0200 | [diff] [blame] | 235 | struct lys_type *type_der; |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 236 | pcre *precomp; |
| 237 | int i, j, rc, err_offset; |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 238 | int ret = -1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 239 | int64_t v, v_; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 240 | int64_t p, p_; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 241 | |
Radek Krejci | 8de7b0f | 2015-07-02 11:43:42 +0200 | [diff] [blame] | 242 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 243 | value = transform_schema2json(module, value); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 244 | if (!value) { |
| 245 | goto error; |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 246 | } |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 247 | |
| 248 | i = parse_identifier(value); |
| 249 | if (i < 1) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 250 | LOGVAL(LYE_INCHAR, LY_VLOG_NONE, NULL, value[-i], &value[-i]); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 251 | lydict_remove(module->ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 252 | goto error; |
| 253 | } |
| 254 | /* module name */ |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 255 | name = value; |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 256 | if (value[i]) { |
| 257 | type->module_name = lydict_insert(module->ctx, value, i); |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 258 | name += i; |
| 259 | if ((name[0] != ':') || (parse_identifier(name + 1) < 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 260 | LOGVAL(LYE_INCHAR, LY_VLOG_NONE, NULL, name[0], name); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 261 | lydict_remove(module->ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 262 | goto error; |
| 263 | } |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 264 | ++name; |
Michal Vasko | ae0bce8 | 2016-06-06 15:08:18 +0200 | [diff] [blame] | 265 | name = lydict_insert(module->ctx, name, 0); |
| 266 | lydict_remove(module->ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 267 | } |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 268 | |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 269 | rc = resolve_superior_type(name, type->module_name, module, parent, &type->der); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 270 | if (rc == -1) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 271 | LOGVAL(LYE_INMOD, LY_VLOG_NONE, NULL, type->module_name); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 272 | goto error; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 273 | |
| 274 | /* 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] | 275 | } else if (rc == EXIT_FAILURE) { |
Michal Vasko | 01c6fd2 | 2016-05-20 11:43:05 +0200 | [diff] [blame] | 276 | LOGVAL(LYE_NORESOLV, LY_VLOG_NONE, NULL, "type", name); |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 277 | ret = EXIT_FAILURE; |
| 278 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 279 | } |
| 280 | type->base = type->der->type.base; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 281 | |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 282 | /* check status */ |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 283 | 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] | 284 | type->der->flags, type->der->module, type->der->name, parent)) { |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 285 | return -1; |
| 286 | } |
| 287 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 288 | switch (type->base) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 289 | case LY_TYPE_BITS: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 290 | /* RFC 6020 9.7.4 - bit */ |
| 291 | |
| 292 | /* get bit specifications, at least one must be present */ |
| 293 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 294 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 295 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 296 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 297 | continue; |
| 298 | } |
| 299 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 300 | if (!strcmp(node->name, "bit")) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 301 | type->info.bits.count++; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 302 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 303 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 304 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 305 | } |
| 306 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 307 | if (!type->der->type.der && !type->info.bits.count) { |
| 308 | /* type is derived directly from buit-in bits type and bit statement is required */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 309 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "bit", "type"); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 310 | goto error; |
| 311 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 312 | if (type->der->type.der && type->info.bits.count) { |
| 313 | /* type is not directly derived from buit-in bits type and bit statement is prohibited */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 314 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "bit"); |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 315 | goto error; |
| 316 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 317 | |
| 318 | 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] | 319 | if (!type->info.bits.bit) { |
| 320 | LOGMEM; |
| 321 | goto error; |
| 322 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 323 | p = 0; |
| 324 | i = -1; |
| 325 | LY_TREE_FOR(yin->child, next) { |
| 326 | i++; |
| 327 | |
| 328 | GETVAL(value, next, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 329 | if (lyp_check_identifier(value, LY_IDENT_SIMPLE, NULL, NULL)) { |
Michal Vasko | 2d26a02 | 2015-12-07 09:27:21 +0100 | [diff] [blame] | 330 | goto error; |
| 331 | } |
| 332 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 333 | 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] | 334 | 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] | 335 | type->info.bits.count = i + 1; |
| 336 | goto error; |
| 337 | } |
| 338 | |
| 339 | /* check the name uniqueness */ |
| 340 | for (j = 0; j < i; j++) { |
| 341 | if (!strcmp(type->info.bits.bit[j].name, type->info.bits.bit[i].name)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 342 | LOGVAL(LYE_BITS_DUPNAME, LY_VLOG_NONE, NULL, type->info.bits.bit[i].name); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 343 | type->info.bits.count = i + 1; |
| 344 | goto error; |
| 345 | } |
| 346 | } |
| 347 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 348 | p_ = -1; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 349 | LY_TREE_FOR(next->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 350 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 351 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 352 | continue; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 353 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 354 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 355 | if (!strcmp(node->name, "position")) { |
| 356 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 357 | p_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 358 | |
| 359 | /* range check */ |
Radek Krejci | b8ca108 | 2015-07-10 11:24:11 +0200 | [diff] [blame] | 360 | if (p_ < 0 || p_ > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 361 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "bit/position"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 362 | type->info.bits.count = i + 1; |
| 363 | goto error; |
| 364 | } |
| 365 | type->info.bits.bit[i].pos = (uint32_t)p_; |
| 366 | |
| 367 | /* keep the highest enum value for automatic increment */ |
Michal Vasko | 9ab0594 | 2015-07-07 15:38:26 +0200 | [diff] [blame] | 368 | if (type->info.bits.bit[i].pos >= p) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 369 | p = type->info.bits.bit[i].pos; |
| 370 | p++; |
| 371 | } else { |
| 372 | /* check that the value is unique */ |
| 373 | for (j = 0; j < i; j++) { |
| 374 | if (type->info.bits.bit[j].pos == type->info.bits.bit[i].pos) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 375 | LOGVAL(LYE_BITS_DUPVAL, LY_VLOG_NONE, NULL, |
Radek Krejci | adb5761 | 2016-02-16 13:34:34 +0100 | [diff] [blame] | 376 | type->info.bits.bit[i].pos, type->info.bits.bit[i].name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 377 | type->info.bits.count = i + 1; |
| 378 | goto error; |
| 379 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 380 | } |
| 381 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 382 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 383 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 384 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 385 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 386 | } |
| 387 | if (p_ == -1) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 388 | /* assign value automatically */ |
| 389 | if (p > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 390 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "4294967295", "bit/position"); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 391 | type->info.bits.count = i + 1; |
| 392 | goto error; |
| 393 | } |
| 394 | type->info.bits.bit[i].pos = (uint32_t)p; |
Michal Vasko | 3f053ef | 2016-02-12 14:27:13 +0100 | [diff] [blame] | 395 | type->info.bits.bit[i].flags |= LYS_AUTOASSIGNED; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 396 | p++; |
| 397 | } |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 398 | |
| 399 | /* keep them ordered by position */ |
| 400 | j = i; |
| 401 | while (j && type->info.bits.bit[j - 1].pos > type->info.bits.bit[j].pos) { |
| 402 | /* switch them */ |
| 403 | memcpy(&bit, &type->info.bits.bit[j], sizeof bit); |
| 404 | memcpy(&type->info.bits.bit[j], &type->info.bits.bit[j - 1], sizeof bit); |
| 405 | memcpy(&type->info.bits.bit[j - 1], &bit, sizeof bit); |
| 406 | j--; |
| 407 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 408 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 409 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 410 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 411 | case LY_TYPE_DEC64: |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 412 | /* RFC 6020 9.2.4 - range and 9.3.4 - fraction-digits */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 413 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 414 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 415 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 416 | continue; |
| 417 | } |
| 418 | |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 419 | if (!strcmp(node->name, "range")) { |
| 420 | if (type->info.dec64.range) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 421 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 422 | goto error; |
| 423 | } |
| 424 | |
| 425 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 426 | if (lyp_check_length_range(value, type)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 427 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "range"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 428 | goto error; |
| 429 | } |
| 430 | type->info.dec64.range = calloc(1, sizeof *type->info.dec64.range); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 431 | if (!type->info.dec64.range) { |
| 432 | LOGMEM; |
| 433 | goto error; |
| 434 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 435 | type->info.dec64.range->expr = lydict_insert(module->ctx, value, 0); |
| 436 | |
| 437 | /* get possible substatements */ |
| 438 | if (read_restr_substmt(module->ctx, type->info.dec64.range, node)) { |
| 439 | goto error; |
| 440 | } |
| 441 | } else if (!strcmp(node->name, "fraction-digits")) { |
| 442 | if (type->info.dec64.dig) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 443 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 444 | goto error; |
| 445 | } |
| 446 | GETVAL(value, node, "value"); |
| 447 | v = strtol(value, NULL, 10); |
| 448 | |
| 449 | /* range check */ |
| 450 | if (v < 1 || v > 18) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 451 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 452 | goto error; |
| 453 | } |
| 454 | type->info.dec64.dig = (uint8_t)v; |
| 455 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 456 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 457 | goto error; |
| 458 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | /* mandatory sub-statement(s) check */ |
| 462 | if (!type->info.dec64.dig && !type->der->type.der) { |
| 463 | /* decimal64 type directly derived from built-in type requires fraction-digits */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 464 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "fraction-digits", "type"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 465 | goto error; |
| 466 | } |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 467 | if (type->info.dec64.dig && type->der->type.der) { |
| 468 | /* 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] | 469 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "fraction-digits"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 470 | goto error; |
| 471 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 472 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 473 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 474 | case LY_TYPE_ENUM: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 475 | /* RFC 6020 9.6 - enum */ |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 476 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 477 | /* get enum specifications, at least one must be present */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 478 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 479 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 480 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 481 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 482 | continue; |
| 483 | } |
| 484 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 485 | if (!strcmp(node->name, "enum")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 486 | type->info.enums.count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 487 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 488 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 489 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 490 | } |
| 491 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 492 | if (!type->der->type.der && !type->info.enums.count) { |
| 493 | /* type is derived directly from buit-in enumeartion type and enum statement is required */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 494 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "enum", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 495 | goto error; |
| 496 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 497 | if (type->der->type.der && type->info.enums.count) { |
| 498 | /* type is not directly derived from buit-in enumeration type and enum statement is prohibited */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 499 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, "enum"); |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 500 | goto error; |
| 501 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 502 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 503 | 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] | 504 | if (!type->info.enums.enm) { |
| 505 | LOGMEM; |
| 506 | goto error; |
| 507 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 508 | v = 0; |
| 509 | i = -1; |
| 510 | LY_TREE_FOR(yin->child, next) { |
| 511 | i++; |
| 512 | |
| 513 | GETVAL(value, next, "name"); |
Michal Vasko | 0fb58e9 | 2015-12-07 09:27:44 +0100 | [diff] [blame] | 514 | if (!value[0]) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 515 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "enum name"); |
| 516 | 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] | 517 | goto error; |
| 518 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 519 | 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] | 520 | 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] | 521 | type->info.enums.count = i + 1; |
| 522 | goto error; |
| 523 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 524 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 525 | /* the assigned name MUST NOT have any leading or trailing whitespace characters */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 526 | value = type->info.enums.enm[i].name; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 527 | if (isspace(value[0]) || isspace(value[strlen(value) - 1])) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 528 | LOGVAL(LYE_ENUM_WS, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 529 | type->info.enums.count = i + 1; |
| 530 | goto error; |
| 531 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 532 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 533 | /* check the name uniqueness */ |
| 534 | for (j = 0; j < i; j++) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 535 | if (!strcmp(type->info.enums.enm[j].name, type->info.enums.enm[i].name)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 536 | LOGVAL(LYE_ENUM_DUPNAME, LY_VLOG_NONE, NULL, type->info.enums.enm[i].name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 537 | type->info.enums.count = i + 1; |
| 538 | goto error; |
| 539 | } |
| 540 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 541 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 542 | v_ = -1; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 543 | LY_TREE_FOR(next->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 544 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 545 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 546 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 547 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 548 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 549 | if (!strcmp(node->name, "value")) { |
| 550 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 551 | v_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 552 | |
| 553 | /* range check */ |
| 554 | if (v_ < INT32_MIN || v_ > INT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 555 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "enum/value"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 556 | type->info.enums.count = i + 1; |
| 557 | goto error; |
| 558 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 559 | type->info.enums.enm[i].value = v_; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 560 | |
| 561 | /* keep the highest enum value for automatic increment */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 562 | if (type->info.enums.enm[i].value > v) { |
| 563 | v = type->info.enums.enm[i].value; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 564 | v++; |
| 565 | } else { |
| 566 | /* check that the value is unique */ |
| 567 | for (j = 0; j < i; j++) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 568 | if (type->info.enums.enm[j].value == type->info.enums.enm[i].value) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 569 | LOGVAL(LYE_ENUM_DUPVAL, LY_VLOG_NONE, NULL, |
Radek Krejci | adb5761 | 2016-02-16 13:34:34 +0100 | [diff] [blame] | 570 | type->info.enums.enm[i].value, type->info.enums.enm[i].name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 571 | type->info.enums.count = i + 1; |
| 572 | goto error; |
| 573 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 574 | } |
| 575 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 576 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 577 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 578 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 579 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 580 | } |
| 581 | if (v_ == -1) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 582 | /* assign value automatically */ |
| 583 | if (v > INT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 584 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "2147483648", "enum/value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 585 | type->info.enums.count = i + 1; |
| 586 | goto error; |
| 587 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 588 | type->info.enums.enm[i].value = v; |
Michal Vasko | 3f053ef | 2016-02-12 14:27:13 +0100 | [diff] [blame] | 589 | type->info.enums.enm[i].flags |= LYS_AUTOASSIGNED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 590 | v++; |
| 591 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 592 | } |
| 593 | break; |
| 594 | |
| 595 | case LY_TYPE_IDENT: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 596 | /* RFC 6020 9.10 - base */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 597 | |
| 598 | /* get base specification, exactly one must be present */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 599 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 600 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 601 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 602 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 603 | continue; |
| 604 | } |
| 605 | |
Michal Vasko | e29c662 | 2015-11-27 15:02:31 +0100 | [diff] [blame] | 606 | if (strcmp(node->name, "base")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 607 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 608 | goto error; |
| 609 | } |
| 610 | } |
| 611 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 612 | if (!yin->child) { |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 613 | if (type->der->type.der) { |
| 614 | /* this is just a derived type with no base specified/required */ |
| 615 | break; |
| 616 | } |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 617 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "base", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 618 | goto error; |
| 619 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 620 | if (yin->child->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 621 | 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] | 622 | goto error; |
| 623 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 624 | GETVAL(value, yin->child, "name"); |
Michal Vasko | bdfb1e0 | 2016-02-05 13:15:11 +0100 | [diff] [blame] | 625 | /* store in the JSON format */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 626 | value = transform_schema2json(module, value); |
Michal Vasko | bdfb1e0 | 2016-02-05 13:15:11 +0100 | [diff] [blame] | 627 | if (!value) { |
| 628 | goto error; |
| 629 | } |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 630 | rc = unres_schema_add_str(module, unres, type, UNRES_TYPE_IDENTREF, value); |
Radek Krejci | c5989d4 | 2016-02-17 11:16:38 +0100 | [diff] [blame] | 631 | lydict_remove(module->ctx, value); |
| 632 | |
| 633 | if (rc == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 634 | goto error; |
| 635 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 636 | break; |
| 637 | |
| 638 | case LY_TYPE_INST: |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 639 | /* RFC 6020 9.13.2 - require-instance */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 640 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 641 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 642 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 643 | continue; |
| 644 | } |
| 645 | |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 646 | if (!strcmp(node->name, "require-instance")) { |
| 647 | if (type->info.inst.req) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 648 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 649 | goto error; |
| 650 | } |
| 651 | GETVAL(value, node, "value"); |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 652 | if (!strcmp(value, "true")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 653 | type->info.inst.req = 1; |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 654 | } else if (!strcmp(value, "false")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 655 | type->info.inst.req = -1; |
| 656 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 657 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 658 | goto error; |
| 659 | } |
| 660 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 661 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 662 | goto error; |
| 663 | } |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 664 | } |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 665 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 666 | break; |
| 667 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 668 | case LY_TYPE_BINARY: |
| 669 | /* 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] | 670 | case LY_TYPE_INT8: |
| 671 | case LY_TYPE_INT16: |
| 672 | case LY_TYPE_INT32: |
| 673 | case LY_TYPE_INT64: |
| 674 | case LY_TYPE_UINT8: |
| 675 | case LY_TYPE_UINT16: |
| 676 | case LY_TYPE_UINT32: |
| 677 | case LY_TYPE_UINT64: |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 678 | /* RFC 6020 9.2.4 - range */ |
| 679 | |
| 680 | /* length and range are actually the same restriction, so process |
| 681 | * them by this common code, we just need to differ the name and |
| 682 | * structure where the information will be stored |
| 683 | */ |
| 684 | if (type->base == LY_TYPE_BINARY) { |
| 685 | restr = &type->info.binary.length; |
| 686 | name = "length"; |
| 687 | } else { |
| 688 | restr = &type->info.num.range; |
| 689 | name = "range"; |
| 690 | } |
| 691 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 692 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 693 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 694 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 695 | continue; |
| 696 | } |
| 697 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 698 | if (!strcmp(node->name, name)) { |
| 699 | if (*restr) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 700 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 701 | goto error; |
| 702 | } |
| 703 | |
| 704 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 705 | if (lyp_check_length_range(value, type)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 706 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 707 | goto error; |
| 708 | } |
| 709 | *restr = calloc(1, sizeof **restr); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 710 | if (!(*restr)) { |
| 711 | LOGMEM; |
| 712 | goto error; |
| 713 | } |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 714 | (*restr)->expr = lydict_insert(module->ctx, value, 0); |
| 715 | |
| 716 | /* get possible substatements */ |
| 717 | if (read_restr_substmt(module->ctx, *restr, node)) { |
| 718 | goto error; |
| 719 | } |
| 720 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 721 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 722 | goto error; |
| 723 | } |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 724 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 725 | break; |
| 726 | |
| 727 | case LY_TYPE_LEAFREF: |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 728 | /* RFC 6020 9.9.2 - path */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 729 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 730 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 731 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 732 | continue; |
| 733 | } |
| 734 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 735 | if (!strcmp(node->name, "path") && !type->der->type.der) { |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 736 | if (type->info.lref.path) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 737 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 738 | goto error; |
| 739 | } |
| 740 | |
| 741 | GETVAL(value, node, "value"); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 742 | /* store in the JSON format */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 743 | type->info.lref.path = transform_schema2json(module, value); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 744 | if (!type->info.lref.path) { |
| 745 | goto error; |
| 746 | } |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 747 | if (unres_schema_add_node(module, unres, type, UNRES_TYPE_LEAFREF, parent) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 748 | goto error; |
| 749 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 750 | |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 751 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 752 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 753 | goto error; |
| 754 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 755 | } |
| 756 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 757 | if (!type->info.lref.path && !type->der->type.der) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 758 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "path", "type"); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 759 | goto error; |
Michal Vasko | 01c6fd2 | 2016-05-20 11:43:05 +0200 | [diff] [blame] | 760 | } else if (type->der->type.der && parent) { |
| 761 | for (type_der = &type->der->type; !type_der->info.lref.path && type_der->der; type_der = &type_der->der->type); |
| 762 | assert(type_der->info.lref.path && type_der->info.lref.target); |
| 763 | /* add pointer to leafref target, only on leaves (not in typedefs) */ |
| 764 | if (lys_leaf_add_leafref_target(type_der->info.lref.target, (struct lys_node *)type->parent)) { |
| 765 | goto error; |
| 766 | } |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 767 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 768 | break; |
| 769 | |
| 770 | case LY_TYPE_STRING: |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 771 | /* RFC 6020 9.4.4 - length */ |
| 772 | /* RFC 6020 9.4.6 - pattern */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 773 | i = 0; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 774 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 775 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 776 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 777 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 778 | continue; |
| 779 | } |
| 780 | |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 781 | if (!strcmp(node->name, "length")) { |
| 782 | if (type->info.str.length) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 783 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 784 | goto error; |
| 785 | } |
| 786 | |
| 787 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 788 | if (lyp_check_length_range(value, type)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 789 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "length"); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 790 | goto error; |
| 791 | } |
| 792 | type->info.str.length = calloc(1, sizeof *type->info.str.length); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 793 | if (!type->info.str.length) { |
| 794 | LOGMEM; |
| 795 | goto error; |
| 796 | } |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 797 | type->info.str.length->expr = lydict_insert(module->ctx, value, 0); |
| 798 | |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 799 | /* get possible sub-statements */ |
| 800 | if (read_restr_substmt(module->ctx, type->info.str.length, node)) { |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 801 | goto error; |
| 802 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 803 | lyxml_free(module->ctx, node); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 804 | } else if (!strcmp(node->name, "pattern")) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 805 | i++; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 806 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 807 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 808 | goto error; |
| 809 | } |
| 810 | } |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 811 | /* store patterns in array */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 812 | if (i) { |
| 813 | type->info.str.patterns = calloc(i, sizeof *type->info.str.patterns); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 814 | if (!type->info.str.patterns) { |
| 815 | LOGMEM; |
| 816 | goto error; |
| 817 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 818 | LY_TREE_FOR(yin->child, node) { |
Michal Vasko | 5b64da2 | 2015-11-23 15:22:30 +0100 | [diff] [blame] | 819 | GETVAL(value, node, "value"); |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 820 | |
| 821 | /* check that the regex is valid */ |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 822 | precomp = pcre_compile(value, PCRE_NO_AUTO_CAPTURE, &err_ptr, &err_offset, NULL); |
| 823 | if (!precomp) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 824 | LOGVAL(LYE_INREGEX, LY_VLOG_NONE, NULL, value, err_ptr); |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 825 | free(type->info.str.patterns); |
| 826 | goto error; |
| 827 | } |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 828 | free(precomp); |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 829 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 830 | type->info.str.patterns[type->info.str.pat_count].expr = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 831 | |
| 832 | /* get possible sub-statements */ |
Michal Vasko | 5b64da2 | 2015-11-23 15:22:30 +0100 | [diff] [blame] | 833 | 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] | 834 | free(type->info.str.patterns); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 835 | goto error; |
| 836 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 837 | type->info.str.pat_count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 838 | } |
| 839 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 840 | break; |
| 841 | |
| 842 | case LY_TYPE_UNION: |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 843 | /* RFC 6020 7.4 - type */ |
| 844 | /* count number of types in union */ |
| 845 | i = 0; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 846 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 847 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 848 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 849 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 850 | continue; |
| 851 | } |
| 852 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 853 | if (!strcmp(node->name, "type")) { |
| 854 | i++; |
| 855 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 856 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 857 | goto error; |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | if (!i) { |
| 862 | if (type->der->type.der) { |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 863 | /* this is just a derived type with no additional type specified/required */ |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 864 | break; |
| 865 | } |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 866 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", "(union) type"); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 867 | goto error; |
| 868 | } |
| 869 | |
| 870 | /* allocate array for union's types ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 871 | type->info.uni.types = calloc(i, sizeof *type->info.uni.types); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 872 | if (!type->info.uni.types) { |
| 873 | LOGMEM; |
| 874 | goto error; |
| 875 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 876 | /* ... and fill the structures */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 877 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 878 | type->info.uni.types[type->info.uni.count].parent = type->parent; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 879 | rc = fill_yin_type(module, parent, node, &type->info.uni.types[type->info.uni.count], unres); |
| 880 | if (!rc) { |
| 881 | type->info.uni.count++; |
| 882 | |
| 883 | /* union's type cannot be empty or leafref */ |
| 884 | if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_EMPTY) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 885 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "empty", node->name); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 886 | rc = -1; |
| 887 | } else if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_LEAFREF) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 888 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, "leafref", node->name); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 889 | rc = -1; |
| 890 | } |
| 891 | } |
| 892 | if (rc) { |
| 893 | /* even if we got EXIT_FAILURE, throw it all away, too much trouble doing something else */ |
| 894 | for (i = 0; i < type->info.uni.count; ++i) { |
| 895 | lys_type_free(module->ctx, &type->info.uni.types[i]); |
| 896 | } |
| 897 | free(type->info.uni.types); |
| 898 | type->info.uni.types = NULL; |
| 899 | type->info.uni.count = 0; |
| 900 | |
| 901 | if (rc == EXIT_FAILURE) { |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 902 | ret = EXIT_FAILURE; |
| 903 | goto error; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 904 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 905 | goto error; |
| 906 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 907 | } |
| 908 | break; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 909 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 910 | case LY_TYPE_BOOL: |
| 911 | case LY_TYPE_EMPTY: |
| 912 | /* no sub-statement allowed */ |
| 913 | LY_TREE_FOR(yin->child, node) { |
| 914 | if (node->ns && !strcmp(node->ns->value, LY_NSYIN)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 915 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 916 | goto error; |
| 917 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 918 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 919 | break; |
| 920 | |
| 921 | default: |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 922 | LOGINT; |
| 923 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | return EXIT_SUCCESS; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 927 | |
| 928 | error: |
Radek Krejci | dc008d7 | 2016-02-17 13:12:14 +0100 | [diff] [blame] | 929 | if (type->module_name) { |
| 930 | lydict_remove(module->ctx, type->module_name); |
| 931 | type->module_name = NULL; |
| 932 | } |
| 933 | return ret; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 934 | } |
| 935 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 936 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 937 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 938 | 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] | 939 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 940 | const char *value; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 941 | struct lyxml_elem *node, *next; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 942 | int has_type = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 943 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 944 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 945 | if (lyp_check_identifier(value, LY_IDENT_TYPE, module, parent)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 946 | goto error; |
| 947 | } |
| 948 | tpdf->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 949 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 950 | /* generic part - status, description, reference */ |
Radek Krejci | 225376f | 2016-02-16 17:36:22 +0100 | [diff] [blame] | 951 | 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] | 952 | goto error; |
| 953 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 954 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 955 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 956 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 957 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 958 | continue; |
| 959 | } |
| 960 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 961 | if (!strcmp(node->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 962 | if (has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 963 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 964 | goto error; |
| 965 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 966 | /* HACK for unres */ |
| 967 | tpdf->type.der = (struct lys_tpdf *)node; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 968 | tpdf->type.parent = tpdf; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 969 | if (unres_schema_add_node(module, unres, &tpdf->type, UNRES_TYPE_DER, parent)) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 970 | goto error; |
| 971 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 972 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 973 | } else if (!strcmp(node->name, "default")) { |
| 974 | if (tpdf->dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 975 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 976 | goto error; |
| 977 | } |
| 978 | GETVAL(value, node, "value"); |
| 979 | tpdf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
| 980 | } else if (!strcmp(node->name, "units")) { |
| 981 | if (tpdf->units) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 982 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 983 | goto error; |
| 984 | } |
| 985 | GETVAL(value, node, "name"); |
| 986 | tpdf->units = lydict_insert(module->ctx, value, strlen(value)); |
| 987 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 988 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 989 | goto error; |
| 990 | } |
| 991 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 992 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 993 | /* check mandatory value */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 994 | if (!has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 995 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 996 | goto error; |
| 997 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 998 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 999 | /* check default value */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1000 | if (tpdf->dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1001 | if (unres_schema_add_str(module, unres, &tpdf->type, UNRES_TYPE_DFLT, tpdf->dflt) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1002 | goto error; |
| 1003 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1004 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1005 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1006 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1007 | |
| 1008 | error: |
| 1009 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1010 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1011 | } |
| 1012 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1013 | /* logs directly */ |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1014 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 1015 | 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] | 1016 | { |
| 1017 | const char *value; |
| 1018 | struct lyxml_elem *child, *next; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 1019 | int c = 0, ret; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1020 | |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1021 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1022 | if (lyp_check_identifier(value, LY_IDENT_FEATURE, module, NULL)) { |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1023 | goto error; |
| 1024 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1025 | f->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 1026 | f->module = module; |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1027 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1028 | if (read_yin_common(module, NULL, (struct lys_node *)f, yin, 0)) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1029 | goto error; |
| 1030 | } |
| 1031 | |
| 1032 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1033 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1034 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1035 | lyxml_free(module->ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1036 | continue; |
| 1037 | } |
| 1038 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1039 | if (!strcmp(child->name, "if-feature")) { |
| 1040 | c++; |
| 1041 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1042 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1043 | goto error; |
| 1044 | } |
| 1045 | } |
| 1046 | |
| 1047 | if (c) { |
| 1048 | f->features = calloc(c, sizeof *f->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1049 | if (!f->features) { |
| 1050 | LOGMEM; |
| 1051 | goto error; |
| 1052 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1053 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1054 | LY_TREE_FOR(yin->child, child) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 1055 | ret = fill_yin_iffeature((struct lys_node *)f, child, &f->features[f->features_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 1056 | f->features_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 1057 | if (ret) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1058 | goto error; |
| 1059 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1060 | } |
| 1061 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1062 | return EXIT_SUCCESS; |
| 1063 | |
| 1064 | error: |
| 1065 | |
| 1066 | return EXIT_FAILURE; |
| 1067 | } |
| 1068 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1069 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1070 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1071 | 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] | 1072 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1073 | const char *value; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1074 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1075 | GETVAL(value, yin, "condition"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1076 | must->expr = transform_schema2json(module, value); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 1077 | if (!must->expr) { |
| 1078 | goto error; |
| 1079 | } |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1080 | if (lyxp_syntax_check(must->expr)) { |
Michal Vasko | 77dc565 | 2016-02-15 12:32:42 +0100 | [diff] [blame] | 1081 | goto error; |
| 1082 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1083 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 1084 | return read_restr_substmt(module->ctx, must, yin); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1085 | |
Michal Vasko | 77dc565 | 2016-02-15 12:32:42 +0100 | [diff] [blame] | 1086 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1087 | return EXIT_FAILURE; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1088 | } |
| 1089 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1090 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1091 | fill_yin_unique(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_unique *unique, |
| 1092 | struct unres_schema *unres) |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1093 | { |
| 1094 | int i, j; |
| 1095 | const char *value, *vaux; |
| 1096 | |
| 1097 | /* get unique value (list of leafs supposed to be unique */ |
| 1098 | GETVAL(value, yin, "tag"); |
| 1099 | |
| 1100 | /* count the number of unique leafs in the value */ |
| 1101 | vaux = value; |
| 1102 | while ((vaux = strpbrk(vaux, " \t\n"))) { |
Michal Vasko | 98645db | 2016-03-07 14:38:49 +0100 | [diff] [blame] | 1103 | unique->expr_size++; |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1104 | while (isspace(*vaux)) { |
| 1105 | vaux++; |
| 1106 | } |
| 1107 | } |
| 1108 | unique->expr_size++; |
| 1109 | unique->expr = calloc(unique->expr_size, sizeof *unique->expr); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1110 | if (!unique->expr) { |
| 1111 | LOGMEM; |
| 1112 | goto error; |
| 1113 | } |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1114 | |
| 1115 | for (i = 0; i < unique->expr_size; i++) { |
| 1116 | vaux = strpbrk(value, " \t\n"); |
| 1117 | if (!vaux) { |
| 1118 | /* the last token, lydict_insert() will count its size on its own */ |
| 1119 | vaux = value; |
| 1120 | } |
| 1121 | |
| 1122 | /* store token into unique structure */ |
| 1123 | unique->expr[i] = lydict_insert(module->ctx, value, vaux - value); |
| 1124 | |
| 1125 | /* check that the expression does not repeat */ |
| 1126 | for (j = 0; j < i; j++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 1127 | if (ly_strequal(unique->expr[j], unique->expr[i], 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1128 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, unique->expr[i], "unique"); |
| 1129 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "The identifier is not unique"); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1130 | goto error; |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | /* try to resolve leaf */ |
| 1135 | if (unres) { |
Pavol Vican | 18b1021 | 2016-04-11 15:41:52 +0200 | [diff] [blame] | 1136 | if (unres_schema_add_str(module, unres, parent, UNRES_LIST_UNIQ, unique->expr[i]) == -1){ |
| 1137 | goto error; |
| 1138 | } |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1139 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1140 | if (resolve_unique(parent, unique->expr[i])) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1141 | goto error; |
| 1142 | } |
| 1143 | } |
| 1144 | |
| 1145 | /* move to next token */ |
| 1146 | value = vaux; |
| 1147 | while(isspace(*value)) { |
| 1148 | value++; |
| 1149 | } |
| 1150 | } |
| 1151 | |
| 1152 | return EXIT_SUCCESS; |
| 1153 | |
| 1154 | error: |
| 1155 | return EXIT_FAILURE; |
| 1156 | } |
| 1157 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1158 | /* logs directly |
| 1159 | * |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1160 | * type: 0 - min, 1 - max |
| 1161 | */ |
| 1162 | static int |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1163 | 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] | 1164 | { |
| 1165 | const char *value; |
| 1166 | char *endptr; |
| 1167 | unsigned long val; |
| 1168 | uint32_t *ui32val; |
| 1169 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1170 | /* del min/max is forbidden */ |
| 1171 | if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1172 | 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] | 1173 | goto error; |
| 1174 | } |
| 1175 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1176 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1177 | if (target->nodetype == LYS_LEAFLIST) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1178 | if (type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1179 | ui32val = &((struct lys_node_leaflist *)target)->max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1180 | } else { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1181 | ui32val = &((struct lys_node_leaflist *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1182 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1183 | } else if (target->nodetype == LYS_LIST) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1184 | if (type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1185 | ui32val = &((struct lys_node_list *)target)->max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1186 | } else { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1187 | ui32val = &((struct lys_node_list *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1188 | } |
| 1189 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1190 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
| 1191 | 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] | 1192 | goto error; |
| 1193 | } |
| 1194 | |
| 1195 | GETVAL(value, node, "value"); |
| 1196 | while (isspace(value[0])) { |
| 1197 | value++; |
| 1198 | } |
| 1199 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1200 | if (type && !strcmp(value, "unbounded")) { |
| 1201 | d->max = val = 0; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 1202 | d->max_set = 1; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1203 | } else { |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1204 | /* convert it to uint32_t */ |
| 1205 | errno = 0; |
| 1206 | endptr = NULL; |
| 1207 | val = strtoul(value, &endptr, 10); |
| 1208 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1209 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, node->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1210 | goto error; |
| 1211 | } |
| 1212 | if (type) { |
| 1213 | d->max = (uint32_t)val; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 1214 | d->max_set = 1; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1215 | } else { |
| 1216 | d->min = (uint32_t)val; |
Radek Krejci | a31ca7a | 2016-03-07 15:05:20 +0100 | [diff] [blame] | 1217 | d->min_set = 1; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1218 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | if (d->mod == LY_DEVIATE_ADD) { |
| 1222 | /* check that there is no current value */ |
| 1223 | if (*ui32val) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1224 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, node->name); |
| 1225 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1226 | goto error; |
| 1227 | } |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 1228 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 1229 | /* unfortunately, there is no way to check reliably that there |
| 1230 | * was a value before, it could have been the default */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1231 | } |
| 1232 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1233 | /* add (already checked) and replace */ |
| 1234 | /* set new value specified in deviation */ |
| 1235 | *ui32val = (uint32_t)val; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1236 | |
| 1237 | return EXIT_SUCCESS; |
| 1238 | |
| 1239 | error: |
| 1240 | |
| 1241 | return EXIT_FAILURE; |
| 1242 | } |
| 1243 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1244 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1245 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1246 | fill_yin_deviation(struct lys_module *module, struct lyxml_elem *yin, struct lys_deviation *dev, |
| 1247 | struct unres_schema *unres) |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1248 | { |
| 1249 | const char *value, **stritem; |
| 1250 | struct lyxml_elem *next, *child, *develem; |
| 1251 | int c_dev = 0, c_must, c_uniq; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1252 | int f_min = 0, f_max = 0; /* flags */ |
Michal Vasko | b40b451 | 2016-02-11 11:35:37 +0100 | [diff] [blame] | 1253 | int i, j, rc; |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1254 | struct ly_ctx *ctx; |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1255 | struct lys_deviate *d = NULL; |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1256 | struct lys_node *node = NULL, *dev_target = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1257 | struct lys_node_choice *choice = NULL; |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 1258 | struct lys_node_leaf *leaf = NULL, **leaf_dflt_check = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1259 | struct lys_node_list *list = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1260 | struct lys_type *t = NULL; |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 1261 | uint8_t *trg_must_size = NULL, leaf_dflt_check_count = 0; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1262 | struct lys_restr **trg_must = NULL; |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 1263 | struct unres_schema tmp_unres; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1264 | |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1265 | ctx = module->ctx; |
| 1266 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1267 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1268 | dev->target_name = transform_schema2json(module, value); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 1269 | if (!dev->target_name) { |
| 1270 | goto error; |
| 1271 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1272 | |
| 1273 | /* resolve target node */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1274 | rc = resolve_augment_schema_nodeid(dev->target_name, NULL, module, (const struct lys_node **)&dev_target); |
| 1275 | if (rc || !dev_target) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1276 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1277 | goto error; |
| 1278 | } |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 1279 | if (dev_target->module == lys_main_module(module)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1280 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, yin->name); |
| 1281 | 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] | 1282 | goto error; |
| 1283 | } |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 1284 | lys_deviation_add_ext_imports(lys_node_module(dev_target), module); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1285 | |
| 1286 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1287 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1288 | /* garbage */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1289 | lyxml_free(ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1290 | continue; |
| 1291 | } |
| 1292 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1293 | if (!strcmp(child->name, "description")) { |
| 1294 | if (dev->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1295 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1296 | goto error; |
| 1297 | } |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1298 | dev->dsc = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1299 | if (!dev->dsc) { |
| 1300 | goto error; |
| 1301 | } |
| 1302 | } else if (!strcmp(child->name, "reference")) { |
| 1303 | if (dev->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1304 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1305 | goto error; |
| 1306 | } |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1307 | dev->ref = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1308 | if (!dev->ref) { |
| 1309 | goto error; |
| 1310 | } |
| 1311 | } else if (!strcmp(child->name, "deviate")) { |
| 1312 | c_dev++; |
| 1313 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1314 | /* skip lyxml_free() at the end of the loop, node will be |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1315 | * further processed later |
| 1316 | */ |
| 1317 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 1318 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1319 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1320 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1321 | goto error; |
| 1322 | } |
| 1323 | |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1324 | lyxml_free(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | if (c_dev) { |
| 1328 | dev->deviate = calloc(c_dev, sizeof *dev->deviate); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1329 | if (!dev->deviate) { |
| 1330 | LOGMEM; |
| 1331 | goto error; |
| 1332 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | LY_TREE_FOR(yin->child, develem) { |
| 1336 | /* init */ |
| 1337 | f_min = 0; |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1338 | f_max = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1339 | c_must = 0; |
| 1340 | c_uniq = 0; |
| 1341 | |
| 1342 | /* get deviation type */ |
| 1343 | GETVAL(value, develem, "value"); |
| 1344 | if (!strcmp(value, "not-supported")) { |
| 1345 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_NO; |
| 1346 | /* no property expected in this case */ |
| 1347 | if (develem->child) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1348 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, develem->child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1349 | goto error; |
| 1350 | } |
| 1351 | |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1352 | /* and neither any other deviate statement is expected, |
| 1353 | * not-supported deviation must be the only deviation of the target |
| 1354 | */ |
| 1355 | if (dev->deviate_size || develem->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1356 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
| 1357 | 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] | 1358 | goto error; |
| 1359 | } |
| 1360 | |
Michal Vasko | ad1f7b7 | 2016-02-17 11:13:58 +0100 | [diff] [blame] | 1361 | /* you cannot remove a key leaf */ |
Michal Vasko | 43c9477 | 2016-05-03 11:47:44 +0200 | [diff] [blame] | 1362 | if ((dev_target->nodetype == LYS_LEAF) && lys_parent(dev_target) && (lys_parent(dev_target)->nodetype == LYS_LIST)) { |
| 1363 | for (i = 0; i < ((struct lys_node_list *)lys_parent(dev_target))->keys_size; ++i) { |
| 1364 | 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] | 1365 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
| 1366 | 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] | 1367 | goto error; |
| 1368 | } |
| 1369 | } |
| 1370 | } |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1371 | |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 1372 | /* unlink and store the original node */ |
| 1373 | lys_node_unlink(dev_target); |
| 1374 | dev->orig_node = dev_target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1375 | |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1376 | dev->deviate_size = 1; |
| 1377 | return EXIT_SUCCESS; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1378 | } else if (!strcmp(value, "add")) { |
| 1379 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_ADD; |
| 1380 | } else if (!strcmp(value, "replace")) { |
| 1381 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_RPL; |
| 1382 | } else if (!strcmp(value, "delete")) { |
| 1383 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_DEL; |
| 1384 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1385 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, develem->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1386 | goto error; |
| 1387 | } |
| 1388 | d = &dev->deviate[dev->deviate_size]; |
Michal Vasko | 0f7d7ee | 2016-03-08 09:20:25 +0100 | [diff] [blame] | 1389 | dev->deviate_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1390 | |
Michal Vasko | ff006c1 | 2016-02-17 11:15:19 +0100 | [diff] [blame] | 1391 | /* store a shallow copy of the original node */ |
| 1392 | if (!dev->orig_node) { |
| 1393 | memset(&tmp_unres, 0, sizeof tmp_unres); |
| 1394 | dev->orig_node = lys_node_dup(dev_target->module, NULL, dev_target, 0, 0, &tmp_unres, 1); |
| 1395 | /* just to be safe */ |
| 1396 | if (tmp_unres.count) { |
| 1397 | LOGINT; |
| 1398 | goto error; |
| 1399 | } |
| 1400 | } |
| 1401 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1402 | /* process deviation properties */ |
| 1403 | LY_TREE_FOR_SAFE(develem->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1404 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1405 | /* garbage */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1406 | lyxml_free(ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1407 | continue; |
| 1408 | } |
| 1409 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1410 | if (!strcmp(child->name, "config")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1411 | if (d->flags & LYS_CONFIG_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1412 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1413 | goto error; |
| 1414 | } |
| 1415 | |
| 1416 | /* for we deviate from RFC 6020 and allow config property even it is/is not |
| 1417 | * specified in the target explicitly since config property inherits. So we expect |
| 1418 | * that config is specified in every node. But for delete, we check that the value |
| 1419 | * is the same as here in deviation |
| 1420 | */ |
| 1421 | GETVAL(value, child, "value"); |
| 1422 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1423 | d->flags |= LYS_CONFIG_R; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1424 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1425 | d->flags |= LYS_CONFIG_W; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1426 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1427 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1428 | goto error; |
| 1429 | } |
| 1430 | |
| 1431 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1432 | /* del config is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1433 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "config", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1434 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1435 | } else { /* add and replace are the same in this case */ |
| 1436 | /* remove current config value of the target ... */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1437 | dev_target->flags &= ~LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1438 | |
| 1439 | /* ... and replace it with the value specified in deviation */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1440 | dev_target->flags |= d->flags & LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1441 | } |
| 1442 | } else if (!strcmp(child->name, "default")) { |
| 1443 | if (d->dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1444 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1445 | goto error; |
| 1446 | } |
| 1447 | GETVAL(value, child, "value"); |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1448 | d->dflt = lydict_insert(ctx, value, 0); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1449 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1450 | if (dev_target->nodetype == LYS_CHOICE) { |
| 1451 | choice = (struct lys_node_choice *)dev_target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1452 | |
| 1453 | if (d->mod == LY_DEVIATE_ADD) { |
| 1454 | /* check that there is no current value */ |
| 1455 | if (choice->dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1456 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1457 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1458 | goto error; |
| 1459 | } |
Radek Krejci | 9e8c10c | 2016-04-05 16:36:52 +0200 | [diff] [blame] | 1460 | /* check collision with mandatory */ |
| 1461 | if (choice->flags & LYS_MAND_TRUE) { |
| 1462 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
| 1463 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
| 1464 | "Adding the \"default\" statement is forbidden on choice with the \"mandatory\" statement."); |
| 1465 | goto error; |
| 1466 | } |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 1467 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 1468 | /* check that there was a value before */ |
| 1469 | if (!choice->dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1470 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1471 | 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] | 1472 | goto error; |
| 1473 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1474 | } |
| 1475 | |
Michal Vasko | 3edeaf7 | 2016-02-11 13:17:43 +0100 | [diff] [blame] | 1476 | rc = resolve_choice_default_schema_nodeid(d->dflt, choice->child, (const struct lys_node **)&node); |
Michal Vasko | 9bb061b | 2016-02-12 11:00:19 +0100 | [diff] [blame] | 1477 | if (rc || !node) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1478 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1479 | goto error; |
| 1480 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1481 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1482 | if (!choice->dflt || (choice->dflt != node)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1483 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
| 1484 | 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] | 1485 | goto error; |
| 1486 | } |
| 1487 | } else { /* add (already checked) and replace */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1488 | choice->dflt = node; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1489 | if (!choice->dflt) { |
| 1490 | /* default branch not found */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1491 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1492 | goto error; |
| 1493 | } |
| 1494 | } |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1495 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 1496 | leaf = (struct lys_node_leaf *)dev_target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1497 | |
| 1498 | if (d->mod == LY_DEVIATE_ADD) { |
| 1499 | /* check that there is no current value */ |
| 1500 | if (leaf->dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1501 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1502 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1503 | goto error; |
| 1504 | } |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 1505 | /* check collision with mandatory */ |
| 1506 | if (leaf->flags & LYS_MAND_TRUE) { |
Radek Krejci | 6052ada | 2016-04-05 16:37:51 +0200 | [diff] [blame] | 1507 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 1508 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
Radek Krejci | 6052ada | 2016-04-05 16:37:51 +0200 | [diff] [blame] | 1509 | "Adding the \"default\" statement is forbidden on leaf with the \"mandatory\" statement."); |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 1510 | goto error; |
| 1511 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1512 | } |
| 1513 | |
| 1514 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | b42b697 | 2016-06-06 14:21:30 +0200 | [diff] [blame] | 1515 | if (!leaf->dflt || !ly_strequal(leaf->dflt, d->dflt, 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1516 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
| 1517 | 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] | 1518 | goto error; |
| 1519 | } |
| 1520 | /* remove value */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1521 | lydict_remove(ctx, leaf->dflt); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1522 | leaf->dflt = NULL; |
| 1523 | } else { /* add (already checked) and replace */ |
| 1524 | /* remove value */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1525 | lydict_remove(ctx, leaf->dflt); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1526 | |
| 1527 | /* set new value */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1528 | leaf->dflt = lydict_insert(ctx, d->dflt, 0); |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 1529 | |
| 1530 | /* remember to check it later (it may not fit now, but the type can be deviated too) */ |
| 1531 | leaf_dflt_check = ly_realloc(leaf_dflt_check, ++leaf_dflt_check_count * sizeof *leaf_dflt_check); |
| 1532 | if (!leaf_dflt_check) { |
| 1533 | LOGMEM; |
| 1534 | goto error; |
| 1535 | } |
| 1536 | leaf_dflt_check[leaf_dflt_check_count - 1] = leaf; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1537 | } |
| 1538 | } else { |
| 1539 | /* invalid target for default value */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1540 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1541 | 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] | 1542 | goto error; |
| 1543 | } |
| 1544 | } else if (!strcmp(child->name, "mandatory")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1545 | if (d->flags & LYS_MAND_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1546 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1547 | goto error; |
| 1548 | } |
| 1549 | |
| 1550 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1551 | if (!(dev_target->nodetype & (LYS_LEAF | LYS_CHOICE | LYS_ANYXML))) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1552 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1553 | 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] | 1554 | goto error; |
| 1555 | } |
| 1556 | |
| 1557 | GETVAL(value, child, "value"); |
| 1558 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1559 | d->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1560 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1561 | d->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1562 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1563 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1564 | goto error; |
| 1565 | } |
| 1566 | |
| 1567 | if (d->mod == LY_DEVIATE_ADD) { |
| 1568 | /* check that there is no current value */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1569 | if (dev_target->flags & LYS_MAND_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1570 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1571 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1572 | goto error; |
| 1573 | } |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 1574 | /* check collision with default-stmt */ |
| 1575 | if ((dev_target->nodetype == LYS_LEAF) && ((struct lys_node_leaf *)(dev_target))->dflt) { |
Radek Krejci | 6052ada | 2016-04-05 16:37:51 +0200 | [diff] [blame] | 1576 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, child->name, child->parent->name); |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 1577 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
Radek Krejci | 6052ada | 2016-04-05 16:37:51 +0200 | [diff] [blame] | 1578 | "Adding the \"mandatory\" statement is forbidden on leaf with the \"default\" statement."); |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 1579 | goto error; |
| 1580 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1581 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 1582 | dev_target->flags |= d->flags & LYS_MAND_MASK; |
| 1583 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 1584 | /* check that there was a value before */ |
| 1585 | if (!(dev_target->flags & LYS_MAND_MASK)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1586 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1587 | 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] | 1588 | goto error; |
| 1589 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1590 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 1591 | dev_target->flags &= ~LYS_MAND_MASK; |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1592 | dev_target->flags |= d->flags & LYS_MAND_MASK; |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 1593 | } else if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1594 | /* del mandatory is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1595 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "mandatory", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1596 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1597 | } |
| 1598 | } else if (!strcmp(child->name, "min-elements")) { |
| 1599 | if (f_min) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1600 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1601 | goto error; |
| 1602 | } |
| 1603 | f_min = 1; |
| 1604 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1605 | if (deviate_minmax(dev_target, child, d, 0)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1606 | goto error; |
| 1607 | } |
| 1608 | } else if (!strcmp(child->name, "max-elements")) { |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1609 | if (f_max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1610 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1611 | goto error; |
| 1612 | } |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 1613 | f_max = 1; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1614 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1615 | if (deviate_minmax(dev_target, child, d, 1)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1616 | goto error; |
| 1617 | } |
| 1618 | } else if (!strcmp(child->name, "must")) { |
| 1619 | c_must++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1620 | /* 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] | 1621 | continue; |
| 1622 | } else if (!strcmp(child->name, "type")) { |
| 1623 | if (d->type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1624 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1625 | goto error; |
| 1626 | } |
| 1627 | |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1628 | /* add, del type is forbidden */ |
| 1629 | if (d->mod == LY_DEVIATE_ADD) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1630 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "deviate add"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1631 | goto error; |
| 1632 | } else if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1633 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "type", "deviate delete"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1634 | goto error; |
| 1635 | } |
| 1636 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1637 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1638 | if (dev_target->nodetype == LYS_LEAF) { |
| 1639 | t = &((struct lys_node_leaf *)dev_target)->type; |
| 1640 | } else if (dev_target->nodetype == LYS_LEAFLIST) { |
| 1641 | t = &((struct lys_node_leaflist *)dev_target)->type; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1642 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1643 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1644 | 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] | 1645 | goto error; |
| 1646 | } |
| 1647 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1648 | /* replace */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1649 | lys_type_free(ctx, t); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1650 | /* HACK for unres */ |
| 1651 | t->der = (struct lys_tpdf *)child; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1652 | if (unres_schema_add_node(module, unres, t, UNRES_TYPE_DER, dev_target)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1653 | goto error; |
| 1654 | } |
| 1655 | d->type = t; |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 1656 | |
| 1657 | /* check leaf default later (type may not fit now, but default can be deviated later too) */ |
| 1658 | if (dev_target->nodetype == LYS_LEAF) { |
| 1659 | leaf_dflt_check = ly_realloc(leaf_dflt_check, ++leaf_dflt_check_count * sizeof *leaf_dflt_check); |
| 1660 | if (!leaf_dflt_check) { |
| 1661 | LOGMEM; |
| 1662 | goto error; |
| 1663 | } |
| 1664 | leaf_dflt_check[leaf_dflt_check_count - 1] = (struct lys_node_leaf *)dev_target; |
| 1665 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1666 | } else if (!strcmp(child->name, "unique")) { |
| 1667 | c_uniq++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1668 | /* 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] | 1669 | continue; |
| 1670 | } else if (!strcmp(child->name, "units")) { |
| 1671 | if (d->units) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1672 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1673 | goto error; |
| 1674 | } |
| 1675 | |
| 1676 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1677 | if (dev_target->nodetype == LYS_LEAFLIST) { |
| 1678 | stritem = &((struct lys_node_leaflist *)dev_target)->units; |
| 1679 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 1680 | stritem = &((struct lys_node_leaf *)dev_target)->units; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1681 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1682 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1683 | 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] | 1684 | goto error; |
| 1685 | } |
| 1686 | |
| 1687 | /* get units value */ |
| 1688 | GETVAL(value, child, "name"); |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1689 | d->units = lydict_insert(ctx, value, 0); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1690 | |
| 1691 | /* apply to target */ |
| 1692 | if (d->mod == LY_DEVIATE_ADD) { |
| 1693 | /* check that there is no current value */ |
| 1694 | if (*stritem) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1695 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1696 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1697 | goto error; |
| 1698 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1699 | |
Michal Vasko | 21be1b3 | 2016-03-07 12:31:34 +0100 | [diff] [blame] | 1700 | *stritem = lydict_insert(ctx, value, 0); |
| 1701 | } else if (d->mod == LY_DEVIATE_RPL) { |
| 1702 | /* check that there was a value before */ |
| 1703 | if (!*stritem) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1704 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1705 | 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] | 1706 | goto error; |
| 1707 | } |
| 1708 | |
| 1709 | lydict_remove(ctx, *stritem); |
| 1710 | *stritem = lydict_insert(ctx, value, 0); |
| 1711 | } else if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1712 | /* check values */ |
Michal Vasko | b42b697 | 2016-06-06 14:21:30 +0200 | [diff] [blame] | 1713 | if (!ly_strequal(*stritem, d->units, 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1714 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
| 1715 | 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] | 1716 | goto error; |
| 1717 | } |
| 1718 | /* remove current units value of the target */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1719 | lydict_remove(ctx, *stritem); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1720 | } |
| 1721 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1722 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1723 | goto error; |
| 1724 | } |
| 1725 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1726 | /* 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] | 1727 | } |
| 1728 | |
| 1729 | if (c_must) { |
| 1730 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1731 | switch (dev_target->nodetype) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1732 | case LYS_LEAF: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1733 | trg_must = &((struct lys_node_leaf *)dev_target)->must; |
| 1734 | trg_must_size = &((struct lys_node_leaf *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1735 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1736 | case LYS_CONTAINER: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1737 | trg_must = &((struct lys_node_container *)dev_target)->must; |
| 1738 | trg_must_size = &((struct lys_node_container *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1739 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1740 | case LYS_LEAFLIST: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1741 | trg_must = &((struct lys_node_leaflist *)dev_target)->must; |
| 1742 | trg_must_size = &((struct lys_node_leaflist *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1743 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1744 | case LYS_LIST: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1745 | trg_must = &((struct lys_node_list *)dev_target)->must; |
| 1746 | trg_must_size = &((struct lys_node_list *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1747 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1748 | case LYS_ANYXML: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1749 | trg_must = &((struct lys_node_anyxml *)dev_target)->must; |
| 1750 | trg_must_size = &((struct lys_node_anyxml *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1751 | break; |
| 1752 | default: |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1753 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1754 | 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] | 1755 | goto error; |
| 1756 | } |
| 1757 | |
| 1758 | if (d->mod == LY_DEVIATE_RPL) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1759 | /* replace must is forbidden */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1760 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "must", "deviate replace"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1761 | goto error; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1762 | } else if (d->mod == LY_DEVIATE_ADD) { |
| 1763 | /* reallocate the must array of the target */ |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1764 | 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] | 1765 | if (!d->must) { |
| 1766 | LOGMEM; |
| 1767 | goto error; |
| 1768 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1769 | *trg_must = d->must; |
Michal Vasko | 979ad5b | 2015-10-23 10:12:55 +0200 | [diff] [blame] | 1770 | d->must = &((*trg_must)[*trg_must_size]); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1771 | d->must_size = c_must; |
| 1772 | } else { /* LY_DEVIATE_DEL */ |
| 1773 | d->must = calloc(c_must, sizeof *d->must); |
| 1774 | } |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1775 | if (!d->must) { |
| 1776 | LOGMEM; |
| 1777 | goto error; |
| 1778 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1779 | } |
| 1780 | if (c_uniq) { |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1781 | /* replace unique is forbidden */ |
| 1782 | if (d->mod == LY_DEVIATE_RPL) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1783 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "unique", "deviate replace"); |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1784 | goto error; |
| 1785 | } |
| 1786 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1787 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1788 | if (dev_target->nodetype != LYS_LIST) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1789 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
| 1790 | 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] | 1791 | goto error; |
| 1792 | } |
| 1793 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1794 | list = (struct lys_node_list *)dev_target; |
Michal Vasko | f7e57d5 | 2016-03-07 11:31:09 +0100 | [diff] [blame] | 1795 | if (d->mod == LY_DEVIATE_ADD) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1796 | /* reallocate the unique array of the target */ |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1797 | 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] | 1798 | list->unique = d->unique; |
| 1799 | d->unique = &list->unique[list->unique_size]; |
| 1800 | d->unique_size = c_uniq; |
| 1801 | } else { /* LY_DEVIATE_DEL */ |
| 1802 | d->unique = calloc(c_uniq, sizeof *d->unique); |
| 1803 | } |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1804 | if (!d->unique) { |
| 1805 | LOGMEM; |
| 1806 | goto error; |
| 1807 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1808 | } |
| 1809 | |
| 1810 | /* process deviation properties with 0..n cardinality */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1811 | LY_TREE_FOR(develem->child, child) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1812 | if (!strcmp(child->name, "must")) { |
| 1813 | if (d->mod == LY_DEVIATE_DEL) { |
| 1814 | if (fill_yin_must(module, child, &d->must[d->must_size])) { |
| 1815 | goto error; |
| 1816 | } |
| 1817 | |
| 1818 | /* find must to delete, we are ok with just matching conditions */ |
| 1819 | for (i = 0; i < *trg_must_size; i++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 1820 | 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] | 1821 | /* we have a match, free the must structure ... */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1822 | lys_restr_free(ctx, &((*trg_must)[i])); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1823 | /* ... and maintain the array */ |
| 1824 | (*trg_must_size)--; |
| 1825 | if (i != *trg_must_size) { |
| 1826 | (*trg_must)[i].expr = (*trg_must)[*trg_must_size].expr; |
| 1827 | (*trg_must)[i].dsc = (*trg_must)[*trg_must_size].dsc; |
| 1828 | (*trg_must)[i].ref = (*trg_must)[*trg_must_size].ref; |
| 1829 | (*trg_must)[i].eapptag = (*trg_must)[*trg_must_size].eapptag; |
| 1830 | (*trg_must)[i].emsg = (*trg_must)[*trg_must_size].emsg; |
| 1831 | } |
| 1832 | if (!(*trg_must_size)) { |
| 1833 | free(*trg_must); |
| 1834 | *trg_must = NULL; |
| 1835 | } else { |
| 1836 | (*trg_must)[*trg_must_size].expr = NULL; |
| 1837 | (*trg_must)[*trg_must_size].dsc = NULL; |
| 1838 | (*trg_must)[*trg_must_size].ref = NULL; |
| 1839 | (*trg_must)[*trg_must_size].eapptag = NULL; |
| 1840 | (*trg_must)[*trg_must_size].emsg = NULL; |
| 1841 | } |
| 1842 | |
| 1843 | i = -1; /* set match flag */ |
| 1844 | break; |
| 1845 | } |
| 1846 | } |
| 1847 | d->must_size++; |
| 1848 | if (i != -1) { |
| 1849 | /* no match found */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1850 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, |
Radek Krejci | adb5761 | 2016-02-16 13:34:34 +0100 | [diff] [blame] | 1851 | d->must[d->must_size - 1].expr, child->name); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1852 | 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] | 1853 | goto error; |
| 1854 | } |
| 1855 | } else { /* replace or add */ |
Michal Vasko | f92a728 | 2016-02-11 12:35:57 +0100 | [diff] [blame] | 1856 | memset(&((*trg_must)[*trg_must_size]), 0, sizeof **trg_must); |
| 1857 | if (fill_yin_must(module, child, &((*trg_must)[*trg_must_size]))) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1858 | goto error; |
| 1859 | } |
| 1860 | (*trg_must_size)++; |
| 1861 | } |
| 1862 | } else if (!strcmp(child->name, "unique")) { |
| 1863 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | a0a10ab | 2016-03-07 14:41:23 +0100 | [diff] [blame] | 1864 | memset(&d->unique[d->unique_size], 0, sizeof *d->unique); |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1865 | 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] | 1866 | d->unique_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1867 | goto error; |
| 1868 | } |
| 1869 | |
| 1870 | /* find unique structures to delete */ |
| 1871 | for (i = 0; i < list->unique_size; i++) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1872 | 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] | 1873 | continue; |
| 1874 | } |
| 1875 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1876 | for (j = 0; j < d->unique[d->unique_size].expr_size; j++) { |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 1877 | 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] | 1878 | break; |
| 1879 | } |
| 1880 | } |
| 1881 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1882 | if (j == d->unique[d->unique_size].expr_size) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1883 | /* we have a match, free the unique structure ... */ |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1884 | for (j = 0; j < list->unique[i].expr_size; j++) { |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1885 | lydict_remove(ctx, list->unique[i].expr[j]); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1886 | } |
| 1887 | free(list->unique[i].expr); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1888 | /* ... and maintain the array */ |
| 1889 | list->unique_size--; |
| 1890 | if (i != list->unique_size) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1891 | list->unique[i].expr_size = list->unique[list->unique_size].expr_size; |
| 1892 | list->unique[i].expr = list->unique[list->unique_size].expr; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | if (!list->unique_size) { |
| 1896 | free(list->unique); |
| 1897 | list->unique = NULL; |
| 1898 | } else { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1899 | list->unique[list->unique_size].expr_size = 0; |
| 1900 | list->unique[list->unique_size].expr = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1901 | } |
| 1902 | |
| 1903 | i = -1; /* set match flag */ |
| 1904 | break; |
| 1905 | } |
| 1906 | } |
| 1907 | |
| 1908 | d->unique_size++; |
| 1909 | if (i != -1) { |
| 1910 | /* no match found */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1911 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, lyxml_get_attr(child, "tag", NULL), child->name); |
| 1912 | 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] | 1913 | goto error; |
| 1914 | } |
| 1915 | } else { /* replace or add */ |
Michal Vasko | a0a10ab | 2016-03-07 14:41:23 +0100 | [diff] [blame] | 1916 | memset(&list->unique[list->unique_size], 0, sizeof *list->unique); |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1917 | 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] | 1918 | list->unique_size++; |
| 1919 | if (i) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1920 | goto error; |
| 1921 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1922 | } |
| 1923 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1924 | } |
| 1925 | } |
| 1926 | |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 1927 | /* now check whether default value, if any, matches the type */ |
| 1928 | for (i = 0; i < leaf_dflt_check_count; ++i) { |
| 1929 | if (leaf_dflt_check[i]->dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1930 | rc = unres_schema_add_str(module, unres, &leaf_dflt_check[i]->type, UNRES_TYPE_DFLT, leaf_dflt_check[i]->dflt); |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 1931 | if (rc == -1) { |
| 1932 | goto error; |
| 1933 | } else if (rc == EXIT_FAILURE) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1934 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, leaf_dflt_check[i]->dflt, "default"); |
| 1935 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Leaf \"%s\" default value no longer matches its type.", dev->target_name); |
Michal Vasko | 43a1feb | 2016-03-07 12:03:02 +0100 | [diff] [blame] | 1936 | goto error; |
| 1937 | } |
| 1938 | } |
| 1939 | } |
| 1940 | free(leaf_dflt_check); |
| 1941 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1942 | return EXIT_SUCCESS; |
| 1943 | |
| 1944 | error: |
Michal Vasko | 3486713 | 2016-03-11 10:26:38 +0100 | [diff] [blame] | 1945 | free(leaf_dflt_check); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1946 | return EXIT_FAILURE; |
| 1947 | } |
| 1948 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1949 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1950 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1951 | 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] | 1952 | struct unres_schema *unres) |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1953 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1954 | const char *value; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1955 | struct lyxml_elem *child, *next; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1956 | struct lys_node *node; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 1957 | int c = 0, ret; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1958 | |
Michal Vasko | 591e0b2 | 2015-08-13 13:53:43 +0200 | [diff] [blame] | 1959 | aug->nodetype = LYS_AUGMENT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1960 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1961 | aug->target_name = transform_schema2json(module, value); |
Michal Vasko | 488c19e | 2015-10-20 15:21:00 +0200 | [diff] [blame] | 1962 | if (!aug->target_name) { |
| 1963 | goto error; |
| 1964 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1965 | aug->parent = parent; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1966 | |
Michal Vasko | 1d87a92 | 2015-08-21 12:57:16 +0200 | [diff] [blame] | 1967 | 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] | 1968 | goto error; |
| 1969 | } |
| 1970 | |
| 1971 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1972 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1973 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1974 | lyxml_free(module->ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1975 | continue; |
| 1976 | } |
| 1977 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1978 | if (!strcmp(child->name, "if-feature")) { |
| 1979 | c++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1980 | continue; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1981 | } else if (!strcmp(child->name, "when")) { |
| 1982 | if (aug->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 1983 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1984 | goto error; |
| 1985 | } |
| 1986 | |
| 1987 | aug->when = read_yin_when(module, child); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1988 | if (!aug->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1989 | lyxml_free(module->ctx, child); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1990 | goto error; |
| 1991 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1992 | lyxml_free(module->ctx, child); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1993 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1994 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1995 | /* check allowed data sub-statements */ |
| 1996 | } else if (!strcmp(child->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1997 | node = read_yin_container(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1998 | } else if (!strcmp(child->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1999 | node = read_yin_leaflist(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2000 | } else if (!strcmp(child->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2001 | node = read_yin_leaf(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2002 | } else if (!strcmp(child->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2003 | node = read_yin_list(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2004 | } else if (!strcmp(child->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2005 | node = read_yin_uses(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2006 | } else if (!strcmp(child->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2007 | node = read_yin_case(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2008 | } else if (!strcmp(child->name, "case")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2009 | node = read_yin_case(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2010 | } else if (!strcmp(child->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2011 | node = read_yin_anyxml(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2012 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2013 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2014 | goto error; |
| 2015 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2016 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2017 | if (!node) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2018 | goto error; |
| 2019 | } |
| 2020 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2021 | node = NULL; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2022 | lyxml_free(module->ctx, child); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2023 | } |
| 2024 | |
| 2025 | if (c) { |
| 2026 | aug->features = calloc(c, sizeof *aug->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2027 | if (!aug->features) { |
| 2028 | LOGMEM; |
| 2029 | goto error; |
| 2030 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2031 | } |
| 2032 | |
| 2033 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 2034 | if (!strcmp(child->name, "if-feature")) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 2035 | ret = fill_yin_iffeature((struct lys_node *)aug, child, &aug->features[aug->features_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 2036 | aug->features_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 2037 | if (ret) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2038 | goto error; |
| 2039 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2040 | lyxml_free(module->ctx, child); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2041 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2042 | } |
| 2043 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2044 | /* aug->child points to the parsed nodes, they must now be |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 2045 | * connected to the tree and adjusted (if possible right now). |
| 2046 | * However, if this is augment in a uses, it gets resolved |
| 2047 | * when the uses does and cannot be resolved now for sure |
| 2048 | * (the grouping was not yet copied into uses). |
| 2049 | */ |
| 2050 | if (!parent || (parent->nodetype != LYS_USES)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2051 | if (unres_schema_add_node(module, unres, aug, UNRES_AUGMENT, NULL) == -1) { |
Michal Vasko | 4adc10f | 2015-08-11 15:26:17 +0200 | [diff] [blame] | 2052 | goto error; |
| 2053 | } |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 2054 | } |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2055 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2056 | return EXIT_SUCCESS; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2057 | |
| 2058 | error: |
| 2059 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2060 | return EXIT_FAILURE; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2061 | } |
| 2062 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2063 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2064 | static int |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 2065 | fill_yin_refine(struct lys_module *module, struct lyxml_elem *yin, struct lys_refine *rfn) |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2066 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2067 | struct lyxml_elem *sub, *next; |
| 2068 | const char *value; |
| 2069 | char *endptr; |
| 2070 | int f_mand = 0, f_min = 0, f_max = 0; |
| 2071 | int c_must = 0; |
| 2072 | int r; |
| 2073 | unsigned long int val; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2074 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2075 | 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] | 2076 | goto error; |
| 2077 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2078 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2079 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2080 | rfn->target_name = transform_schema2json(module, value); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 2081 | if (!rfn->target_name) { |
| 2082 | goto error; |
| 2083 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2084 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2085 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2086 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2087 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2088 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2089 | continue; |
| 2090 | } |
| 2091 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2092 | /* limited applicability */ |
| 2093 | if (!strcmp(sub->name, "default")) { |
| 2094 | /* leaf or choice */ |
| 2095 | if (rfn->mod.dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2096 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2097 | goto error; |
| 2098 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2099 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2100 | /* check possibility of statements combination */ |
| 2101 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2102 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2103 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2104 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 2105 | 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] | 2106 | goto error; |
| 2107 | } |
| 2108 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2109 | rfn->target_type = LYS_LEAF | LYS_CHOICE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2110 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2111 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2112 | GETVAL(value, sub, "value"); |
| 2113 | rfn->mod.dflt = lydict_insert(module->ctx, value, strlen(value)); |
| 2114 | } else if (!strcmp(sub->name, "mandatory")) { |
| 2115 | /* leaf, choice or anyxml */ |
| 2116 | if (f_mand) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2117 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2118 | goto error; |
| 2119 | } |
| 2120 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2121 | * multiple mandatory statements with the "false" value |
| 2122 | */ |
| 2123 | f_mand = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2124 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2125 | /* check possibility of statements combination */ |
| 2126 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2127 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE | LYS_ANYXML); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2128 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2129 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 2130 | 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] | 2131 | goto error; |
| 2132 | } |
| 2133 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2134 | rfn->target_type = LYS_LEAF | LYS_CHOICE | LYS_ANYXML; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2135 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2136 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2137 | GETVAL(value, sub, "value"); |
| 2138 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2139 | rfn->flags |= LYS_MAND_TRUE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2140 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2141 | rfn->flags |= LYS_MAND_FALSE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2142 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2143 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2144 | goto error; |
| 2145 | } |
| 2146 | } else if (!strcmp(sub->name, "min-elements")) { |
| 2147 | /* list or leaf-list */ |
| 2148 | if (f_min) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2149 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2150 | goto error; |
| 2151 | } |
| 2152 | f_min = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2153 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2154 | /* check possibility of statements combination */ |
| 2155 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2156 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2157 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2158 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 2159 | 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] | 2160 | goto error; |
| 2161 | } |
| 2162 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2163 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2164 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2165 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2166 | GETVAL(value, sub, "value"); |
| 2167 | while (isspace(value[0])) { |
| 2168 | value++; |
| 2169 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2170 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2171 | /* convert it to uint32_t */ |
| 2172 | errno = 0; |
| 2173 | endptr = NULL; |
| 2174 | val = strtoul(value, &endptr, 10); |
| 2175 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2176 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2177 | goto error; |
| 2178 | } |
| 2179 | rfn->mod.list.min = (uint32_t) val; |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 2180 | rfn->flags |= LYS_RFN_MINSET; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2181 | } else if (!strcmp(sub->name, "max-elements")) { |
| 2182 | /* list or leaf-list */ |
| 2183 | if (f_max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2184 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2185 | goto error; |
| 2186 | } |
| 2187 | f_max = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2188 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2189 | /* check possibility of statements combination */ |
| 2190 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2191 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2192 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2193 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 2194 | 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] | 2195 | goto error; |
| 2196 | } |
| 2197 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2198 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2199 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2200 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2201 | GETVAL(value, sub, "value"); |
| 2202 | while (isspace(value[0])) { |
| 2203 | value++; |
| 2204 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2205 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2206 | if (!strcmp(value, "unbounded")) { |
| 2207 | rfn->mod.list.max = 0; |
| 2208 | } else { |
| 2209 | /* convert it to uint32_t */ |
| 2210 | errno = 0; |
| 2211 | endptr = NULL; |
| 2212 | val = strtoul(value, &endptr, 10); |
| 2213 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2214 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 2215 | goto error; |
| 2216 | } |
| 2217 | rfn->mod.list.max = (uint32_t) val; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2218 | } |
Radek Krejci | 0f04a6c | 2016-04-14 16:16:36 +0200 | [diff] [blame] | 2219 | rfn->flags |= LYS_RFN_MAXSET; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2220 | } else if (!strcmp(sub->name, "presence")) { |
| 2221 | /* container */ |
| 2222 | if (rfn->mod.presence) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2223 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2224 | goto error; |
| 2225 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2226 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2227 | /* check possibility of statements combination */ |
| 2228 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2229 | rfn->target_type &= LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2230 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2231 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 2232 | 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] | 2233 | goto error; |
| 2234 | } |
| 2235 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2236 | rfn->target_type = LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2237 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2238 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2239 | GETVAL(value, sub, "value"); |
| 2240 | rfn->mod.presence = lydict_insert(module->ctx, value, strlen(value)); |
| 2241 | } else if (!strcmp(sub->name, "must")) { |
| 2242 | /* leaf-list, list, container or anyxml */ |
| 2243 | /* check possibility of statements combination */ |
| 2244 | if (rfn->target_type) { |
Michal Vasko | bc18a9d | 2016-05-23 15:13:35 +0200 | [diff] [blame] | 2245 | rfn->target_type &= (LYS_LEAF | LYS_LIST | LYS_LEAFLIST | LYS_CONTAINER | LYS_ANYXML); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2246 | if (!rfn->target_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2247 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, sub->name, yin->name); |
| 2248 | 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] | 2249 | goto error; |
| 2250 | } |
| 2251 | } else { |
Michal Vasko | bc18a9d | 2016-05-23 15:13:35 +0200 | [diff] [blame] | 2252 | rfn->target_type = LYS_LEAF | LYS_LIST | LYS_LEAFLIST | LYS_CONTAINER | LYS_ANYXML; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2253 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2254 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2255 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 2256 | continue; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2257 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2258 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2259 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2260 | goto error; |
| 2261 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2262 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2263 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2264 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2265 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2266 | /* process nodes with cardinality of 0..n */ |
| 2267 | if (c_must) { |
| 2268 | rfn->must = calloc(c_must, sizeof *rfn->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2269 | if (!rfn->must) { |
| 2270 | LOGMEM; |
| 2271 | goto error; |
| 2272 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2273 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2274 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 2275 | r = fill_yin_must(module, sub, &rfn->must[rfn->must_size]); |
| 2276 | rfn->must_size++; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2277 | if (r) { |
| 2278 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2279 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2280 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2281 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2282 | return EXIT_SUCCESS; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2283 | |
| 2284 | error: |
| 2285 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2286 | return EXIT_FAILURE; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2287 | } |
| 2288 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2289 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2290 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2291 | 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] | 2292 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2293 | struct lyxml_elem *child; |
| 2294 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2295 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2296 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2297 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2298 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2299 | continue; |
| 2300 | } |
| 2301 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2302 | if (!strcmp(child->name, "prefix")) { |
| 2303 | GETVAL(value, child, "value"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2304 | if (lyp_check_identifier(value, LY_IDENT_PREFIX, module, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2305 | goto error; |
| 2306 | } |
| 2307 | imp->prefix = lydict_insert(module->ctx, value, strlen(value)); |
| 2308 | } else if (!strcmp(child->name, "revision-date")) { |
| 2309 | if (imp->rev[0]) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2310 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2311 | goto error; |
| 2312 | } |
| 2313 | GETVAL(value, child, "date"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2314 | if (lyp_check_date(value)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2315 | goto error; |
| 2316 | } |
| 2317 | memcpy(imp->rev, value, LY_REV_SIZE - 1); |
| 2318 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2319 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2320 | goto error; |
| 2321 | } |
| 2322 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2323 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2324 | /* check mandatory information */ |
| 2325 | if (!imp->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2326 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2327 | goto error; |
| 2328 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2329 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2330 | GETVAL(value, yin, "module"); |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2331 | |
Pavol Vican | e994fda | 2016-03-22 10:47:58 +0100 | [diff] [blame] | 2332 | return lyp_check_import(module, value, imp); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2333 | |
| 2334 | error: |
| 2335 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2336 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2337 | } |
| 2338 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2339 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2340 | static int |
Michal Vasko | 5ff7882 | 2016-02-12 09:33:31 +0100 | [diff] [blame] | 2341 | fill_yin_include(struct lys_module *module, struct lys_submodule *submodule, struct lyxml_elem *yin, |
| 2342 | struct lys_include *inc, struct unres_schema *unres) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2343 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2344 | struct lyxml_elem *child; |
| 2345 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2346 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2347 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2348 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2349 | /* garbage */ |
| 2350 | continue; |
| 2351 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2352 | if (!strcmp(child->name, "revision-date")) { |
| 2353 | if (inc->rev[0]) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2354 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2355 | goto error; |
| 2356 | } |
| 2357 | GETVAL(value, child, "date"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2358 | if (lyp_check_date(value)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2359 | goto error; |
| 2360 | } |
| 2361 | memcpy(inc->rev, value, LY_REV_SIZE - 1); |
| 2362 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2363 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2364 | goto error; |
| 2365 | } |
| 2366 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2367 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2368 | GETVAL(value, yin, "module"); |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2369 | |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 2370 | return lyp_check_include(module, submodule, value, inc, unres); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2371 | |
| 2372 | error: |
| 2373 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2374 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2375 | } |
| 2376 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2377 | /* logs directly |
| 2378 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2379 | * Covers: |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 2380 | * description, reference, status, optionaly config |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 2381 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2382 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2383 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2384 | read_yin_common(struct lys_module *module, struct lys_node *parent, |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2385 | struct lys_node *node, struct lyxml_elem *xmlnode, int opt) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2386 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2387 | const char *value; |
| 2388 | struct lyxml_elem *sub, *next; |
| 2389 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2390 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2391 | if (opt & OPT_MODULE) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2392 | node->module = module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2393 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2394 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2395 | if (opt & OPT_IDENT) { |
| 2396 | GETVAL(value, xmlnode, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2397 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2398 | goto error; |
| 2399 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2400 | node->name = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2401 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2402 | |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2403 | /* inherit NACM flags */ |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2404 | if ((opt & OPT_NACMEXT) && parent) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2405 | node->nacm = parent->nacm; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2406 | } |
| 2407 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2408 | /* process local parameters */ |
| 2409 | LY_TREE_FOR_SAFE(xmlnode->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2410 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2411 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2412 | lyxml_free(ctx, sub); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2413 | continue; |
| 2414 | } |
| 2415 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 2416 | /* NACM extensions */ |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2417 | if ((opt & OPT_NACMEXT) && !strcmp(sub->ns->value, LY_NSNACM)) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2418 | if (!strcmp(sub->name, "default-deny-write")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2419 | node->nacm |= LYS_NACM_DENYW; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2420 | } else if (!strcmp(sub->name, "default-deny-all")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2421 | node->nacm |= LYS_NACM_DENYA; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2422 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2423 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2424 | goto error; |
| 2425 | } |
| 2426 | } |
| 2427 | |
| 2428 | /* else garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2429 | lyxml_free(ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2430 | continue; |
| 2431 | } |
| 2432 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2433 | if (!strcmp(sub->name, "description")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2434 | if (node->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2435 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2436 | goto error; |
| 2437 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2438 | node->dsc = read_yin_subnode(ctx, sub, "text"); |
| 2439 | if (!node->dsc) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2440 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2441 | } |
| 2442 | } else if (!strcmp(sub->name, "reference")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2443 | if (node->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2444 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2445 | goto error; |
| 2446 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2447 | node->ref = read_yin_subnode(ctx, sub, "text"); |
| 2448 | if (!node->ref) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2449 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2450 | } |
| 2451 | } else if (!strcmp(sub->name, "status")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2452 | if (node->flags & LYS_STATUS_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2453 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2454 | goto error; |
| 2455 | } |
| 2456 | GETVAL(value, sub, "value"); |
| 2457 | if (!strcmp(value, "current")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2458 | node->flags |= LYS_STATUS_CURR; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2459 | } else if (!strcmp(value, "deprecated")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2460 | node->flags |= LYS_STATUS_DEPRC; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2461 | } else if (!strcmp(value, "obsolete")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2462 | node->flags |= LYS_STATUS_OBSLT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2463 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2464 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2465 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2466 | } |
| 2467 | } else if ((opt & OPT_CONFIG) && !strcmp(sub->name, "config")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2468 | if (node->flags & LYS_CONFIG_MASK) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2469 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2470 | goto error; |
| 2471 | } |
| 2472 | GETVAL(value, sub, "value"); |
| 2473 | if (!strcmp(value, "false")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2474 | node->flags |= LYS_CONFIG_R; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2475 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2476 | node->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2477 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2478 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2479 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2480 | } |
Radek Krejci | 32c7bd6 | 2016-04-14 17:47:04 +0200 | [diff] [blame] | 2481 | node->flags |= LYS_CONFIG_SET; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2482 | } else { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2483 | /* skip the lyxml_free */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2484 | continue; |
| 2485 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2486 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2487 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2488 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2489 | if ((opt & OPT_INHERIT) && !(node->flags & LYS_CONFIG_MASK)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2490 | /* get config flag from parent */ |
Radek Krejci | 32c7bd6 | 2016-04-14 17:47:04 +0200 | [diff] [blame] | 2491 | if (parent && (parent->flags & LYS_CONFIG_R)) { |
| 2492 | node->flags |= LYS_CONFIG_R; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2493 | } else { |
| 2494 | /* default config is true */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2495 | node->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2496 | } |
| 2497 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2498 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2499 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 2500 | |
| 2501 | error: |
| 2502 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2503 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2504 | } |
| 2505 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2506 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2507 | static struct lys_when * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2508 | read_yin_when(struct lys_module *module, struct lyxml_elem *yin) |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2509 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2510 | struct lys_when *retval = NULL; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2511 | struct lyxml_elem *child; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2512 | const char *value; |
| 2513 | |
| 2514 | retval = calloc(1, sizeof *retval); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2515 | if (!retval) { |
| 2516 | LOGMEM; |
| 2517 | return NULL; |
| 2518 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2519 | |
| 2520 | GETVAL(value, yin, "condition"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2521 | retval->cond = transform_schema2json(module, value); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 2522 | if (!retval->cond) { |
| 2523 | goto error; |
| 2524 | } |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2525 | if (lyxp_syntax_check(retval->cond)) { |
Michal Vasko | 77dc565 | 2016-02-15 12:32:42 +0100 | [diff] [blame] | 2526 | goto error; |
| 2527 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2528 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2529 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2530 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2531 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2532 | continue; |
| 2533 | } |
| 2534 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2535 | if (!strcmp(child->name, "description")) { |
| 2536 | if (retval->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2537 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2538 | goto error; |
| 2539 | } |
| 2540 | retval->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 2541 | if (!retval->dsc) { |
| 2542 | goto error; |
| 2543 | } |
| 2544 | } else if (!strcmp(child->name, "reference")) { |
| 2545 | if (retval->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2546 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2547 | goto error; |
| 2548 | } |
| 2549 | retval->ref = read_yin_subnode(module->ctx, child, "text"); |
| 2550 | if (!retval->ref) { |
| 2551 | goto error; |
| 2552 | } |
| 2553 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2554 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2555 | goto error; |
| 2556 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2557 | } |
| 2558 | |
| 2559 | return retval; |
| 2560 | |
| 2561 | error: |
| 2562 | |
Michal Vasko | 0308dd6 | 2015-10-07 09:14:40 +0200 | [diff] [blame] | 2563 | lys_when_free(module->ctx, retval); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2564 | return NULL; |
| 2565 | } |
| 2566 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2567 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2568 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 2569 | read_yin_case(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 2570 | struct unres_schema *unres) |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2571 | { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2572 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2573 | struct lys_node_case *cs; |
| 2574 | struct lys_node *retval, *node = NULL; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 2575 | int c_ftrs = 0, ret; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2576 | |
Radek Krejci | e867c85 | 2015-08-27 09:52:34 +0200 | [diff] [blame] | 2577 | /* init */ |
| 2578 | memset(&root, 0, sizeof root); |
| 2579 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2580 | cs = calloc(1, sizeof *cs); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2581 | if (!cs) { |
| 2582 | LOGMEM; |
| 2583 | return NULL; |
| 2584 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2585 | cs->nodetype = LYS_CASE; |
| 2586 | cs->prev = (struct lys_node *)cs; |
| 2587 | retval = (struct lys_node *)cs; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2588 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2589 | 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] | 2590 | goto error; |
| 2591 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2592 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 2593 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 2594 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2595 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 2596 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2597 | goto error; |
| 2598 | } |
| 2599 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2600 | /* process choice's specific children */ |
| 2601 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2602 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2603 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2604 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2605 | continue; |
| 2606 | } |
| 2607 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2608 | if (!strcmp(sub->name, "container") || |
| 2609 | !strcmp(sub->name, "leaf-list") || |
| 2610 | !strcmp(sub->name, "leaf") || |
| 2611 | !strcmp(sub->name, "list") || |
| 2612 | !strcmp(sub->name, "uses") || |
| 2613 | !strcmp(sub->name, "choice") || |
| 2614 | !strcmp(sub->name, "anyxml")) { |
| 2615 | |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 2616 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2617 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2618 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2619 | c_ftrs++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2620 | /* 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] | 2621 | continue; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2622 | } else if (!strcmp(sub->name, "when")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2623 | if (cs->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2624 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2625 | goto error; |
| 2626 | } |
| 2627 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2628 | cs->when = read_yin_when(module, sub); |
| 2629 | if (!cs->when) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2630 | goto error; |
| 2631 | } |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2632 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2633 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2634 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2635 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2636 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2637 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2638 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2639 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2640 | if (c_ftrs) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2641 | cs->features = calloc(c_ftrs, sizeof *cs->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2642 | if (!cs->features) { |
| 2643 | LOGMEM; |
| 2644 | goto error; |
| 2645 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2646 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2647 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 2648 | ret = fill_yin_iffeature(retval, sub, &cs->features[cs->features_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 2649 | cs->features_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 2650 | if (ret) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2651 | goto error; |
| 2652 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2653 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 2654 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2655 | /* last part - process data nodes */ |
| 2656 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 2657 | if (!strcmp(sub->name, "container")) { |
| 2658 | node = read_yin_container(module, retval, sub, resolve, unres); |
| 2659 | } else if (!strcmp(sub->name, "leaf-list")) { |
| 2660 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
| 2661 | } else if (!strcmp(sub->name, "leaf")) { |
| 2662 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
| 2663 | } else if (!strcmp(sub->name, "list")) { |
| 2664 | node = read_yin_list(module, retval, sub, resolve, unres); |
| 2665 | } else if (!strcmp(sub->name, "choice")) { |
| 2666 | node = read_yin_choice(module, retval, sub, resolve, unres); |
| 2667 | } else if (!strcmp(sub->name, "uses")) { |
| 2668 | node = read_yin_uses(module, retval, sub, resolve, unres); |
| 2669 | } else if (!strcmp(sub->name, "anyxml")) { |
| 2670 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
| 2671 | } |
| 2672 | if (!node) { |
| 2673 | goto error; |
| 2674 | } |
| 2675 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2676 | lyxml_free(module->ctx, sub); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2677 | } |
| 2678 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2679 | return retval; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2680 | |
| 2681 | error: |
| 2682 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2683 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2684 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2685 | } |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 2686 | lys_node_free(retval, NULL, 0); |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2687 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2688 | return NULL; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2689 | } |
| 2690 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2691 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2692 | static struct lys_node * |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 2693 | 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] | 2694 | { |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 2695 | struct lyxml_elem *sub, *next, *dflt = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2696 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2697 | struct lys_node *retval, *node = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2698 | struct lys_node_choice *choice; |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 2699 | const char *value; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 2700 | int f_mand = 0, c_ftrs = 0, ret; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2701 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2702 | choice = calloc(1, sizeof *choice); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2703 | if (!choice) { |
| 2704 | LOGMEM; |
| 2705 | return NULL; |
| 2706 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2707 | choice->nodetype = LYS_CHOICE; |
| 2708 | choice->prev = (struct lys_node *)choice; |
| 2709 | retval = (struct lys_node *)choice; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2710 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 2711 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 2712 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2713 | goto error; |
| 2714 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2715 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 2716 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 2717 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2718 | /* insert the node into the schema tree */ |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 2719 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2720 | goto error; |
| 2721 | } |
| 2722 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2723 | /* process choice's specific children */ |
| 2724 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2725 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2726 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2727 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2728 | continue; |
| 2729 | } |
| 2730 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2731 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2732 | if (!(node = read_yin_container(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2733 | goto error; |
| 2734 | } |
| 2735 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2736 | if (!(node = read_yin_leaflist(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2737 | goto error; |
| 2738 | } |
| 2739 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2740 | if (!(node = read_yin_leaf(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2741 | goto error; |
| 2742 | } |
| 2743 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2744 | if (!(node = read_yin_list(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2745 | goto error; |
| 2746 | } |
| 2747 | } else if (!strcmp(sub->name, "case")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2748 | if (!(node = read_yin_case(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2749 | goto error; |
| 2750 | } |
| 2751 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2752 | if (!(node = read_yin_anyxml(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2753 | goto error; |
| 2754 | } |
| 2755 | } else if (!strcmp(sub->name, "default")) { |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 2756 | if (dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2757 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2758 | goto error; |
| 2759 | } |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 2760 | dflt = sub; |
| 2761 | lyxml_unlink_elem(ctx, dflt, 0); |
| 2762 | |
Radek Krejci | f9a312c | 2016-06-06 15:14:30 +0200 | [diff] [blame^] | 2763 | continue; |
| 2764 | /* skip lyxml_free() at the end of the loop, the sub node is processed later as dflt */ |
| 2765 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2766 | } else if (!strcmp(sub->name, "mandatory")) { |
| 2767 | if (f_mand) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2768 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2769 | goto error; |
| 2770 | } |
| 2771 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2772 | * multiple mandatory statements with the "false" value |
| 2773 | */ |
| 2774 | f_mand = 1; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2775 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2776 | GETVAL(value, sub, "value"); |
| 2777 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2778 | choice->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2779 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2780 | choice->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2781 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2782 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2783 | goto error; |
| 2784 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2785 | } else if (!strcmp(sub->name, "when")) { |
| 2786 | if (choice->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2787 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2788 | goto error; |
| 2789 | } |
| 2790 | |
| 2791 | choice->when = read_yin_when(module, sub); |
| 2792 | if (!choice->when) { |
| 2793 | goto error; |
| 2794 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2795 | } else if (!strcmp(sub->name, "if-feature")) { |
| 2796 | c_ftrs++; |
| 2797 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2798 | /* 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] | 2799 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2800 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2801 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2802 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2803 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2804 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2805 | node = NULL; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2806 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2807 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2808 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2809 | if (c_ftrs) { |
| 2810 | choice->features = calloc(c_ftrs, sizeof *choice->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2811 | if (!choice->features) { |
| 2812 | LOGMEM; |
| 2813 | goto error; |
| 2814 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2815 | } |
| 2816 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2817 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 2818 | ret = fill_yin_iffeature(retval, sub, &choice->features[choice->features_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 2819 | choice->features_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 2820 | if (ret) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2821 | goto error; |
| 2822 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2823 | } |
| 2824 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2825 | /* check - default is prohibited in combination with mandatory */ |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 2826 | if (dflt && (choice->flags & LYS_MAND_TRUE)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2827 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "default", "choice"); |
| 2828 | 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] | 2829 | goto error; |
| 2830 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2831 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2832 | /* link default with the case */ |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 2833 | if (dflt) { |
| 2834 | GETVAL(value, dflt, "value"); |
| 2835 | 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] | 2836 | goto error; |
| 2837 | } |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 2838 | lyxml_free(ctx, dflt); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2839 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2840 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2841 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2842 | |
| 2843 | error: |
| 2844 | |
Radek Krejci | 629cdef | 2016-06-06 15:06:36 +0200 | [diff] [blame] | 2845 | lyxml_free(ctx, dflt); |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 2846 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2847 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2848 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2849 | } |
| 2850 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2851 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2852 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2853 | read_yin_anyxml(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] | 2854 | struct unres_schema *unres) |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2855 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2856 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2857 | struct lys_node_leaf *anyxml; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2858 | struct lyxml_elem *sub, *next; |
| 2859 | const char *value; |
| 2860 | int r; |
| 2861 | int f_mand = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2862 | int c_must = 0, c_ftrs = 0; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2863 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2864 | anyxml = calloc(1, sizeof *anyxml); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2865 | if (!anyxml) { |
| 2866 | LOGMEM; |
| 2867 | return NULL; |
| 2868 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2869 | anyxml->nodetype = LYS_ANYXML; |
| 2870 | anyxml->prev = (struct lys_node *)anyxml; |
| 2871 | retval = (struct lys_node *)anyxml; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2872 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 2873 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 2874 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2875 | goto error; |
| 2876 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2877 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 2878 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 2879 | |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 2880 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2881 | goto error; |
| 2882 | } |
| 2883 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2884 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2885 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2886 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2887 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2888 | continue; |
| 2889 | } |
| 2890 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2891 | if (!strcmp(sub->name, "mandatory")) { |
| 2892 | if (f_mand) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2893 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2894 | goto error; |
| 2895 | } |
| 2896 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2897 | * multiple mandatory statements with the "false" value |
| 2898 | */ |
| 2899 | f_mand = 1; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2900 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2901 | GETVAL(value, sub, "value"); |
| 2902 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2903 | anyxml->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2904 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2905 | anyxml->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2906 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2907 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2908 | goto error; |
| 2909 | } |
| 2910 | /* else false is the default value, so we can ignore it */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2911 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2912 | } else if (!strcmp(sub->name, "when")) { |
| 2913 | if (anyxml->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2914 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2915 | goto error; |
| 2916 | } |
| 2917 | |
| 2918 | anyxml->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2919 | if (!anyxml->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2920 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2921 | goto error; |
| 2922 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2923 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2924 | } else if (!strcmp(sub->name, "must")) { |
| 2925 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2926 | } else if (!strcmp(sub->name, "if-feature")) { |
| 2927 | c_ftrs++; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2928 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2929 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2930 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2931 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2932 | } |
| 2933 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2934 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2935 | /* middle part - process nodes with cardinality of 0..n */ |
| 2936 | if (c_must) { |
| 2937 | anyxml->must = calloc(c_must, sizeof *anyxml->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2938 | if (!anyxml->must) { |
| 2939 | LOGMEM; |
| 2940 | goto error; |
| 2941 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2942 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2943 | if (c_ftrs) { |
| 2944 | anyxml->features = calloc(c_ftrs, sizeof *anyxml->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2945 | if (!anyxml->features) { |
| 2946 | LOGMEM; |
| 2947 | goto error; |
| 2948 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2949 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2950 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2951 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2952 | if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 2953 | r = fill_yin_must(module, sub, &anyxml->must[anyxml->must_size]); |
| 2954 | anyxml->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2955 | if (r) { |
| 2956 | goto error; |
| 2957 | } |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 2958 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 2959 | r = fill_yin_iffeature(retval, sub, &anyxml->features[anyxml->features_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 2960 | anyxml->features_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 2961 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2962 | goto error; |
| 2963 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2964 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2965 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2966 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2967 | return retval; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2968 | |
| 2969 | error: |
| 2970 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 2971 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2972 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2973 | return NULL; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2974 | } |
| 2975 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2976 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2977 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2978 | 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] | 2979 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2980 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2981 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2982 | struct lys_node_leaf *leaf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2983 | struct lyxml_elem *sub, *next; |
| 2984 | const char *value; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 2985 | int r, has_type = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2986 | int c_must = 0, c_ftrs = 0, f_mand = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2987 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2988 | leaf = calloc(1, sizeof *leaf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2989 | if (!leaf) { |
| 2990 | LOGMEM; |
| 2991 | return NULL; |
| 2992 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2993 | leaf->nodetype = LYS_LEAF; |
| 2994 | leaf->prev = (struct lys_node *)leaf; |
| 2995 | retval = (struct lys_node *)leaf; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2996 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 2997 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 2998 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2999 | goto error; |
| 3000 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3001 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3002 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3003 | |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 3004 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3005 | goto error; |
| 3006 | } |
| 3007 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3008 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3009 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3010 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3011 | lyxml_free(module->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, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 3016 | if (has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3017 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3018 | goto error; |
| 3019 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3020 | /* HACK for unres */ |
| 3021 | leaf->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3022 | leaf->type.parent = (struct lys_tpdf *)leaf; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3023 | if (unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DER, parent)) { |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3024 | leaf->type.der = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3025 | goto error; |
| 3026 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3027 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3028 | } else if (!strcmp(sub->name, "default")) { |
| 3029 | if (leaf->dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3030 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3031 | goto error; |
| 3032 | } |
| 3033 | GETVAL(value, sub, "value"); |
| 3034 | leaf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
| 3035 | } else if (!strcmp(sub->name, "units")) { |
| 3036 | if (leaf->units) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3037 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3038 | goto error; |
| 3039 | } |
| 3040 | GETVAL(value, sub, "name"); |
| 3041 | leaf->units = lydict_insert(module->ctx, value, strlen(value)); |
| 3042 | } else if (!strcmp(sub->name, "mandatory")) { |
| 3043 | if (f_mand) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3044 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3045 | goto error; |
| 3046 | } |
| 3047 | /* just checking the flags in leaf is not sufficient, we would allow |
| 3048 | * multiple mandatory statements with the "false" value |
| 3049 | */ |
| 3050 | f_mand = 1; |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3051 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3052 | GETVAL(value, sub, "value"); |
| 3053 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3054 | leaf->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3055 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3056 | leaf->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3057 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3058 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3059 | goto error; |
| 3060 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3061 | } else if (!strcmp(sub->name, "when")) { |
| 3062 | if (leaf->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3063 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3064 | goto error; |
| 3065 | } |
| 3066 | |
| 3067 | leaf->when = read_yin_when(module, sub); |
| 3068 | if (!leaf->when) { |
| 3069 | goto error; |
| 3070 | } |
| 3071 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3072 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3073 | c_must++; |
| 3074 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3075 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3076 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3077 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3078 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3079 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3080 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3081 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3082 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3083 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3084 | /* 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] | 3085 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3086 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3087 | /* check mandatory parameters */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3088 | if (!has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3089 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3090 | goto error; |
| 3091 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3092 | if (leaf->dflt) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3093 | if (unres_schema_add_str(module, unres, &leaf->type, UNRES_TYPE_DFLT, leaf->dflt) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3094 | goto error; |
| 3095 | } |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 3096 | if (leaf->flags & LYS_MAND_TRUE) { |
Radek Krejci | 6052ada | 2016-04-05 16:37:51 +0200 | [diff] [blame] | 3097 | LOGVAL(LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "mandatory", "leaf"); |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 3098 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, |
Radek Krejci | 6052ada | 2016-04-05 16:37:51 +0200 | [diff] [blame] | 3099 | "The \"mandatory\" statement is forbidden on leaf with the \"default\" statement."); |
Radek Krejci | 841ec08 | 2016-04-05 13:05:17 +0200 | [diff] [blame] | 3100 | goto error; |
| 3101 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3102 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3103 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3104 | /* middle part - process nodes with cardinality of 0..n */ |
| 3105 | if (c_must) { |
| 3106 | leaf->must = calloc(c_must, sizeof *leaf->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3107 | if (!leaf->must) { |
| 3108 | LOGMEM; |
| 3109 | goto error; |
| 3110 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3111 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3112 | if (c_ftrs) { |
| 3113 | leaf->features = calloc(c_ftrs, sizeof *leaf->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3114 | if (!leaf->features) { |
| 3115 | LOGMEM; |
| 3116 | goto error; |
| 3117 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3118 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3119 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3120 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3121 | if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3122 | r = fill_yin_must(module, sub, &leaf->must[leaf->must_size]); |
| 3123 | leaf->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3124 | if (r) { |
| 3125 | goto error; |
| 3126 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3127 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3128 | r = fill_yin_iffeature(retval, sub, &leaf->features[leaf->features_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3129 | leaf->features_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3130 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3131 | goto error; |
| 3132 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3133 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3134 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3135 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3136 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3137 | |
| 3138 | error: |
| 3139 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 3140 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3141 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3142 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3143 | } |
| 3144 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3145 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3146 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3147 | 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] | 3148 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3149 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3150 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3151 | struct lys_node_leaflist *llist; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3152 | struct lyxml_elem *sub, *next; |
| 3153 | const char *value; |
| 3154 | char *endptr; |
| 3155 | unsigned long val; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3156 | int r, has_type = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3157 | int c_must = 0, c_ftrs = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3158 | int f_ordr = 0, f_min = 0, f_max = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3159 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3160 | llist = calloc(1, sizeof *llist); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3161 | if (!llist) { |
| 3162 | LOGMEM; |
| 3163 | return NULL; |
| 3164 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3165 | llist->nodetype = LYS_LEAFLIST; |
| 3166 | llist->prev = (struct lys_node *)llist; |
| 3167 | retval = (struct lys_node *)llist; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3168 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3169 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3170 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3171 | goto error; |
| 3172 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3173 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3174 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3175 | |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 3176 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3177 | goto error; |
| 3178 | } |
| 3179 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 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 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3187 | if (!strcmp(sub->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 3188 | if (has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3189 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3190 | goto error; |
| 3191 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3192 | /* HACK for unres */ |
| 3193 | llist->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3194 | llist->type.parent = (struct lys_tpdf *)llist; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3195 | if (unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DER, parent)) { |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3196 | llist->type.der = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3197 | goto error; |
| 3198 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3199 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3200 | } else if (!strcmp(sub->name, "units")) { |
| 3201 | if (llist->units) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3202 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3203 | goto error; |
| 3204 | } |
| 3205 | GETVAL(value, sub, "name"); |
| 3206 | llist->units = lydict_insert(module->ctx, value, strlen(value)); |
| 3207 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 3208 | if (f_ordr) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3209 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3210 | goto error; |
| 3211 | } |
| 3212 | /* just checking the flags in llist is not sufficient, we would |
| 3213 | * allow multiple ordered-by statements with the "system" value |
| 3214 | */ |
| 3215 | f_ordr = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3216 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3217 | if (llist->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3218 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 3219 | * state data |
| 3220 | */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3221 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3222 | continue; |
| 3223 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3224 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3225 | GETVAL(value, sub, "value"); |
| 3226 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3227 | llist->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3228 | } else if (strcmp(value, "system")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3229 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3230 | goto error; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3231 | } /* else system is the default value, so we can ignore it */ |
| 3232 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3233 | } else if (!strcmp(sub->name, "must")) { |
| 3234 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3235 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3236 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3237 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3238 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3239 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3240 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3241 | if (f_min) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3242 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3243 | goto error; |
| 3244 | } |
| 3245 | f_min = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3246 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3247 | GETVAL(value, sub, "value"); |
| 3248 | while (isspace(value[0])) { |
| 3249 | value++; |
| 3250 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3251 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3252 | /* convert it to uint32_t */ |
| 3253 | errno = 0; |
| 3254 | endptr = NULL; |
| 3255 | val = strtoul(value, &endptr, 10); |
| 3256 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3257 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3258 | goto error; |
| 3259 | } |
| 3260 | llist->min = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 3261 | if (llist->max && (llist->min > llist->max)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3262 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
| 3263 | 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] | 3264 | goto error; |
| 3265 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3266 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3267 | if (f_max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3268 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3269 | goto error; |
| 3270 | } |
| 3271 | f_max = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3272 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3273 | GETVAL(value, sub, "value"); |
| 3274 | while (isspace(value[0])) { |
| 3275 | value++; |
| 3276 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3277 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 3278 | if (!strcmp(value, "unbounded")) { |
| 3279 | llist->max = 0; |
| 3280 | } else { |
| 3281 | /* convert it to uint32_t */ |
| 3282 | errno = 0; |
| 3283 | endptr = NULL; |
| 3284 | val = strtoul(value, &endptr, 10); |
| 3285 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3286 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 3287 | goto error; |
| 3288 | } |
| 3289 | llist->max = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 3290 | if (llist->min > llist->max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3291 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
| 3292 | 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] | 3293 | goto error; |
| 3294 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3295 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3296 | } else if (!strcmp(sub->name, "when")) { |
| 3297 | if (llist->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3298 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3299 | goto error; |
| 3300 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3301 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3302 | llist->when = read_yin_when(module, sub); |
| 3303 | if (!llist->when) { |
| 3304 | goto error; |
| 3305 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3306 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3307 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3308 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3309 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3310 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3311 | /* 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] | 3312 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3313 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3314 | /* check constraints */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3315 | if (!has_type) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3316 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3317 | goto error; |
| 3318 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3319 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3320 | /* middle part - process nodes with cardinality of 0..n */ |
| 3321 | if (c_must) { |
| 3322 | llist->must = calloc(c_must, sizeof *llist->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3323 | if (!llist->must) { |
| 3324 | LOGMEM; |
| 3325 | goto error; |
| 3326 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3327 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3328 | if (c_ftrs) { |
| 3329 | llist->features = calloc(c_ftrs, sizeof *llist->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3330 | if (!llist->features) { |
| 3331 | LOGMEM; |
| 3332 | goto error; |
| 3333 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3334 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3335 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3336 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3337 | if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3338 | r = fill_yin_must(module, sub, &llist->must[llist->must_size]); |
| 3339 | llist->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3340 | if (r) { |
| 3341 | goto error; |
| 3342 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3343 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3344 | r = fill_yin_iffeature(retval, sub, &llist->features[llist->features_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3345 | llist->features_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3346 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3347 | goto error; |
| 3348 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3349 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3350 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3351 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3352 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3353 | |
| 3354 | error: |
| 3355 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 3356 | lys_node_free(retval, NULL, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3357 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3358 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3359 | } |
| 3360 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3361 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3362 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3363 | read_yin_list(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 3364 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3365 | { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3366 | struct lys_node *retval, *node; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3367 | struct lys_node_list *list; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3368 | struct lyxml_elem *sub, *next, root, uniq; |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3369 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3370 | 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] | 3371 | int f_ordr = 0, f_max = 0, f_min = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3372 | const char *key_str = NULL, *value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3373 | char *auxs; |
| 3374 | unsigned long val; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3375 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3376 | /* init */ |
| 3377 | memset(&root, 0, sizeof root); |
| 3378 | memset(&uniq, 0, sizeof uniq); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3379 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3380 | list = calloc(1, sizeof *list); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3381 | if (!list) { |
| 3382 | LOGMEM; |
| 3383 | return NULL; |
| 3384 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3385 | list->nodetype = LYS_LIST; |
| 3386 | list->prev = (struct lys_node *)list; |
| 3387 | retval = (struct lys_node *)list; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3388 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3389 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3390 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3391 | goto error; |
| 3392 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3393 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3394 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3395 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3396 | /* process list's specific children */ |
| 3397 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3398 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3399 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3400 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3401 | continue; |
| 3402 | } |
| 3403 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3404 | /* data statements */ |
| 3405 | if (!strcmp(sub->name, "container") || |
| 3406 | !strcmp(sub->name, "leaf-list") || |
| 3407 | !strcmp(sub->name, "leaf") || |
| 3408 | !strcmp(sub->name, "list") || |
| 3409 | !strcmp(sub->name, "choice") || |
| 3410 | !strcmp(sub->name, "uses") || |
| 3411 | !strcmp(sub->name, "grouping") || |
| 3412 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 3413 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3414 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3415 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3416 | /* array counters */ |
| 3417 | } else if (!strcmp(sub->name, "key")) { |
| 3418 | /* check cardinality 0..1 */ |
| 3419 | if (list->keys_size) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3420 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, list->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3421 | goto error; |
| 3422 | } |
Radek Krejci | d7f0d01 | 2015-05-25 15:04:52 +0200 | [diff] [blame] | 3423 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3424 | /* count the number of keys */ |
| 3425 | GETVAL(value, sub, "value"); |
| 3426 | key_str = value; |
| 3427 | while ((value = strpbrk(value, " \t\n"))) { |
| 3428 | list->keys_size++; |
| 3429 | while (isspace(*value)) { |
| 3430 | value++; |
| 3431 | } |
| 3432 | } |
| 3433 | list->keys_size++; |
| 3434 | list->keys = calloc(list->keys_size, sizeof *list->keys); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3435 | if (!list->keys) { |
| 3436 | LOGMEM; |
| 3437 | goto error; |
| 3438 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3439 | } else if (!strcmp(sub->name, "unique")) { |
| 3440 | c_uniq++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 3441 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3442 | lyxml_add_child(module->ctx, &uniq, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3443 | } else if (!strcmp(sub->name, "typedef")) { |
| 3444 | c_tpdf++; |
| 3445 | } else if (!strcmp(sub->name, "must")) { |
| 3446 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3447 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3448 | c_ftrs++; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3449 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3450 | /* optional stetments */ |
| 3451 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 3452 | if (f_ordr) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3453 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3454 | goto error; |
| 3455 | } |
| 3456 | /* just checking the flags in llist is not sufficient, we would |
| 3457 | * allow multiple ordered-by statements with the "system" value |
| 3458 | */ |
| 3459 | f_ordr = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3460 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3461 | if (list->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3462 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 3463 | * state data |
| 3464 | */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3465 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3466 | continue; |
| 3467 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3468 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3469 | GETVAL(value, sub, "value"); |
| 3470 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3471 | list->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3472 | } else if (strcmp(value, "system")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3473 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3474 | goto error; |
| 3475 | } |
| 3476 | /* else system is the default value, so we can ignore it */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3477 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3478 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3479 | if (f_min) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3480 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3481 | goto error; |
| 3482 | } |
| 3483 | f_min = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3484 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3485 | GETVAL(value, sub, "value"); |
| 3486 | while (isspace(value[0])) { |
| 3487 | value++; |
| 3488 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3489 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3490 | /* convert it to uint32_t */ |
| 3491 | errno = 0; |
| 3492 | auxs = NULL; |
| 3493 | val = strtoul(value, &auxs, 10); |
| 3494 | if (*auxs || value[0] == '-' || errno || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3495 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3496 | goto error; |
| 3497 | } |
| 3498 | list->min = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 3499 | if (list->max && (list->min > list->max)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3500 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
| 3501 | 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] | 3502 | lyxml_free(module->ctx, sub); |
| 3503 | goto error; |
| 3504 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3505 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3506 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3507 | if (f_max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3508 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3509 | goto error; |
| 3510 | } |
| 3511 | f_max = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3512 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3513 | GETVAL(value, sub, "value"); |
| 3514 | while (isspace(value[0])) { |
| 3515 | value++; |
| 3516 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3517 | |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 3518 | if (!strcmp(value, "unbounded")) { |
| 3519 | list->max = 0;; |
| 3520 | } else { |
| 3521 | /* convert it to uint32_t */ |
| 3522 | errno = 0; |
| 3523 | auxs = NULL; |
| 3524 | val = strtoul(value, &auxs, 10); |
| 3525 | if (*auxs || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3526 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
Radek Krejci | 0d7b247 | 2016-02-12 11:11:03 +0100 | [diff] [blame] | 3527 | goto error; |
| 3528 | } |
| 3529 | list->max = (uint32_t) val; |
Michal Vasko | 6ea3e36 | 2016-03-11 10:25:36 +0100 | [diff] [blame] | 3530 | if (list->min > list->max) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3531 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, sub->name); |
| 3532 | 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] | 3533 | goto error; |
| 3534 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3535 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3536 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3537 | } else if (!strcmp(sub->name, "when")) { |
| 3538 | if (list->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3539 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3540 | goto error; |
| 3541 | } |
| 3542 | |
| 3543 | list->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3544 | if (!list->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3545 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3546 | goto error; |
| 3547 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3548 | lyxml_free(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3549 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3550 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3551 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3552 | } |
| 3553 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3554 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3555 | /* check - if list is configuration, key statement is mandatory */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3556 | if ((list->flags & LYS_CONFIG_W) && !key_str) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3557 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "key", "list"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3558 | goto error; |
| 3559 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3560 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3561 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3562 | if (c_tpdf) { |
| 3563 | list->tpdf = calloc(c_tpdf, sizeof *list->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3564 | if (!list->tpdf) { |
| 3565 | LOGMEM; |
| 3566 | goto error; |
| 3567 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3568 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3569 | if (c_must) { |
| 3570 | list->must = calloc(c_must, sizeof *list->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3571 | if (!list->must) { |
| 3572 | LOGMEM; |
| 3573 | goto error; |
| 3574 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3575 | } |
| 3576 | if (c_ftrs) { |
| 3577 | list->features = calloc(c_ftrs, sizeof *list->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3578 | if (!list->features) { |
| 3579 | LOGMEM; |
| 3580 | goto error; |
| 3581 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3582 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3583 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3584 | if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3585 | r = fill_yin_typedef(module, retval, sub, &list->tpdf[list->tpdf_size], unres); |
| 3586 | list->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3587 | if (r) { |
| 3588 | goto error; |
| 3589 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3590 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3591 | r = fill_yin_iffeature(retval, sub, &list->features[list->features_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3592 | list->features_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3593 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3594 | goto error; |
| 3595 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3596 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3597 | r = fill_yin_must(module, sub, &list->must[list->must_size]); |
| 3598 | list->must_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3599 | if (r) { |
| 3600 | goto error; |
| 3601 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3602 | } |
| 3603 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 3604 | |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 3605 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3606 | goto error; |
| 3607 | } |
| 3608 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3609 | /* last part - process data nodes */ |
| 3610 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3611 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3612 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3613 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3614 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3615 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3616 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3617 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3618 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3619 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3620 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3621 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3622 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3623 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3624 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3625 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3626 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Michal Vasko | c07187d | 2015-08-13 15:20:57 +0200 | [diff] [blame] | 3627 | } else { |
| 3628 | LOGINT; |
| 3629 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3630 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3631 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3632 | goto error; |
| 3633 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3634 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3635 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3636 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3637 | |
Radek Krejci | 461efb9 | 2016-02-12 15:52:18 +0100 | [diff] [blame] | 3638 | if (key_str) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3639 | 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] | 3640 | goto error; |
| 3641 | } |
| 3642 | } /* 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] | 3643 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3644 | /* process unique statements */ |
| 3645 | if (c_uniq) { |
| 3646 | list->unique = calloc(c_uniq, sizeof *list->unique); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3647 | if (!list->unique) { |
| 3648 | LOGMEM; |
| 3649 | goto error; |
| 3650 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 3651 | |
Radek Krejci | 461efb9 | 2016-02-12 15:52:18 +0100 | [diff] [blame] | 3652 | LY_TREE_FOR_SAFE(uniq.child, next, sub) { |
| 3653 | r = fill_yin_unique(module, retval, sub, &list->unique[list->unique_size], unres); |
| 3654 | list->unique_size++; |
| 3655 | if (r) { |
| 3656 | goto error; |
| 3657 | } |
| 3658 | |
| 3659 | lyxml_free(module->ctx, sub); |
| 3660 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3661 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 3662 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3663 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3664 | |
| 3665 | error: |
| 3666 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 3667 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3668 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3669 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3670 | } |
| 3671 | while (uniq.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3672 | lyxml_free(module->ctx, uniq.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3673 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3674 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3675 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3676 | } |
| 3677 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3678 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3679 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3680 | read_yin_container(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 3681 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3682 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3683 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3684 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3685 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3686 | struct lys_node_container *cont; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3687 | const char *value; |
| 3688 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3689 | int c_tpdf = 0, c_must = 0, c_ftrs = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3690 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3691 | /* init */ |
| 3692 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3693 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3694 | cont = calloc(1, sizeof *cont); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3695 | if (!cont) { |
| 3696 | LOGMEM; |
| 3697 | return NULL; |
| 3698 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3699 | cont->nodetype = LYS_CONTAINER; |
| 3700 | cont->prev = (struct lys_node *)cont; |
| 3701 | retval = (struct lys_node *)cont; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3702 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3703 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3704 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3705 | goto error; |
| 3706 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3707 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3708 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3709 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3710 | /* process container's specific children */ |
| 3711 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3712 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3713 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3714 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3715 | continue; |
| 3716 | } |
| 3717 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3718 | if (!strcmp(sub->name, "presence")) { |
| 3719 | if (cont->presence) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3720 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3721 | goto error; |
| 3722 | } |
| 3723 | GETVAL(value, sub, "value"); |
| 3724 | cont->presence = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 3725 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3726 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3727 | } else if (!strcmp(sub->name, "when")) { |
| 3728 | if (cont->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3729 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3730 | goto error; |
| 3731 | } |
| 3732 | |
| 3733 | cont->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3734 | if (!cont->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3735 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3736 | goto error; |
| 3737 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3738 | lyxml_free(module->ctx, sub); |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3739 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3740 | /* data statements */ |
| 3741 | } else if (!strcmp(sub->name, "container") || |
| 3742 | !strcmp(sub->name, "leaf-list") || |
| 3743 | !strcmp(sub->name, "leaf") || |
| 3744 | !strcmp(sub->name, "list") || |
| 3745 | !strcmp(sub->name, "choice") || |
| 3746 | !strcmp(sub->name, "uses") || |
| 3747 | !strcmp(sub->name, "grouping") || |
| 3748 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 3749 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3750 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3751 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3752 | /* array counters */ |
| 3753 | } else if (!strcmp(sub->name, "typedef")) { |
| 3754 | c_tpdf++; |
| 3755 | } else if (!strcmp(sub->name, "must")) { |
| 3756 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3757 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3758 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3759 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3760 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3761 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3762 | } |
| 3763 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3764 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3765 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3766 | if (c_tpdf) { |
| 3767 | cont->tpdf = calloc(c_tpdf, sizeof *cont->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3768 | if (!cont->tpdf) { |
| 3769 | LOGMEM; |
| 3770 | goto error; |
| 3771 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3772 | } |
| 3773 | if (c_must) { |
| 3774 | cont->must = calloc(c_must, sizeof *cont->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3775 | if (!cont->must) { |
| 3776 | LOGMEM; |
| 3777 | goto error; |
| 3778 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3779 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3780 | if (c_ftrs) { |
| 3781 | cont->features = calloc(c_ftrs, sizeof *cont->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3782 | if (!cont->features) { |
| 3783 | LOGMEM; |
| 3784 | goto error; |
| 3785 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3786 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 3787 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3788 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3789 | if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3790 | r = fill_yin_typedef(module, retval, sub, &cont->tpdf[cont->tpdf_size], unres); |
| 3791 | cont->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3792 | if (r) { |
| 3793 | goto error; |
| 3794 | } |
| 3795 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3796 | r = fill_yin_must(module, sub, &cont->must[cont->must_size]); |
| 3797 | cont->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3798 | if (r) { |
| 3799 | goto error; |
| 3800 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3801 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3802 | r = fill_yin_iffeature(retval, sub, &cont->features[cont->features_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3803 | cont->features_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 3804 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3805 | goto error; |
| 3806 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3807 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3808 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3809 | |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 3810 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3811 | goto error; |
| 3812 | } |
| 3813 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3814 | /* last part - process data nodes */ |
| 3815 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3816 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3817 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3818 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3819 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3820 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3821 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3822 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3823 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3824 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3825 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3826 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3827 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3828 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3829 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3830 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3831 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3832 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3833 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3834 | goto error; |
| 3835 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3836 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3837 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3838 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3839 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3840 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3841 | |
| 3842 | error: |
| 3843 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 3844 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3845 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3846 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3847 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3848 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3849 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3850 | } |
| 3851 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3852 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3853 | static struct lys_node * |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3854 | 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] | 3855 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3856 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3857 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3858 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3859 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3860 | struct lys_node_grp *grp; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3861 | int r; |
| 3862 | int c_tpdf = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3863 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3864 | /* init */ |
| 3865 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3866 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3867 | grp = calloc(1, sizeof *grp); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3868 | if (!grp) { |
| 3869 | LOGMEM; |
| 3870 | return NULL; |
| 3871 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3872 | grp->nodetype = LYS_GROUPING; |
| 3873 | grp->prev = (struct lys_node *)grp; |
| 3874 | retval = (struct lys_node *)grp; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3875 | |
Michal Vasko | 71e1aa8 | 2015-08-12 12:17:51 +0200 | [diff] [blame] | 3876 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3877 | goto error; |
| 3878 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3879 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3880 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3881 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3882 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3883 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3884 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3885 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3886 | continue; |
| 3887 | } |
| 3888 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3889 | /* data statements */ |
| 3890 | if (!strcmp(sub->name, "container") || |
| 3891 | !strcmp(sub->name, "leaf-list") || |
| 3892 | !strcmp(sub->name, "leaf") || |
| 3893 | !strcmp(sub->name, "list") || |
| 3894 | !strcmp(sub->name, "choice") || |
| 3895 | !strcmp(sub->name, "uses") || |
| 3896 | !strcmp(sub->name, "grouping") || |
| 3897 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 3898 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3899 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3900 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3901 | /* array counters */ |
| 3902 | } else if (!strcmp(sub->name, "typedef")) { |
| 3903 | c_tpdf++; |
| 3904 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 3905 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3906 | goto error; |
| 3907 | } |
| 3908 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3909 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3910 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3911 | if (c_tpdf) { |
| 3912 | grp->tpdf = calloc(c_tpdf, sizeof *grp->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3913 | if (!grp->tpdf) { |
| 3914 | LOGMEM; |
| 3915 | goto error; |
| 3916 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3917 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3918 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3919 | r = fill_yin_typedef(module, retval, sub, &grp->tpdf[grp->tpdf_size], unres); |
| 3920 | grp->tpdf_size++; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3921 | if (r) { |
| 3922 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3923 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3924 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3925 | |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 3926 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3927 | goto error; |
| 3928 | } |
| 3929 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3930 | /* last part - process data nodes */ |
Michal Vasko | 919dbbc | 2016-05-19 15:22:45 +0200 | [diff] [blame] | 3931 | if (!root.child) { |
| 3932 | LOGWRN("Grouping \"%s\" without children.", retval->name); |
| 3933 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3934 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3935 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3936 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3937 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3938 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3939 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3940 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3941 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3942 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3943 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3944 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3945 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3946 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3947 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3948 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3949 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3950 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3951 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3952 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3953 | goto error; |
| 3954 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3955 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3956 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3957 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3958 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3959 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3960 | |
| 3961 | error: |
| 3962 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 3963 | lys_node_free(retval, NULL, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3964 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3965 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3966 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3967 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3968 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3969 | } |
| 3970 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3971 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3972 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3973 | read_yin_input_output(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 3974 | struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3975 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3976 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3977 | struct lys_node *node = NULL; |
Radek Krejci | 31fc30d | 2015-08-13 08:27:38 +0200 | [diff] [blame] | 3978 | struct lys_node *retval = NULL; |
Radek Krejci | 4608ada | 2015-08-05 16:04:37 +0200 | [diff] [blame] | 3979 | struct lys_node_rpc_inout *inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3980 | int r; |
| 3981 | int c_tpdf = 0; |
| 3982 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3983 | /* init */ |
| 3984 | memset(&root, 0, sizeof root); |
| 3985 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3986 | inout = calloc(1, sizeof *inout); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3987 | if (!inout) { |
| 3988 | LOGMEM; |
| 3989 | return NULL; |
| 3990 | } |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 3991 | inout->prev = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3992 | |
| 3993 | if (!strcmp(yin->name, "input")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3994 | inout->nodetype = LYS_INPUT; |
Michal Vasko | 0a1aaa4 | 2016-04-19 09:48:25 +0200 | [diff] [blame] | 3995 | inout->name = lydict_insert(module->ctx, "input", 0); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3996 | } else if (!strcmp(yin->name, "output")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3997 | inout->nodetype = LYS_OUTPUT; |
Michal Vasko | 0a1aaa4 | 2016-04-19 09:48:25 +0200 | [diff] [blame] | 3998 | inout->name = lydict_insert(module->ctx, "output", 0); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3999 | } else { |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 4000 | LOGINT; |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 4001 | free(inout); |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 4002 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4003 | } |
| 4004 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4005 | retval = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4006 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4007 | if (read_yin_common(module, parent, retval, yin, OPT_MODULE | OPT_NACMEXT)) { |
Michal Vasko | ebeac94 | 2015-06-15 12:11:50 +0200 | [diff] [blame] | 4008 | goto error; |
| 4009 | } |
| 4010 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4011 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4012 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4013 | /* data statements */ |
| 4014 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4015 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4016 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4017 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4018 | continue; |
| 4019 | } |
| 4020 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4021 | if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4022 | !strcmp(sub->name, "leaf-list") || |
| 4023 | !strcmp(sub->name, "leaf") || |
| 4024 | !strcmp(sub->name, "list") || |
| 4025 | !strcmp(sub->name, "choice") || |
| 4026 | !strcmp(sub->name, "uses") || |
| 4027 | !strcmp(sub->name, "grouping") || |
| 4028 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4029 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4030 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4031 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4032 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4033 | } else if (!strcmp(sub->name, "typedef")) { |
| 4034 | c_tpdf++; |
Radek Krejci | d2bfa79 | 2015-07-02 16:45:29 +0200 | [diff] [blame] | 4035 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4036 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4037 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4038 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4039 | } |
| 4040 | } |
| 4041 | |
| 4042 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4043 | if (c_tpdf) { |
| 4044 | inout->tpdf = calloc(c_tpdf, sizeof *inout->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4045 | if (!inout->tpdf) { |
| 4046 | LOGMEM; |
| 4047 | goto error; |
| 4048 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4049 | } |
| 4050 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4051 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4052 | r = fill_yin_typedef(module, retval, sub, &inout->tpdf[inout->tpdf_size], unres); |
| 4053 | inout->tpdf_size++; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4054 | if (r) { |
| 4055 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4056 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4057 | } |
| 4058 | |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4059 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4060 | goto error; |
| 4061 | } |
| 4062 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4063 | /* last part - process data nodes */ |
| 4064 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4065 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4066 | node = read_yin_container(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4067 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4068 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4069 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4070 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4071 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4072 | node = read_yin_list(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4073 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4074 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4075 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4076 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4077 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4078 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4079 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4080 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4081 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4082 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4083 | goto error; |
| 4084 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4085 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4086 | lyxml_free(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4087 | } |
| 4088 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4089 | return retval; |
| 4090 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4091 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4092 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4093 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 4094 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4095 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4096 | } |
| 4097 | |
| 4098 | return NULL; |
| 4099 | } |
| 4100 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4101 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4102 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4103 | read_yin_notif(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 4104 | struct unres_schema *unres) |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4105 | { |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 4106 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4107 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4108 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4109 | struct lys_node_notif *notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4110 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4111 | int c_tpdf = 0, c_ftrs = 0; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4112 | |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 4113 | memset(&root, 0, sizeof root); |
| 4114 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4115 | notif = calloc(1, sizeof *notif); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4116 | if (!notif) { |
| 4117 | LOGMEM; |
| 4118 | return NULL; |
| 4119 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4120 | notif->nodetype = LYS_NOTIF; |
| 4121 | notif->prev = (struct lys_node *)notif; |
| 4122 | retval = (struct lys_node *)notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4123 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4124 | 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] | 4125 | goto error; |
| 4126 | } |
| 4127 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4128 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4129 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4130 | /* process rpc's specific children */ |
| 4131 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4132 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4133 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4134 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4135 | continue; |
| 4136 | } |
| 4137 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4138 | /* data statements */ |
| 4139 | if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4140 | !strcmp(sub->name, "leaf-list") || |
| 4141 | !strcmp(sub->name, "leaf") || |
| 4142 | !strcmp(sub->name, "list") || |
| 4143 | !strcmp(sub->name, "choice") || |
| 4144 | !strcmp(sub->name, "uses") || |
| 4145 | !strcmp(sub->name, "grouping") || |
| 4146 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4147 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4148 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4149 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4150 | /* array counters */ |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4151 | } else if (!strcmp(sub->name, "typedef")) { |
| 4152 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4153 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4154 | c_ftrs++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4155 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4156 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4157 | goto error; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4158 | } |
| 4159 | } |
| 4160 | |
| 4161 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4162 | if (c_tpdf) { |
| 4163 | notif->tpdf = calloc(c_tpdf, sizeof *notif->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4164 | if (!notif->tpdf) { |
| 4165 | LOGMEM; |
| 4166 | goto error; |
| 4167 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4168 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4169 | if (c_ftrs) { |
| 4170 | notif->features = calloc(c_ftrs, sizeof *notif->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4171 | if (!notif->features) { |
| 4172 | LOGMEM; |
| 4173 | goto error; |
| 4174 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4175 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4176 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4177 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4178 | if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4179 | r = fill_yin_typedef(module, retval, sub, ¬if->tpdf[notif->tpdf_size], unres); |
| 4180 | notif->tpdf_size++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4181 | if (r) { |
| 4182 | goto error; |
| 4183 | } |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 4184 | } else if (!strcmp(sub->name, "if-features")) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4185 | r = fill_yin_iffeature(retval, sub, ¬if->features[notif->features_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4186 | notif->features_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4187 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4188 | goto error; |
| 4189 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4190 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4191 | } |
| 4192 | |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4193 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4194 | goto error; |
| 4195 | } |
| 4196 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4197 | /* last part - process data nodes */ |
| 4198 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4199 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4200 | node = read_yin_container(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4201 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4202 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4203 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4204 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4205 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4206 | node = read_yin_list(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4207 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4208 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4209 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4210 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4211 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4212 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4213 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4214 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4215 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4216 | if (!node) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4217 | goto error; |
| 4218 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4219 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4220 | lyxml_free(module->ctx, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4221 | } |
| 4222 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4223 | return retval; |
| 4224 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4225 | error: |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4226 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4227 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4228 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4229 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4230 | } |
| 4231 | |
| 4232 | return NULL; |
| 4233 | } |
| 4234 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4235 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4236 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4237 | read_yin_rpc(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 4238 | struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4239 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4240 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4241 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4242 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4243 | struct lys_node_rpc *rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4244 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4245 | int c_tpdf = 0, c_ftrs = 0; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4246 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4247 | /* init */ |
| 4248 | memset(&root, 0, sizeof root); |
| 4249 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4250 | rpc = calloc(1, sizeof *rpc); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4251 | if (!rpc) { |
| 4252 | LOGMEM; |
| 4253 | return NULL; |
| 4254 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4255 | rpc->nodetype = LYS_RPC; |
| 4256 | rpc->prev = (struct lys_node *)rpc; |
| 4257 | retval = (struct lys_node *)rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4258 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4259 | 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] | 4260 | goto error; |
| 4261 | } |
| 4262 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4263 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4264 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4265 | /* process rpc's specific children */ |
| 4266 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4267 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4268 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4269 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4270 | continue; |
| 4271 | } |
| 4272 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4273 | if (!strcmp(sub->name, "input")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4274 | if (rpc->child |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4275 | && (rpc->child->nodetype == LYS_INPUT |
| 4276 | || (rpc->child->next && rpc->child->next->nodetype == LYS_INPUT))) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4277 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4278 | goto error; |
| 4279 | } |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4280 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4281 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4282 | } else if (!strcmp(sub->name, "output")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4283 | if (rpc->child |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4284 | && (rpc->child->nodetype == LYS_INPUT |
| 4285 | || (rpc->child->next && rpc->child->next->nodetype == LYS_INPUT))) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4286 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4287 | goto error; |
| 4288 | } |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4289 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4290 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4291 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4292 | /* data statements */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4293 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4294 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4295 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4296 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4297 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4298 | } else if (!strcmp(sub->name, "typedef")) { |
| 4299 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4300 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4301 | c_ftrs++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4302 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4303 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4304 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4305 | } |
| 4306 | } |
| 4307 | |
| 4308 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4309 | if (c_tpdf) { |
| 4310 | rpc->tpdf = calloc(c_tpdf, sizeof *rpc->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4311 | if (!rpc->tpdf) { |
| 4312 | LOGMEM; |
| 4313 | goto error; |
| 4314 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4315 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4316 | if (c_ftrs) { |
| 4317 | rpc->features = calloc(c_ftrs, sizeof *rpc->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4318 | if (!rpc->features) { |
| 4319 | LOGMEM; |
| 4320 | goto error; |
| 4321 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4322 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4323 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4324 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4325 | if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4326 | r = fill_yin_typedef(module, retval, sub, &rpc->tpdf[rpc->tpdf_size], unres); |
| 4327 | rpc->tpdf_size++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4328 | if (r) { |
| 4329 | goto error; |
| 4330 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4331 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4332 | r = fill_yin_iffeature(retval, sub, &rpc->features[rpc->features_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4333 | rpc->features_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4334 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4335 | goto error; |
| 4336 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4337 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4338 | } |
| 4339 | |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4340 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4341 | goto error; |
| 4342 | } |
| 4343 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4344 | /* last part - process data nodes */ |
| 4345 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4346 | if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4347 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4348 | } else if (!strcmp(sub->name, "input")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4349 | node = read_yin_input_output(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4350 | } else if (!strcmp(sub->name, "output")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4351 | node = read_yin_input_output(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4352 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4353 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4354 | goto error; |
| 4355 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4356 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4357 | lyxml_free(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4358 | } |
| 4359 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4360 | return retval; |
| 4361 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4362 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4363 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4364 | lys_node_free(retval, NULL, 0); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 4365 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4366 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4367 | } |
| 4368 | |
| 4369 | return NULL; |
| 4370 | } |
| 4371 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4372 | /* logs directly |
| 4373 | * |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4374 | * resolve - referenced grouping should be bounded to the namespace (resolved) |
| 4375 | * only when uses does not appear in grouping. In a case of grouping's uses, |
| 4376 | * we just get information but we do not apply augment or refine to it. |
| 4377 | */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4378 | static struct lys_node * |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4379 | read_yin_uses(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] | 4380 | struct unres_schema *unres) |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4381 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4382 | struct lyxml_elem *sub, *next; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4383 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4384 | struct lys_node_uses *uses; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4385 | const char *value; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4386 | int c_ref = 0, c_aug = 0, c_ftrs = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4387 | int r; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4388 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4389 | uses = calloc(1, sizeof *uses); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4390 | if (!uses) { |
| 4391 | LOGMEM; |
| 4392 | return NULL; |
| 4393 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4394 | uses->nodetype = LYS_USES; |
| 4395 | uses->prev = (struct lys_node *)uses; |
| 4396 | retval = (struct lys_node *)uses; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4397 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4398 | GETVAL(value, yin, "name"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4399 | uses->name = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 4400 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 4401 | if (read_yin_common(module, parent, retval, yin, OPT_MODULE |
| 4402 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4403 | goto error; |
| 4404 | } |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4405 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4406 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4407 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4408 | /* get other properties of uses */ |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4409 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4410 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4411 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4412 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4413 | continue; |
| 4414 | } |
| 4415 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4416 | if (!strcmp(sub->name, "refine")) { |
| 4417 | c_ref++; |
| 4418 | } else if (!strcmp(sub->name, "augment")) { |
| 4419 | c_aug++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4420 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 56e8977 | 2015-06-19 10:00:54 +0200 | [diff] [blame] | 4421 | c_ftrs++; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4422 | } else if (!strcmp(sub->name, "when")) { |
| 4423 | if (uses->when) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4424 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4425 | goto error; |
| 4426 | } |
| 4427 | |
| 4428 | uses->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4429 | if (!uses->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4430 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4431 | goto error; |
| 4432 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4433 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4434 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4435 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4436 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4437 | } |
| 4438 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4439 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4440 | /* process properties with cardinality 0..n */ |
| 4441 | if (c_ref) { |
| 4442 | uses->refine = calloc(c_ref, sizeof *uses->refine); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4443 | if (!uses->refine) { |
| 4444 | LOGMEM; |
| 4445 | goto error; |
| 4446 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4447 | } |
| 4448 | if (c_aug) { |
| 4449 | uses->augment = calloc(c_aug, sizeof *uses->augment); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4450 | if (!uses->augment) { |
| 4451 | LOGMEM; |
| 4452 | goto error; |
| 4453 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4454 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4455 | if (c_ftrs) { |
| 4456 | uses->features = calloc(c_ftrs, sizeof *uses->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4457 | if (!uses->features) { |
| 4458 | LOGMEM; |
| 4459 | goto error; |
| 4460 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4461 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4462 | |
Radek Krejci | c428344 | 2016-04-22 09:19:27 +0200 | [diff] [blame] | 4463 | if (lys_node_addchild(parent, lys_main_module(module), retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4464 | goto error; |
| 4465 | } |
| 4466 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4467 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4468 | if (!strcmp(sub->name, "refine")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4469 | r = fill_yin_refine(module, sub, &uses->refine[uses->refine_size]); |
| 4470 | uses->refine_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4471 | if (r) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4472 | goto error; |
| 4473 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4474 | } else if (!strcmp(sub->name, "augment")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4475 | r = fill_yin_augment(module, retval, sub, &uses->augment[uses->augment_size], unres); |
| 4476 | uses->augment_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4477 | if (r) { |
| 4478 | goto error; |
| 4479 | } |
| 4480 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4481 | r = fill_yin_iffeature(retval, sub, &uses->features[uses->features_size], unres); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4482 | uses->features_size++; |
Michal Vasko | 1d337e1 | 2016-02-15 12:32:04 +0100 | [diff] [blame] | 4483 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4484 | goto error; |
| 4485 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4486 | } |
| 4487 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4488 | |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4489 | if (unres_schema_add_node(module, unres, uses, UNRES_USES, NULL) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4490 | goto error; |
| 4491 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4492 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4493 | if (resolve) { |
| 4494 | /* inherit config flag */ |
| 4495 | if (parent) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4496 | retval->flags |= parent->flags & LYS_CONFIG_MASK; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4497 | } else { |
| 4498 | /* default config is true */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4499 | retval->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4500 | } |
| 4501 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 4502 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4503 | return retval; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4504 | |
| 4505 | error: |
| 4506 | |
Michal Vasko | d51d6ad | 2016-02-16 13:24:31 +0100 | [diff] [blame] | 4507 | lys_node_free(retval, NULL, 0); |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4508 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4509 | return NULL; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4510 | } |
| 4511 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4512 | /* logs directly |
| 4513 | * |
| 4514 | * common code for yin_read_module() and yin_read_submodule() |
| 4515 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4516 | static int |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4517 | read_sub_module(struct lys_module *module, struct lys_submodule *submodule, struct lyxml_elem *yin, |
| 4518 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4519 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4520 | struct ly_ctx *ctx = module->ctx; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4521 | struct lyxml_elem *next, *child, *child2, root, grps, augs; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4522 | struct lys_node *node = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4523 | struct lys_module *trg; |
Pavol Vican | 974377b | 2016-03-23 00:38:53 +0100 | [diff] [blame] | 4524 | struct lys_include inc; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4525 | const char *value; |
Pavol Vican | 974377b | 2016-03-23 00:38:53 +0100 | [diff] [blame] | 4526 | int i, r; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4527 | int inc_size_aux = 0; |
| 4528 | int version_flag = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4529 | /* counters */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4530 | 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] | 4531 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4532 | /* to simplify code, store the module/submodule being processed as trg */ |
Michal Vasko | fe7e5a7 | 2016-05-02 14:49:23 +0200 | [diff] [blame] | 4533 | trg = submodule ? (struct lys_module *)submodule : module; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4534 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4535 | /* init */ |
| 4536 | memset(&root, 0, sizeof root); |
| 4537 | memset(&grps, 0, sizeof grps); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4538 | memset(&augs, 0, sizeof augs); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4539 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4540 | /* |
| 4541 | * in the first run, we process elements with cardinality of 1 or 0..1 and |
| 4542 | * count elements with cardinality 0..n. Data elements (choices, containers, |
| 4543 | * leafs, lists, leaf-lists) are moved aside to be processed last, since we |
| 4544 | * need have all top-level and groupings already prepared at that time. In |
| 4545 | * the middle loop, we process other elements with carinality of 0..n since |
| 4546 | * we need to allocate arrays to store them. |
| 4547 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4548 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 4549 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4550 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4551 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4552 | continue; |
| 4553 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4554 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4555 | if (!submodule && !strcmp(child->name, "namespace")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4556 | if (module->ns) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4557 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4558 | goto error; |
| 4559 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4560 | GETVAL(value, child, "uri"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4561 | module->ns = lydict_insert(ctx, value, strlen(value)); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4562 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4563 | } else if (!submodule && !strcmp(child->name, "prefix")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4564 | if (module->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4565 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4566 | goto error; |
| 4567 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4568 | GETVAL(value, child, "value"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4569 | if (lyp_check_identifier(value, LY_IDENT_PREFIX, module, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4570 | goto error; |
| 4571 | } |
| 4572 | module->prefix = lydict_insert(ctx, value, strlen(value)); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4573 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4574 | } else if (submodule && !strcmp(child->name, "belongs-to")) { |
| 4575 | if (submodule->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4576 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4577 | goto error; |
| 4578 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4579 | GETVAL(value, child, "module"); |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 4580 | if (!ly_strequal(value, submodule->belongsto->name, 1)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4581 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4582 | goto error; |
| 4583 | } |
Radek Krejci | f388693 | 2015-06-04 17:36:06 +0200 | [diff] [blame] | 4584 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4585 | /* get the prefix substatement, start with checks */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4586 | if (!child->child) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4587 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4588 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4589 | } else if (strcmp(child->child->name, "prefix")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4590 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4591 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4592 | } else if (child->child->next) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4593 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->child->next->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4594 | goto error; |
| 4595 | } |
| 4596 | /* and now finally get the value */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4597 | GETVAL(value, child->child, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4598 | /* check here differs from a generic prefix check, since this prefix |
| 4599 | * don't have to be unique |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4600 | */ |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4601 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4602 | goto error; |
| 4603 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4604 | submodule->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 0af1387 | 2015-05-30 11:50:52 +0200 | [diff] [blame] | 4605 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4606 | /* we are done with belongs-to */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4607 | lyxml_free(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4608 | |
| 4609 | /* counters (statements with n..1 cardinality) */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4610 | } else if (!strcmp(child->name, "import")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4611 | c_imp++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4612 | } else if (!strcmp(child->name, "revision")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4613 | c_rev++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4614 | } else if (!strcmp(child->name, "typedef")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4615 | c_tpdf++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4616 | } else if (!strcmp(child->name, "identity")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4617 | c_ident++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4618 | } else if (!strcmp(child->name, "include")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4619 | c_inc++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4620 | } else if (!strcmp(child->name, "augment")) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4621 | c_aug++; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4622 | /* keep augments separated, processed last */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4623 | lyxml_unlink_elem(ctx, child, 2); |
| 4624 | lyxml_add_child(ctx, &augs, child); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4625 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4626 | } else if (!strcmp(child->name, "feature")) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4627 | c_ftrs++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4628 | } else if (!strcmp(child->name, "deviation")) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4629 | c_dev++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4630 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4631 | /* data statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4632 | } else if (!strcmp(child->name, "container") || |
| 4633 | !strcmp(child->name, "leaf-list") || |
| 4634 | !strcmp(child->name, "leaf") || |
| 4635 | !strcmp(child->name, "list") || |
| 4636 | !strcmp(child->name, "choice") || |
| 4637 | !strcmp(child->name, "uses") || |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 4638 | !strcmp(child->name, "anyxml") || |
| 4639 | !strcmp(child->name, "rpc") || |
| 4640 | !strcmp(child->name, "notification")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4641 | lyxml_unlink_elem(ctx, child, 2); |
| 4642 | lyxml_add_child(ctx, &root, child); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 4643 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4644 | } else if (!strcmp(child->name, "grouping")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4645 | /* keep groupings separated and process them before other data statements */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4646 | lyxml_unlink_elem(ctx, child, 2); |
| 4647 | lyxml_add_child(ctx, &grps, child); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4648 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4649 | /* optional statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4650 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4651 | if (trg->dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4652 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4653 | goto error; |
| 4654 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4655 | trg->dsc = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4656 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4657 | if (!trg->dsc) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4658 | goto error; |
| 4659 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4660 | } else if (!strcmp(child->name, "reference")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4661 | if (trg->ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4662 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4663 | goto error; |
| 4664 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4665 | trg->ref = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4666 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4667 | if (!trg->ref) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4668 | goto error; |
| 4669 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4670 | } else if (!strcmp(child->name, "organization")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4671 | if (trg->org) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4672 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4673 | goto error; |
| 4674 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4675 | trg->org = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4676 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4677 | if (!trg->org) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4678 | goto error; |
| 4679 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4680 | } else if (!strcmp(child->name, "contact")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4681 | if (trg->contact) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4682 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4683 | goto error; |
| 4684 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4685 | trg->contact = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4686 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4687 | if (!trg->contact) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4688 | goto error; |
| 4689 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4690 | } else if (!strcmp(child->name, "yang-version")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4691 | /* TODO: support YANG 1.1 ? */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4692 | if (version_flag) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4693 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4694 | goto error; |
| 4695 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4696 | GETVAL(value, child, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4697 | if (strcmp(value, "1")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4698 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, "yang-version"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4699 | goto error; |
| 4700 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4701 | version_flag = 1; |
| 4702 | if (!submodule) { |
| 4703 | module->version = 1; |
| 4704 | } /* TODO else check for the submodule's same version as in main module, waits for YANG 1.1 support */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4705 | lyxml_free(ctx, child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4706 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4707 | } else if (!strcmp(child->name, "extension")) { |
| 4708 | GETVAL(value, child, "name"); |
Radek Krejci | 5166a89 | 2015-07-02 16:44:24 +0200 | [diff] [blame] | 4709 | |
Radek Krejci | 3d46812 | 2015-10-02 13:36:12 +0200 | [diff] [blame] | 4710 | /* we have the following supported (hardcoded) extensions: */ |
| 4711 | /* ietf-netconf's get-filter-element-attributes */ |
| 4712 | if (!strcmp(module->ns, LY_NSNC) && |
| 4713 | !strcmp(value, "get-filter-element-attributes")) { |
| 4714 | LOGDBG("NETCONF filter extension found"); |
| 4715 | /* NACM's default-deny-write and default-deny-all */ |
| 4716 | } else if (!strcmp(module->ns, LY_NSNACM) && |
| 4717 | (!strcmp(value, "default-deny-write") || !strcmp(value, "default-deny-all"))) { |
| 4718 | LOGDBG("NACM extension found"); |
| 4719 | /* other extensions are not supported, so inform about such an extension */ |
| 4720 | } else { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 4721 | LOGWRN("Not supported \"%s\" extension statement found, ignoring.", value); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4722 | lyxml_free(ctx, child); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 4723 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4724 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4725 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4726 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4727 | } |
| 4728 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4729 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4730 | /* check for mandatory statements */ |
| 4731 | if (submodule && !submodule->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4732 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "belongs-to", "submodule"); |
Michal Vasko | bdf51ef | 2015-12-10 12:11:21 +0100 | [diff] [blame] | 4733 | goto error; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4734 | } else if (!submodule) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4735 | if (!module->ns) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4736 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "namespace", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4737 | goto error; |
| 4738 | } |
| 4739 | if (!module->prefix) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4740 | LOGVAL(LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4741 | goto error; |
| 4742 | } |
| 4743 | } |
Radek Krejci | bb3257d | 2015-05-21 23:03:51 +0200 | [diff] [blame] | 4744 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4745 | /* allocate arrays for elements with cardinality of 0..n */ |
| 4746 | if (c_imp) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4747 | trg->imp = calloc(c_imp, sizeof *trg->imp); |
| 4748 | if (!trg->imp) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4749 | LOGMEM; |
| 4750 | goto error; |
| 4751 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4752 | } |
| 4753 | if (c_rev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4754 | trg->rev = calloc(c_rev, sizeof *trg->rev); |
| 4755 | if (!trg->rev) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4756 | LOGMEM; |
| 4757 | goto error; |
| 4758 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4759 | } |
| 4760 | if (c_tpdf) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4761 | trg->tpdf = calloc(c_tpdf, sizeof *trg->tpdf); |
| 4762 | if (!trg->tpdf) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4763 | LOGMEM; |
| 4764 | goto error; |
| 4765 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4766 | } |
| 4767 | if (c_ident) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4768 | trg->ident = calloc(c_ident, sizeof *trg->ident); |
| 4769 | if (!trg->ident) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4770 | LOGMEM; |
| 4771 | goto error; |
| 4772 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4773 | } |
| 4774 | if (c_inc) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4775 | trg->inc = calloc(c_inc, sizeof *trg->inc); |
| 4776 | if (!trg->inc) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4777 | LOGMEM; |
| 4778 | goto error; |
| 4779 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4780 | trg->inc_size = c_inc; |
| 4781 | /* trg->inc_size can be updated by the included submodules, |
| 4782 | * so we will use inc_size_aux here, trg->inc_size stores the |
| 4783 | * target size of the array |
| 4784 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4785 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4786 | if (c_aug) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4787 | trg->augment = calloc(c_aug, sizeof *trg->augment); |
| 4788 | if (!trg->augment) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4789 | LOGMEM; |
| 4790 | goto error; |
| 4791 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4792 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4793 | if (c_ftrs) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4794 | trg->features = calloc(c_ftrs, sizeof *trg->features); |
| 4795 | if (!trg->features) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4796 | LOGMEM; |
| 4797 | goto error; |
| 4798 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4799 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4800 | if (c_dev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4801 | trg->deviation = calloc(c_dev, sizeof *trg->deviation); |
| 4802 | if (!trg->deviation) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4803 | LOGMEM; |
| 4804 | goto error; |
| 4805 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4806 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4807 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4808 | /* middle part - process nodes with cardinality of 0..n except the data nodes and augments */ |
| 4809 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4810 | if (!strcmp(child->name, "import")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4811 | r = fill_yin_import(trg, child, &trg->imp[trg->imp_size]); |
| 4812 | trg->imp_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4813 | if (r) { |
| 4814 | goto error; |
| 4815 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4816 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4817 | /* check duplicities in imported modules */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4818 | for (i = 0; i < trg->imp_size - 1; i++) { |
| 4819 | if (!strcmp(trg->imp[i].module->name, trg->imp[trg->imp_size - 1].module->name)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4820 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, trg->imp[i].module->name, "import"); |
| 4821 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Importing module \"%s\" repeatedly.", trg->imp[i].module->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4822 | goto error; |
| 4823 | } |
| 4824 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4825 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4826 | } else if (!strcmp(child->name, "include")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4827 | memset(&inc, 0, sizeof inc); |
| 4828 | /* 1) pass module, not trg, since we want to pass the main module |
| 4829 | * 2) we cannot pass directly the structure in the array since |
| 4830 | * submodule parser can realloc our array of includes */ |
Michal Vasko | 5ff7882 | 2016-02-12 09:33:31 +0100 | [diff] [blame] | 4831 | r = fill_yin_include(module, submodule, child, &inc, unres); |
Michal Vasko | 9c4c99d | 2016-02-11 15:47:08 +0100 | [diff] [blame] | 4832 | memcpy(&trg->inc[inc_size_aux], &inc, sizeof inc); |
| 4833 | inc_size_aux++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4834 | if (r) { |
| 4835 | goto error; |
| 4836 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4837 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4838 | /* check duplications in include submodules */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4839 | for (i = 0; i < inc_size_aux - 1; i++) { |
Michal Vasko | 27ab822 | 2016-02-12 09:33:52 +0100 | [diff] [blame] | 4840 | if (trg->inc[i].submodule && !strcmp(trg->inc[i].submodule->name, trg->inc[inc_size_aux - 1].submodule->name)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4841 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, trg->inc[i].submodule->name, "include"); |
| 4842 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Including submodule \"%s\" repeatedly.", trg->inc[i].submodule->name); |
Pavol Vican | 5587041 | 2016-03-10 12:36:21 +0100 | [diff] [blame] | 4843 | trg->inc[inc_size_aux - 1].submodule = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4844 | goto error; |
| 4845 | } |
| 4846 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4847 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4848 | } else if (!strcmp(child->name, "revision")) { |
| 4849 | GETVAL(value, child, "date"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4850 | if (lyp_check_date(value)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4851 | goto error; |
| 4852 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4853 | memcpy(trg->rev[trg->rev_size].date, value, LY_REV_SIZE - 1); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4854 | /* check uniqueness of the revision date - not required by RFC */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4855 | for (i = 0; i < trg->rev_size; i++) { |
| 4856 | if (!strcmp(value, trg->rev[i].date)) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4857 | LOGVAL(LYE_INARG, LY_VLOG_NONE, NULL, value, child->name); |
| 4858 | LOGVAL(LYE_SPEC, LY_VLOG_NONE, NULL, "Revision is not unique."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4859 | } |
| 4860 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4861 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4862 | LY_TREE_FOR(child->child, child2) { |
| 4863 | if (!strcmp(child2->name, "description")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4864 | if (trg->rev[trg->rev_size].dsc) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4865 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child2->name, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4866 | goto error; |
| 4867 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4868 | trg->rev[trg->rev_size].dsc = read_yin_subnode(ctx, child2, "text"); |
| 4869 | if (!trg->rev[trg->rev_size].dsc) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4870 | goto error; |
| 4871 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4872 | } else if (!strcmp(child2->name, "reference")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4873 | if (trg->rev[trg->rev_size].ref) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4874 | LOGVAL(LYE_TOOMANY, LY_VLOG_NONE, NULL, child2->name, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4875 | goto error; |
| 4876 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4877 | trg->rev[trg->rev_size].ref = read_yin_subnode(ctx, child2, "text"); |
| 4878 | if (!trg->rev[trg->rev_size].ref) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4879 | goto error; |
| 4880 | } |
| 4881 | } else { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 4882 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, child2->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4883 | goto error; |
| 4884 | } |
| 4885 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4886 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4887 | /* keep the latest revision at position 0 */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4888 | 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] | 4889 | /* switch their position */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4890 | value = strdup(trg->rev[0].date); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4891 | if (!value) { |
| 4892 | LOGMEM; |
| 4893 | goto error; |
| 4894 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4895 | memcpy(trg->rev[0].date, trg->rev[trg->rev_size].date, LY_REV_SIZE - 1); |
| 4896 | memcpy(trg->rev[trg->rev_size].date, value, LY_REV_SIZE - 1); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4897 | free((char *)value); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4898 | |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 4899 | 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] | 4900 | value = trg->rev[0].dsc; |
| 4901 | trg->rev[0].dsc = trg->rev[trg->rev_size].dsc; |
| 4902 | trg->rev[trg->rev_size].dsc = value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4903 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4904 | |
Radek Krejci | 749190d | 2016-02-18 16:26:25 +0100 | [diff] [blame] | 4905 | 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] | 4906 | value = trg->rev[0].ref; |
| 4907 | trg->rev[0].ref = trg->rev[trg->rev_size].ref; |
| 4908 | trg->rev[trg->rev_size].ref = value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4909 | } |
| 4910 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4911 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4912 | trg->rev_size++; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4913 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4914 | } else if (!strcmp(child->name, "typedef")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4915 | r = fill_yin_typedef(trg, NULL, child, &trg->tpdf[trg->tpdf_size], unres); |
| 4916 | trg->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4917 | if (r) { |
| 4918 | goto error; |
| 4919 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4920 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4921 | } else if (!strcmp(child->name, "identity")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4922 | r = fill_yin_identity(trg, child, &trg->ident[trg->ident_size], unres); |
| 4923 | trg->ident_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4924 | if (r) { |
| 4925 | goto error; |
| 4926 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4927 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4928 | } else if (!strcmp(child->name, "feature")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4929 | r = fill_yin_feature(trg, child, &trg->features[trg->features_size], unres); |
| 4930 | trg->features_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4931 | if (r) { |
| 4932 | goto error; |
| 4933 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4934 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4935 | } else if (!strcmp(child->name, "deviation")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4936 | r = fill_yin_deviation(trg, child, &trg->deviation[trg->deviation_size], unres); |
| 4937 | trg->deviation_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4938 | if (r) { |
| 4939 | goto error; |
| 4940 | } |
Michal Vasko | 53a42af | 2016-02-12 11:05:02 +0100 | [diff] [blame] | 4941 | /* module with deviation - must be implemented (description of /ietf-yang-library:modules-state/module/deviation) */ |
| 4942 | module->implemented = 1; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4943 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4944 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4945 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4946 | |
Pavol Vican | e994fda | 2016-03-22 10:47:58 +0100 | [diff] [blame] | 4947 | if (submodule && lyp_propagate_submodule(module, submodule)) { |
Pavol Vican | aa1eba9 | 2016-03-09 12:27:11 +0100 | [diff] [blame] | 4948 | goto error; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4949 | } |
| 4950 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4951 | /* process data nodes. Start with groupings to allow uses |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4952 | * refer to them. Submodule's data nodes are stored in the |
| 4953 | * main module data tree. |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4954 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4955 | LY_TREE_FOR_SAFE(grps.child, next, child) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4956 | node = read_yin_grouping(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4957 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4958 | goto error; |
| 4959 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4960 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4961 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4962 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4963 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4964 | /* parse data nodes, ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4965 | LY_TREE_FOR_SAFE(root.child, next, child) { |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4966 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4967 | if (!strcmp(child->name, "container")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 4968 | node = read_yin_container(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4969 | } else if (!strcmp(child->name, "leaf-list")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 4970 | node = read_yin_leaflist(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4971 | } else if (!strcmp(child->name, "leaf")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 4972 | node = read_yin_leaf(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4973 | } else if (!strcmp(child->name, "list")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 4974 | node = read_yin_list(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4975 | } else if (!strcmp(child->name, "choice")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 4976 | node = read_yin_choice(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4977 | } else if (!strcmp(child->name, "uses")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 4978 | node = read_yin_uses(trg, NULL, child, 1, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4979 | } else if (!strcmp(child->name, "anyxml")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 4980 | node = read_yin_anyxml(trg, NULL, child, 1, unres); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 4981 | } else if (!strcmp(child->name, "rpc")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 4982 | node = read_yin_rpc(trg, NULL, child, 0, unres); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 4983 | } else if (!strcmp(child->name, "notification")) { |
Michal Vasko | cd07422 | 2016-02-15 11:07:03 +0100 | [diff] [blame] | 4984 | node = read_yin_notif(trg, NULL, child, 0, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4985 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4986 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4987 | goto error; |
| 4988 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 4989 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4990 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4991 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4992 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4993 | /* ... and finally augments (last, so we can augment our data, for instance) */ |
| 4994 | LY_TREE_FOR_SAFE(augs.child, next, child) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4995 | r = fill_yin_augment(trg, NULL, child, &trg->augment[trg->augment_size], unres); |
| 4996 | trg->augment_size++; |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4997 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4998 | if (r) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4999 | goto error; |
| 5000 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5001 | lyxml_free(ctx, child); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5002 | } |
| 5003 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5004 | return EXIT_SUCCESS; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5005 | |
| 5006 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5007 | /* cleanup */ |
| 5008 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5009 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5010 | } |
| 5011 | while (grps.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5012 | lyxml_free(module->ctx, grps.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5013 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5014 | while (augs.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5015 | lyxml_free(module->ctx, augs.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5016 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5017 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5018 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5019 | } |
| 5020 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5021 | /* logs directly */ |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5022 | struct lys_submodule * |
| 5023 | 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] | 5024 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5025 | struct lyxml_elem *yin; |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5026 | struct lys_submodule *submodule = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5027 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5028 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5029 | assert(module->ctx); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5030 | |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 5031 | yin = lyxml_parse_mem(module->ctx, data, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5032 | if (!yin) { |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5033 | return NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5034 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5035 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5036 | /* check root element */ |
| 5037 | if (!yin->name || strcmp(yin->name, "submodule")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5038 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5039 | goto error; |
| 5040 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5041 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5042 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5043 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5044 | goto error; |
| 5045 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5046 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5047 | submodule = calloc(1, sizeof *submodule); |
| 5048 | if (!submodule) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5049 | LOGMEM; |
| 5050 | goto error; |
| 5051 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5052 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5053 | submodule->ctx = module->ctx; |
| 5054 | submodule->name = lydict_insert(submodule->ctx, value, strlen(value)); |
| 5055 | submodule->type = 1; |
| 5056 | submodule->belongsto = module; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5057 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5058 | LOGVRB("Reading submodule \"%s\".", submodule->name); |
| 5059 | if (read_sub_module(module, submodule, yin, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5060 | goto error; |
| 5061 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5062 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5063 | /* cleanup */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5064 | lyxml_free(module->ctx, yin); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5065 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5066 | LOGVRB("Submodule \"%s\" successfully parsed.", submodule->name); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5067 | return submodule; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5068 | |
| 5069 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5070 | /* cleanup */ |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5071 | unres_schema_free((struct lys_module *)submodule, &unres); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5072 | lyxml_free(module->ctx, yin); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5073 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5074 | if (!submodule) { |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 5075 | LOGERR(ly_errno, "Submodule parsing failed."); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5076 | return NULL; |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 5077 | } |
| 5078 | |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5079 | LOGERR(ly_errno, "Submodule \"%s\" parsing failed.", submodule->name); |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 5080 | |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 5081 | lys_sub_module_remove_devs_augs((struct lys_module *)submodule); |
| 5082 | lys_submodule_module_data_free(submodule); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5083 | lys_submodule_free(submodule, NULL); |
Michal Vasko | 5a721fd | 2016-02-16 12:16:48 +0100 | [diff] [blame] | 5084 | return NULL; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5085 | } |
| 5086 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5087 | /* logs directly */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5088 | struct lys_module * |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 5089 | 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] | 5090 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5091 | struct lyxml_elem *yin; |
Pavol Vican | c99b59e | 2016-03-22 15:46:39 +0100 | [diff] [blame] | 5092 | struct lys_module *module = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5093 | struct unres_schema *unres; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5094 | const char *value; |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 5095 | int i; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5096 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5097 | unres = calloc(1, sizeof *unres); |
| 5098 | if (!unres) { |
| 5099 | LOGMEM; |
| 5100 | return NULL; |
| 5101 | } |
| 5102 | |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 5103 | yin = lyxml_parse_mem(ctx, data, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5104 | if (!yin) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5105 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5106 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5107 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5108 | /* check root element */ |
| 5109 | if (!yin->name || strcmp(yin->name, "module")) { |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5110 | LOGVAL(LYE_INSTMT, LY_VLOG_NONE, NULL, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5111 | goto error; |
| 5112 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5113 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5114 | GETVAL(value, yin, "name"); |
Radek Krejci | 48464ed | 2016-03-17 15:44:09 +0100 | [diff] [blame] | 5115 | if (lyp_check_identifier(value, LY_IDENT_NAME, NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5116 | goto error; |
| 5117 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5118 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5119 | module = calloc(1, sizeof *module); |
| 5120 | if (!module) { |
| 5121 | LOGMEM; |
| 5122 | goto error; |
| 5123 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5124 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5125 | module->ctx = ctx; |
| 5126 | module->name = lydict_insert(ctx, value, strlen(value)); |
| 5127 | module->type = 0; |
Michal Vasko | d8aa32d | 2015-07-24 11:50:01 +0200 | [diff] [blame] | 5128 | module->implemented = (implement ? 1 : 0); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5129 | |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5130 | LOGVRB("Reading module \"%s\".", module->name); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5131 | if (read_sub_module(module, NULL, yin, unres)) { |
| 5132 | goto error; |
| 5133 | } |
| 5134 | |
| 5135 | /* resolve rest of unres items */ |
| 5136 | if (unres->count && resolve_unres_schema(module, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5137 | goto error; |
| 5138 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5139 | |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 5140 | if (revision) { |
| 5141 | /* check revision of the parsed model */ |
| 5142 | if (!module->rev_size || strcmp(revision, module->rev[0].date)) { |
Michal Vasko | b24e788 | 2016-03-21 16:13:25 +0100 | [diff] [blame] | 5143 | LOGVRB("Module \"%s\" parsed with the wrong revision (\"%s\" instead \"%s\").", |
| 5144 | module->name, module->rev[0].date, revision); |
Radek Krejci | ff4874d | 2016-03-07 12:30:50 +0100 | [diff] [blame] | 5145 | goto error; |
| 5146 | } |
| 5147 | } |
| 5148 | |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 5149 | if (lyp_ctx_add_module(&module)) { |
Pavol Vican | c99b59e | 2016-03-22 15:46:39 +0100 | [diff] [blame] | 5150 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5151 | } |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 5152 | |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 5153 | if (module->augment_size || module->deviation_size) { |
Michal Vasko | 5cec331 | 2016-05-04 08:59:41 +0200 | [diff] [blame] | 5154 | if (!module->implemented) { |
| 5155 | LOGVRB("Module \"%s\" includes augments or deviations, changing conformance to \"implement\".", module->name); |
| 5156 | } |
Michal Vasko | 2605575 | 2016-05-03 11:36:31 +0200 | [diff] [blame] | 5157 | if (lys_module_set_implement(module)) { |
| 5158 | goto error; |
| 5159 | } |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 5160 | |
Michal Vasko | 2605575 | 2016-05-03 11:36:31 +0200 | [diff] [blame] | 5161 | if (lys_sub_module_set_dev_aug_target_implement(module)) { |
| 5162 | goto error; |
| 5163 | } |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 5164 | for (i = 0; i < module->inc_size; ++i) { |
Michal Vasko | 2605575 | 2016-05-03 11:36:31 +0200 | [diff] [blame] | 5165 | if (lys_sub_module_set_dev_aug_target_implement((struct lys_module *)module->inc[i].submodule)) { |
| 5166 | goto error; |
| 5167 | } |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 5168 | } |
| 5169 | } |
| 5170 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5171 | lyxml_free(ctx, yin); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5172 | unres_schema_free(NULL, &unres); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5173 | LOGVRB("Module \"%s\" successfully parsed.", module->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5174 | return module; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5175 | |
| 5176 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5177 | /* cleanup */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5178 | lyxml_free(ctx, yin); |
Radek Krejci | b8c07b8 | 2016-02-12 11:11:55 +0100 | [diff] [blame] | 5179 | unres_schema_free(module, &unres); |
| 5180 | |
| 5181 | if (!module) { |
Radek Krejci | daea821 | 2016-02-15 08:28:20 +0100 | [diff] [blame] | 5182 | LOGERR(ly_errno, "Module parsing failed."); |
Radek Krejci | b8c07b8 | 2016-02-12 11:11:55 +0100 | [diff] [blame] | 5183 | return NULL; |
| 5184 | } |
| 5185 | |
| 5186 | LOGERR(ly_errno, "Module \"%s\" parsing failed.", module->name); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5187 | |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 5188 | lys_sub_module_remove_devs_augs(module); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5189 | lys_free(module, NULL, 1); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5190 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5191 | } |