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 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in |
| 15 | * the documentation and/or other materials provided with the |
| 16 | * distribution. |
| 17 | * 3. Neither the name of the Company nor the names of its contributors |
| 18 | * may be used to endorse or promote products derived from this |
| 19 | * software without specific prior written permission. |
| 20 | */ |
| 21 | |
Radek Krejci | 812b10a | 2015-05-28 16:48:25 +0200 | [diff] [blame] | 22 | #include <assert.h> |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 23 | #include <ctype.h> |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 24 | #include <errno.h> |
| 25 | #include <limits.h> |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 26 | #include <stdint.h> |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 27 | #include <stdlib.h> |
| 28 | #include <string.h> |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 29 | #include <stddef.h> |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 30 | #include <sys/types.h> |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 31 | #include <pcre.h> |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 32 | |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 33 | #include "libyang.h" |
| 34 | #include "common.h" |
| 35 | #include "context.h" |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 36 | #include "xpath.h" |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 37 | #include "dict.h" |
| 38 | #include "parser.h" |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 39 | #include "resolve.h" |
| 40 | #include "tree_internal.h" |
Radek Krejci | c6704c8 | 2015-10-06 11:12:45 +0200 | [diff] [blame] | 41 | #include "xml_private.h" |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 42 | |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 43 | enum LY_IDENT { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 44 | LY_IDENT_SIMPLE, /* only syntax rules */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 45 | LY_IDENT_FEATURE, |
| 46 | LY_IDENT_IDENTITY, |
| 47 | LY_IDENT_TYPE, |
| 48 | LY_IDENT_NODE, |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 49 | LY_IDENT_NAME, /* uniqueness across the siblings */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 50 | LY_IDENT_PREFIX |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 51 | }; |
| 52 | |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 53 | #define GETVAL(value, node, arg) \ |
| 54 | value = lyxml_get_attr(node, arg, NULL); \ |
| 55 | if (!value) { \ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 56 | LOGVAL(LYE_MISSARG, LOGLINE(node), arg, node->name); \ |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 57 | goto error; \ |
| 58 | } |
| 59 | |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 60 | #define OPT_IDENT 0x01 |
| 61 | #define OPT_CONFIG 0x02 |
| 62 | #define OPT_MODULE 0x04 |
| 63 | #define OPT_INHERIT 0x08 |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 64 | #define OPT_NACMEXT 0x10 |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 65 | 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] | 66 | |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 67 | 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] | 68 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 69 | 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] | 70 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 71 | 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] | 72 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 73 | 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] | 74 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 75 | 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] | 76 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 77 | 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] | 78 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 79 | 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] | 80 | int resolve, struct unres_schema *unres); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 81 | 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] | 82 | int resolve, struct unres_schema *unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 83 | 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] | 84 | int resolve, struct unres_schema *unres); |
| 85 | 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] | 86 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 87 | /* does not log */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 88 | static int |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 89 | dup_typedef_check(const char *type, struct lys_tpdf *tpdf, int size) |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 90 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 91 | int i; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 92 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 93 | for (i = 0; i < size; i++) { |
| 94 | if (!strcmp(type, tpdf[i].name)) { |
| 95 | /* name collision */ |
| 96 | return EXIT_FAILURE; |
| 97 | } |
| 98 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 99 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 100 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 101 | } |
| 102 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 103 | /* does not log */ |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 104 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 105 | dup_feature_check(const char *id, struct lys_module *module) |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 106 | { |
| 107 | int i; |
| 108 | |
| 109 | for (i = 0; i < module->features_size; i++) { |
| 110 | if (!strcmp(id, module->features[i].name)) { |
| 111 | return EXIT_FAILURE; |
| 112 | } |
| 113 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 114 | |
| 115 | return EXIT_SUCCESS; |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 116 | } |
| 117 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 118 | /* does not log */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 119 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 120 | dup_prefix_check(const char *prefix, struct lys_module *module) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 121 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 122 | int i; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 123 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 124 | if (!module->type && module->prefix && !strcmp(module->prefix, prefix)) { |
| 125 | return EXIT_FAILURE; |
| 126 | } |
| 127 | for (i = 0; i < module->imp_size; i++) { |
| 128 | if (!strcmp(module->imp[i].prefix, prefix)) { |
| 129 | return EXIT_FAILURE; |
| 130 | } |
| 131 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 132 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 133 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 134 | } |
| 135 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 136 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 137 | static int |
| 138 | check_identifier(const char *id, enum LY_IDENT type, unsigned int line, |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 139 | struct lys_module *module, struct lys_node *parent) |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 140 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 141 | int i; |
| 142 | int size; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 143 | struct lys_tpdf *tpdf; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 144 | struct lys_node *node; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 145 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 146 | assert(id); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 147 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 148 | /* check id syntax */ |
| 149 | if (!(id[0] >= 'A' && id[0] <= 'Z') && !(id[0] >= 'a' && id[0] <= 'z') && id[0] != '_') { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 150 | LOGVAL(LYE_INID, line, id, "invalid start character"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 151 | return EXIT_FAILURE; |
| 152 | } |
| 153 | for (i = 1; id[i]; i++) { |
| 154 | if (!(id[i] >= 'A' && id[i] <= 'Z') && !(id[i] >= 'a' && id[i] <= 'z') |
| 155 | && !(id[i] >= '0' && id[i] <= '9') && id[i] != '_' && id[i] != '-' && id[i] != '.') { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 156 | LOGVAL(LYE_INID, line, id, "invalid character"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 157 | return EXIT_FAILURE; |
| 158 | } |
| 159 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 160 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 161 | if (i > 64) { |
| 162 | LOGWRN("Identifier \"%s\" is long, you should use something shorter.", id); |
| 163 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 164 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 165 | switch (type) { |
| 166 | case LY_IDENT_NAME: |
| 167 | /* check uniqueness of the node within its siblings */ |
| 168 | if (!parent) { |
| 169 | break; |
| 170 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 171 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 172 | LY_TREE_FOR(parent->child, node) { |
| 173 | if (node->name == id) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 174 | LOGVAL(LYE_INID, line, id, "name duplication"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 175 | return EXIT_FAILURE; |
| 176 | } |
| 177 | } |
| 178 | break; |
| 179 | case LY_IDENT_TYPE: |
| 180 | assert(module); |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 181 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 182 | /* check collision with the built-in types */ |
| 183 | if (!strcmp(id, "binary") || !strcmp(id, "bits") || |
| 184 | !strcmp(id, "boolean") || !strcmp(id, "decimal64") || |
| 185 | !strcmp(id, "empty") || !strcmp(id, "enumeration") || |
| 186 | !strcmp(id, "identityref") || !strcmp(id, "instance-identifier") || |
| 187 | !strcmp(id, "int8") || !strcmp(id, "int16") || |
| 188 | !strcmp(id, "int32") || !strcmp(id, "int64") || |
| 189 | !strcmp(id, "leafref") || !strcmp(id, "string") || |
| 190 | !strcmp(id, "uint8") || !strcmp(id, "uint16") || |
| 191 | !strcmp(id, "uint32") || !strcmp(id, "uint64") || !strcmp(id, "union")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 192 | LOGVAL(LYE_SPEC, line, "Typedef name duplicates built-in type."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 193 | return EXIT_FAILURE; |
| 194 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 195 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 196 | /* check locally scoped typedefs (avoid name shadowing) */ |
| 197 | for (; parent; parent = parent->parent) { |
| 198 | switch (parent->nodetype) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 199 | case LYS_CONTAINER: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 200 | size = ((struct lys_node_container *)parent)->tpdf_size; |
| 201 | tpdf = ((struct lys_node_container *)parent)->tpdf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 202 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 203 | case LYS_LIST: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 204 | size = ((struct lys_node_list *)parent)->tpdf_size; |
| 205 | tpdf = ((struct lys_node_list *)parent)->tpdf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 206 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 207 | case LYS_GROUPING: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 208 | size = ((struct lys_node_grp *)parent)->tpdf_size; |
| 209 | tpdf = ((struct lys_node_grp *)parent)->tpdf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 210 | break; |
| 211 | default: |
| 212 | continue; |
| 213 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 214 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 215 | if (dup_typedef_check(id, tpdf, size)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 216 | LOGVAL(LYE_DUPID, line, "typedef", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 217 | return EXIT_FAILURE; |
| 218 | } |
| 219 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 220 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 221 | /* check top-level names */ |
| 222 | if (dup_typedef_check(id, module->tpdf, module->tpdf_size)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 223 | LOGVAL(LYE_DUPID, line, "typedef", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 224 | return EXIT_FAILURE; |
| 225 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 226 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 227 | /* check submodule's top-level names */ |
| 228 | for (i = 0; i < module->inc_size; i++) { |
| 229 | if (dup_typedef_check(id, module->inc[i].submodule->tpdf, module->inc[i].submodule->tpdf_size)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 230 | LOGVAL(LYE_DUPID, line, "typedef", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 231 | return EXIT_FAILURE; |
| 232 | } |
| 233 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 234 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 235 | /* check top-level names in the main module */ |
| 236 | if (module->type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 237 | if (dup_typedef_check(id, ((struct lys_submodule *)module)->belongsto->tpdf, |
| 238 | ((struct lys_submodule *)module)->belongsto->tpdf_size)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 239 | LOGVAL(LYE_DUPID, line, "typedef", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 240 | return EXIT_FAILURE; |
| 241 | } |
| 242 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 243 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 244 | break; |
| 245 | case LY_IDENT_PREFIX: |
| 246 | assert(module); |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 247 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 248 | if (module->type) { |
| 249 | /* go to the main module */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 250 | module = ((struct lys_submodule *)module)->belongsto; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 251 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 252 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 253 | /* check the main module itself */ |
| 254 | if (dup_prefix_check(id, module)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 255 | LOGVAL(LYE_DUPID, line, "prefix", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 256 | return EXIT_FAILURE; |
| 257 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 258 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 259 | /* and all its submodules */ |
| 260 | for (i = 0; i < module->inc_size; i++) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 261 | if (dup_prefix_check(id, (struct lys_module *)module->inc[i].submodule)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 262 | LOGVAL(LYE_DUPID, line, "prefix", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 263 | return EXIT_FAILURE; |
| 264 | } |
| 265 | } |
| 266 | break; |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 267 | case LY_IDENT_FEATURE: |
| 268 | assert(module); |
| 269 | |
| 270 | /* check feature name uniqness*/ |
Radek Krejci | 49babf3 | 2015-06-18 13:56:17 +0200 | [diff] [blame] | 271 | /* check features in the current module */ |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 272 | if (dup_feature_check(id, module)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 273 | LOGVAL(LYE_DUPID, line, "feature", id); |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 274 | return EXIT_FAILURE; |
| 275 | } |
| 276 | |
| 277 | /* and all its submodules */ |
| 278 | for (i = 0; i < module->inc_size; i++) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 279 | if (dup_feature_check(id, (struct lys_module *)module->inc[i].submodule)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 280 | LOGVAL(LYE_DUPID, line, "feature", id); |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 281 | return EXIT_FAILURE; |
| 282 | } |
| 283 | } |
| 284 | break; |
| 285 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 286 | default: |
| 287 | /* no check required */ |
| 288 | break; |
| 289 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 290 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 291 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 292 | } |
| 293 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 294 | /* does not log */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 295 | static int |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 296 | check_mandatory(struct lys_node *node) |
Radek Krejci | 3de29a7 | 2015-06-16 15:23:03 +0200 | [diff] [blame] | 297 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 298 | struct lys_node *child; |
Radek Krejci | 3de29a7 | 2015-06-16 15:23:03 +0200 | [diff] [blame] | 299 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 300 | assert(node); |
Radek Krejci | 3de29a7 | 2015-06-16 15:23:03 +0200 | [diff] [blame] | 301 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 302 | if (node->flags & LYS_MAND_TRUE) { |
Radek Krejci | 3de29a7 | 2015-06-16 15:23:03 +0200 | [diff] [blame] | 303 | return EXIT_FAILURE; |
| 304 | } |
| 305 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 306 | if (node->nodetype == LYS_CASE || node->nodetype == LYS_CHOICE) { |
| 307 | LY_TREE_FOR(node->child, child) { |
Radek Krejci | fd0bb0a | 2015-06-18 13:18:24 +0200 | [diff] [blame] | 308 | if (check_mandatory(child)) { |
| 309 | return EXIT_FAILURE; |
| 310 | } |
Radek Krejci | 3de29a7 | 2015-06-16 15:23:03 +0200 | [diff] [blame] | 311 | } |
| 312 | } |
| 313 | |
| 314 | return EXIT_SUCCESS; |
| 315 | } |
| 316 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 317 | /* logs directly */ |
Radek Krejci | 3de29a7 | 2015-06-16 15:23:03 +0200 | [diff] [blame] | 318 | static int |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 319 | check_date(const char *date, unsigned int line) |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 320 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 321 | int i; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 322 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 323 | assert(date); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 324 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 325 | if (strlen(date) != LY_REV_SIZE - 1) { |
| 326 | goto error; |
| 327 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 328 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 329 | for (i = 0; i < LY_REV_SIZE - 1; i++) { |
| 330 | if (i == 4 || i == 7) { |
| 331 | if (date[i] != '-') { |
| 332 | goto error; |
| 333 | } |
| 334 | } else if (!isdigit(date[i])) { |
| 335 | goto error; |
| 336 | } |
| 337 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 338 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 339 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 340 | |
| 341 | error: |
| 342 | |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 343 | LOGVAL(LYE_INDATE, line, date); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 344 | return EXIT_FAILURE; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 345 | } |
| 346 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 347 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 348 | static const char * |
| 349 | 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] | 350 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 351 | int len; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 352 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 353 | /* there should be <text> child */ |
| 354 | if (!node->child || !node->child->name || strcmp(node->child->name, name)) { |
| 355 | LOGWRN("Expected \"%s\" element in \"%s\" element.", name, node->name); |
| 356 | } else if (node->child->content) { |
| 357 | len = strlen(node->child->content); |
| 358 | return lydict_insert(ctx, node->child->content, len); |
| 359 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 360 | |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 361 | LOGVAL(LYE_INARG, LOGLINE(node), name, node->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 362 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 363 | } |
| 364 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 365 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 366 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 367 | 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] | 368 | { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 369 | struct lyxml_elem *node; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 370 | const char *value; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 371 | |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 372 | GETVAL(value, yin, "name"); |
| 373 | ident->name = lydict_insert(module->ctx, value, 0); |
| 374 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 375 | 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] | 376 | return EXIT_FAILURE; |
| 377 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 378 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 379 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 380 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 381 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 382 | continue; |
| 383 | } |
| 384 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 385 | if (!strcmp(node->name, "base")) { |
| 386 | if (ident->base) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 387 | LOGVAL(LYE_TOOMANY, LOGLINE(node), "base", "identity"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 388 | return EXIT_FAILURE; |
| 389 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 390 | GETVAL(value, node, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 391 | if (unres_schema_add_str(module, unres, ident, UNRES_IDENT, value, LOGLINE(node)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 392 | return EXIT_FAILURE; |
| 393 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 394 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 395 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name, "identity"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 396 | return EXIT_FAILURE; |
| 397 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 398 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 399 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 400 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 401 | return EXIT_SUCCESS; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 402 | } |
| 403 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 404 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 405 | static int |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 406 | 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] | 407 | { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 408 | struct lyxml_elem *child; |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 409 | const char *value; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 410 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 411 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 412 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 413 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 414 | continue; |
| 415 | } |
| 416 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 417 | if (!strcmp(child->name, "description")) { |
| 418 | if (restr->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 419 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 420 | return EXIT_FAILURE; |
| 421 | } |
| 422 | restr->dsc = read_yin_subnode(ctx, child, "text"); |
| 423 | if (!restr->dsc) { |
| 424 | return EXIT_FAILURE; |
| 425 | } |
| 426 | } else if (!strcmp(child->name, "reference")) { |
| 427 | if (restr->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 428 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 429 | return EXIT_FAILURE; |
| 430 | } |
| 431 | restr->ref = read_yin_subnode(ctx, child, "text"); |
| 432 | if (!restr->ref) { |
| 433 | return EXIT_FAILURE; |
| 434 | } |
| 435 | } else if (!strcmp(child->name, "error-app-tag")) { |
| 436 | if (restr->eapptag) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 437 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 438 | return EXIT_FAILURE; |
| 439 | } |
Michal Vasko | 54e426f | 2015-07-07 15:38:02 +0200 | [diff] [blame] | 440 | GETVAL(value, child, "value"); |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 441 | restr->eapptag = lydict_insert(ctx, value, 0); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 442 | } else if (!strcmp(child->name, "error-message")) { |
| 443 | if (restr->emsg) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 444 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 445 | return EXIT_FAILURE; |
| 446 | } |
| 447 | restr->emsg = read_yin_subnode(ctx, child, "value"); |
| 448 | if (!restr->emsg) { |
| 449 | return EXIT_FAILURE; |
| 450 | } |
| 451 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 452 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 453 | return EXIT_FAILURE; |
| 454 | } |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | return EXIT_SUCCESS; |
Michal Vasko | c8ef47f | 2015-06-29 14:56:19 +0200 | [diff] [blame] | 458 | |
| 459 | error: |
| 460 | return EXIT_FAILURE; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 461 | } |
| 462 | |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 463 | /* logs directly */ |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 464 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 465 | 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] | 466 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 467 | { |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 468 | #define REGEX_ERR_LEN 128 |
Michal Vasko | 0fb82c6 | 2015-10-20 13:41:53 +0200 | [diff] [blame] | 469 | const char *value, *name, *err_ptr; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 470 | struct lyxml_elem *next, *node; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 471 | struct lys_restr **restr; |
| 472 | struct lys_type_bit bit; |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 473 | pcre *precomp; |
| 474 | int i, j, rc, err_offset; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 475 | int64_t v, v_; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 476 | int64_t p, p_; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 477 | |
Radek Krejci | 8de7b0f | 2015-07-02 11:43:42 +0200 | [diff] [blame] | 478 | GETVAL(value, yin, "name"); |
Michal Vasko | 0fb82c6 | 2015-10-20 13:41:53 +0200 | [diff] [blame] | 479 | value = transform_expr_xml2json(module->ctx, value, yin, 1); |
| 480 | if (!value) { |
| 481 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 482 | } |
Michal Vasko | 0fb82c6 | 2015-10-20 13:41:53 +0200 | [diff] [blame] | 483 | type->module_name = value; |
Radek Krejci | 667b97f | 2015-05-25 15:03:30 +0200 | [diff] [blame] | 484 | |
Michal Vasko | 0fb82c6 | 2015-10-20 13:41:53 +0200 | [diff] [blame] | 485 | rc = resolve_superior_type(value, type->module_name, module, parent, &type->der); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 486 | if (rc == -1) { |
Michal Vasko | 0fb82c6 | 2015-10-20 13:41:53 +0200 | [diff] [blame] | 487 | LOGVAL(LYE_INMOD, LOGLINE(yin), type->module_name); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 488 | goto error; |
| 489 | } else if (rc == EXIT_FAILURE) { |
| 490 | /* HACK for unres */ |
| 491 | type->der = (struct lys_tpdf *)parent; |
| 492 | rc = unres_schema_add_str(module, unres, type, UNRES_TYPE_DER, value, LOGLINE(yin)); |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 493 | if (rc == -1) { |
| 494 | goto error; |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 495 | } else { |
| 496 | return EXIT_SUCCESS; |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 497 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 498 | } |
| 499 | type->base = type->der->type.base; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 500 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 501 | switch (type->base) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 502 | case LY_TYPE_BITS: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 503 | /* RFC 6020 9.7.4 - bit */ |
| 504 | |
| 505 | /* get bit specifications, at least one must be present */ |
| 506 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 507 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 508 | /* garbage */ |
| 509 | lyxml_free_elem(module->ctx, node); |
| 510 | continue; |
| 511 | } |
| 512 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 513 | if (!strcmp(node->name, "bit")) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 514 | type->info.bits.count++; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 515 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 516 | LOGVAL(LYE_INSTMT, LOGLINE(yin->child), yin->child->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 517 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 518 | } |
| 519 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 520 | if (!type->der->type.der && !type->info.bits.count) { |
| 521 | /* type is derived directly from buit-in bits type and bit statement is required */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 522 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "bit", "type"); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 523 | goto error; |
| 524 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 525 | if (type->der->type.der && type->info.bits.count) { |
| 526 | /* type is not directly derived from buit-in bits type and bit statement is prohibited */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 527 | LOGVAL(LYE_INSTMT, LOGLINE(yin), "bit"); |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 528 | goto error; |
| 529 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 530 | |
| 531 | type->info.bits.bit = calloc(type->info.bits.count, sizeof *type->info.bits.bit); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 532 | p = 0; |
| 533 | i = -1; |
| 534 | LY_TREE_FOR(yin->child, next) { |
| 535 | i++; |
| 536 | |
| 537 | GETVAL(value, next, "name"); |
| 538 | if (check_identifier(value, LY_IDENT_SIMPLE, LOGLINE(next), NULL, NULL)) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 539 | goto error; |
| 540 | } |
| 541 | 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] | 542 | 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] | 543 | type->info.bits.count = i + 1; |
| 544 | goto error; |
| 545 | } |
| 546 | |
| 547 | /* check the name uniqueness */ |
| 548 | for (j = 0; j < i; j++) { |
| 549 | if (!strcmp(type->info.bits.bit[j].name, type->info.bits.bit[i].name)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 550 | LOGVAL(LYE_BITS_DUPNAME, LOGLINE(next), type->info.bits.bit[i].name); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 551 | type->info.bits.count = i + 1; |
| 552 | goto error; |
| 553 | } |
| 554 | } |
| 555 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 556 | p_ = -1; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 557 | LY_TREE_FOR(next->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 558 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 559 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 560 | continue; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 561 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 562 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 563 | if (!strcmp(node->name, "position")) { |
| 564 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 565 | p_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 566 | |
| 567 | /* range check */ |
Radek Krejci | b8ca108 | 2015-07-10 11:24:11 +0200 | [diff] [blame] | 568 | if (p_ < 0 || p_ > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 569 | LOGVAL(LYE_INARG, LOGLINE(node), value, "bit/position"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 570 | type->info.bits.count = i + 1; |
| 571 | goto error; |
| 572 | } |
| 573 | type->info.bits.bit[i].pos = (uint32_t)p_; |
| 574 | |
| 575 | /* keep the highest enum value for automatic increment */ |
Michal Vasko | 9ab0594 | 2015-07-07 15:38:26 +0200 | [diff] [blame] | 576 | if (type->info.bits.bit[i].pos >= p) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 577 | p = type->info.bits.bit[i].pos; |
| 578 | p++; |
| 579 | } else { |
| 580 | /* check that the value is unique */ |
| 581 | for (j = 0; j < i; j++) { |
| 582 | if (type->info.bits.bit[j].pos == type->info.bits.bit[i].pos) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 583 | LOGVAL(LYE_BITS_DUPVAL, LOGLINE(node), type->info.bits.bit[i].pos, type->info.bits.bit[i].name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 584 | type->info.bits.count = i + 1; |
| 585 | goto error; |
| 586 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 587 | } |
| 588 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 589 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 590 | LOGVAL(LYE_INSTMT, LOGLINE(next), next->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 591 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 592 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 593 | } |
| 594 | if (p_ == -1) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 595 | /* assign value automatically */ |
| 596 | if (p > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 597 | LOGVAL(LYE_INARG, LOGLINE(next), "4294967295", "bit/position"); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 598 | type->info.bits.count = i + 1; |
| 599 | goto error; |
| 600 | } |
| 601 | type->info.bits.bit[i].pos = (uint32_t)p; |
| 602 | p++; |
| 603 | } |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 604 | |
| 605 | /* keep them ordered by position */ |
| 606 | j = i; |
| 607 | while (j && type->info.bits.bit[j - 1].pos > type->info.bits.bit[j].pos) { |
| 608 | /* switch them */ |
| 609 | memcpy(&bit, &type->info.bits.bit[j], sizeof bit); |
| 610 | memcpy(&type->info.bits.bit[j], &type->info.bits.bit[j - 1], sizeof bit); |
| 611 | memcpy(&type->info.bits.bit[j - 1], &bit, sizeof bit); |
| 612 | j--; |
| 613 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 614 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 615 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 616 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 617 | case LY_TYPE_DEC64: |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 618 | /* RFC 6020 9.2.4 - range and 9.3.4 - fraction-digits */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 619 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 620 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 621 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 622 | continue; |
| 623 | } |
| 624 | |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 625 | if (!strcmp(node->name, "range")) { |
| 626 | if (type->info.dec64.range) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 627 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 628 | goto error; |
| 629 | } |
| 630 | |
| 631 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 632 | if (lyp_check_length_range(value, type)) { |
Michal Vasko | 9c1bc64 | 2015-08-05 16:25:53 +0200 | [diff] [blame] | 633 | LOGVAL(LYE_INARG, LOGLINE(node), value, "range"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 634 | goto error; |
| 635 | } |
| 636 | type->info.dec64.range = calloc(1, sizeof *type->info.dec64.range); |
| 637 | type->info.dec64.range->expr = lydict_insert(module->ctx, value, 0); |
| 638 | |
| 639 | /* get possible substatements */ |
| 640 | if (read_restr_substmt(module->ctx, type->info.dec64.range, node)) { |
| 641 | goto error; |
| 642 | } |
| 643 | } else if (!strcmp(node->name, "fraction-digits")) { |
| 644 | if (type->info.dec64.dig) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 645 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 646 | goto error; |
| 647 | } |
| 648 | GETVAL(value, node, "value"); |
| 649 | v = strtol(value, NULL, 10); |
| 650 | |
| 651 | /* range check */ |
| 652 | if (v < 1 || v > 18) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 653 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 654 | goto error; |
| 655 | } |
| 656 | type->info.dec64.dig = (uint8_t)v; |
| 657 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 658 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 659 | goto error; |
| 660 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | /* mandatory sub-statement(s) check */ |
| 664 | if (!type->info.dec64.dig && !type->der->type.der) { |
| 665 | /* decimal64 type directly derived from built-in type requires fraction-digits */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 666 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "fraction-digits", "type"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 667 | goto error; |
| 668 | } |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 669 | if (type->info.dec64.dig && type->der->type.der) { |
| 670 | /* type is not directly derived from buit-in type and fraction-digits statement is prohibited */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 671 | LOGVAL(LYE_INSTMT, LOGLINE(yin), "fraction-digits"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 672 | goto error; |
| 673 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 674 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 675 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 676 | case LY_TYPE_ENUM: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 677 | /* RFC 6020 9.6 - enum */ |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 678 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 679 | /* get enum specifications, at least one must be present */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 680 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 681 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 682 | /* garbage */ |
| 683 | lyxml_free_elem(module->ctx, node); |
| 684 | continue; |
| 685 | } |
| 686 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 687 | if (!strcmp(node->name, "enum")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 688 | type->info.enums.count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 689 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 690 | LOGVAL(LYE_INSTMT, LOGLINE(yin->child), yin->child->name); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 691 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 692 | } |
| 693 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 694 | if (!type->der->type.der && !type->info.enums.count) { |
| 695 | /* type is derived directly from buit-in enumeartion type and enum statement is required */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 696 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "enum", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 697 | goto error; |
| 698 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 699 | if (type->der->type.der && type->info.enums.count) { |
| 700 | /* type is not directly derived from buit-in enumeration type and enum statement is prohibited */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 701 | LOGVAL(LYE_INSTMT, LOGLINE(yin), "enum"); |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 702 | goto error; |
| 703 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 704 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 705 | type->info.enums.enm = calloc(type->info.enums.count, sizeof *type->info.enums.enm); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 706 | v = 0; |
| 707 | i = -1; |
| 708 | LY_TREE_FOR(yin->child, next) { |
| 709 | i++; |
| 710 | |
| 711 | GETVAL(value, next, "name"); |
| 712 | if (check_identifier(value, LY_IDENT_SIMPLE, LOGLINE(next), NULL, NULL)) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 713 | goto error; |
| 714 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 715 | 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] | 716 | 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] | 717 | type->info.enums.count = i + 1; |
| 718 | goto error; |
| 719 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 720 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 721 | /* the assigned name MUST NOT have any leading or trailing whitespace characters */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 722 | value = type->info.enums.enm[i].name; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 723 | if (isspace(value[0]) || isspace(value[strlen(value) - 1])) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 724 | LOGVAL(LYE_ENUM_WS, LOGLINE(next), value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 725 | type->info.enums.count = i + 1; |
| 726 | goto error; |
| 727 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 728 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 729 | /* check the name uniqueness */ |
| 730 | for (j = 0; j < i; j++) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 731 | if (!strcmp(type->info.enums.enm[j].name, type->info.enums.enm[i].name)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 732 | LOGVAL(LYE_ENUM_DUPNAME, LOGLINE(next), type->info.enums.enm[i].name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 733 | type->info.enums.count = i + 1; |
| 734 | goto error; |
| 735 | } |
| 736 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 737 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 738 | v_ = -1; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 739 | LY_TREE_FOR(next->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 740 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 741 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 742 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 743 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 744 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 745 | if (!strcmp(node->name, "value")) { |
| 746 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 747 | v_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 748 | |
| 749 | /* range check */ |
| 750 | if (v_ < INT32_MIN || v_ > INT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 751 | LOGVAL(LYE_INARG, LOGLINE(node), value, "enum/value"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 752 | type->info.enums.count = i + 1; |
| 753 | goto error; |
| 754 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 755 | type->info.enums.enm[i].value = v_; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 756 | |
| 757 | /* keep the highest enum value for automatic increment */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 758 | if (type->info.enums.enm[i].value > v) { |
| 759 | v = type->info.enums.enm[i].value; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 760 | v++; |
| 761 | } else { |
| 762 | /* check that the value is unique */ |
| 763 | for (j = 0; j < i; j++) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 764 | if (type->info.enums.enm[j].value == type->info.enums.enm[i].value) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 765 | LOGVAL(LYE_ENUM_DUPVAL, LOGLINE(node), type->info.enums.enm[i].value, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 766 | type->info.enums.enm[i].name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 767 | type->info.enums.count = i + 1; |
| 768 | goto error; |
| 769 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 770 | } |
| 771 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 772 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 773 | LOGVAL(LYE_INSTMT, LOGLINE(next), next->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 774 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 775 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 776 | } |
| 777 | if (v_ == -1) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 778 | /* assign value automatically */ |
| 779 | if (v > INT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 780 | LOGVAL(LYE_INARG, LOGLINE(next), "2147483648", "enum/value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 781 | type->info.enums.count = i + 1; |
| 782 | goto error; |
| 783 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 784 | type->info.enums.enm[i].value = v; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 785 | v++; |
| 786 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 787 | } |
| 788 | break; |
| 789 | |
| 790 | case LY_TYPE_IDENT: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 791 | /* RFC 6020 9.10 - base */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 792 | |
| 793 | /* get base specification, exactly one must be present */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 794 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 795 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 796 | /* garbage */ |
| 797 | lyxml_free_elem(module->ctx, node); |
| 798 | continue; |
| 799 | } |
| 800 | |
| 801 | if (strcmp(yin->child->name, "base")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 802 | LOGVAL(LYE_INSTMT, LOGLINE(yin->child), yin->child->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 803 | goto error; |
| 804 | } |
| 805 | } |
| 806 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 807 | if (!yin->child) { |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 808 | if (type->der->type.der) { |
| 809 | /* this is just a derived type with no base specified/required */ |
| 810 | break; |
| 811 | } |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 812 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "base", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 813 | goto error; |
| 814 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 815 | if (yin->child->next) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 816 | LOGVAL(LYE_TOOMANY, LOGLINE(yin->child->next), yin->child->next->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 817 | goto error; |
| 818 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 819 | GETVAL(value, yin->child, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 820 | if (unres_schema_add_str(module, unres, type, UNRES_TYPE_IDENTREF, value, LOGLINE(yin->child)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 821 | goto error; |
| 822 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 823 | break; |
| 824 | |
| 825 | case LY_TYPE_INST: |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 826 | /* RFC 6020 9.13.2 - require-instance */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 827 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 828 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 829 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 830 | continue; |
| 831 | } |
| 832 | |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 833 | if (!strcmp(node->name, "require-instance")) { |
| 834 | if (type->info.inst.req) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 835 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 836 | goto error; |
| 837 | } |
| 838 | GETVAL(value, node, "value"); |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 839 | if (!strcmp(value, "true")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 840 | type->info.inst.req = 1; |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 841 | } else if (!strcmp(value, "false")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 842 | type->info.inst.req = -1; |
| 843 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 844 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 845 | goto error; |
| 846 | } |
| 847 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 848 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 849 | goto error; |
| 850 | } |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 851 | } |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 852 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 853 | break; |
| 854 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 855 | case LY_TYPE_BINARY: |
| 856 | /* 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] | 857 | case LY_TYPE_INT8: |
| 858 | case LY_TYPE_INT16: |
| 859 | case LY_TYPE_INT32: |
| 860 | case LY_TYPE_INT64: |
| 861 | case LY_TYPE_UINT8: |
| 862 | case LY_TYPE_UINT16: |
| 863 | case LY_TYPE_UINT32: |
| 864 | case LY_TYPE_UINT64: |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 865 | /* RFC 6020 9.2.4 - range */ |
| 866 | |
| 867 | /* length and range are actually the same restriction, so process |
| 868 | * them by this common code, we just need to differ the name and |
| 869 | * structure where the information will be stored |
| 870 | */ |
| 871 | if (type->base == LY_TYPE_BINARY) { |
| 872 | restr = &type->info.binary.length; |
| 873 | name = "length"; |
| 874 | } else { |
| 875 | restr = &type->info.num.range; |
| 876 | name = "range"; |
| 877 | } |
| 878 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 879 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 880 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 881 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 882 | continue; |
| 883 | } |
| 884 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 885 | if (!strcmp(node->name, name)) { |
| 886 | if (*restr) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 887 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 888 | goto error; |
| 889 | } |
| 890 | |
| 891 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 892 | if (lyp_check_length_range(value, type)) { |
Michal Vasko | 9c1bc64 | 2015-08-05 16:25:53 +0200 | [diff] [blame] | 893 | LOGVAL(LYE_INARG, LOGLINE(node), value, name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 894 | goto error; |
| 895 | } |
| 896 | *restr = calloc(1, sizeof **restr); |
| 897 | (*restr)->expr = lydict_insert(module->ctx, value, 0); |
| 898 | |
| 899 | /* get possible substatements */ |
| 900 | if (read_restr_substmt(module->ctx, *restr, node)) { |
| 901 | goto error; |
| 902 | } |
| 903 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 904 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 905 | goto error; |
| 906 | } |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 907 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 908 | break; |
| 909 | |
| 910 | case LY_TYPE_LEAFREF: |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 911 | /* RFC 6020 9.9.2 - path */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 912 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 913 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 914 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 915 | continue; |
| 916 | } |
| 917 | |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 918 | if (!strcmp(node->name, "path")) { |
| 919 | if (type->info.lref.path) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 920 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 921 | goto error; |
| 922 | } |
| 923 | |
| 924 | GETVAL(value, node, "value"); |
Michal Vasko | 0fb82c6 | 2015-10-20 13:41:53 +0200 | [diff] [blame] | 925 | /* store in the JSON format */ |
| 926 | type->info.lref.path = transform_expr_xml2json(module->ctx, value, node, 1); |
| 927 | if (!type->info.lref.path) { |
| 928 | goto error; |
| 929 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 930 | if (unres_schema_add_node(module, unres, type, UNRES_TYPE_LEAFREF, parent, LOGLINE(yin)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 931 | goto error; |
| 932 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 933 | |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 934 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 935 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 936 | goto error; |
| 937 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | if (!type->info.lref.path) { |
| 941 | if (type->der->type.der) { |
| 942 | /* this is just a derived type with no path specified/required */ |
| 943 | break; |
| 944 | } |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 945 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "path", "type"); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 946 | goto error; |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 947 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 948 | break; |
| 949 | |
| 950 | case LY_TYPE_STRING: |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 951 | /* RFC 6020 9.4.4 - length */ |
| 952 | /* RFC 6020 9.4.6 - pattern */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 953 | i = 0; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 954 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 955 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 956 | /* garbage */ |
| 957 | lyxml_free_elem(module->ctx, node); |
| 958 | continue; |
| 959 | } |
| 960 | |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 961 | if (!strcmp(node->name, "length")) { |
| 962 | if (type->info.str.length) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 963 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 964 | goto error; |
| 965 | } |
| 966 | |
| 967 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 968 | if (lyp_check_length_range(value, type)) { |
Michal Vasko | 9c1bc64 | 2015-08-05 16:25:53 +0200 | [diff] [blame] | 969 | LOGVAL(LYE_INARG, LOGLINE(node), value, "length"); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 970 | goto error; |
| 971 | } |
| 972 | type->info.str.length = calloc(1, sizeof *type->info.str.length); |
| 973 | type->info.str.length->expr = lydict_insert(module->ctx, value, 0); |
| 974 | |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 975 | /* get possible sub-statements */ |
| 976 | if (read_restr_substmt(module->ctx, type->info.str.length, node)) { |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 977 | goto error; |
| 978 | } |
Radek Krejci | 82d971d | 2015-06-19 14:20:50 +0200 | [diff] [blame] | 979 | lyxml_free_elem(module->ctx, node); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 980 | } else if (!strcmp(node->name, "pattern")) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 981 | i++; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 982 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 983 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 984 | goto error; |
| 985 | } |
| 986 | } |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 987 | /* store patterns in array */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 988 | if (i) { |
| 989 | type->info.str.patterns = calloc(i, sizeof *type->info.str.patterns); |
| 990 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 991 | GETVAL(value, yin->child, "value"); |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 992 | |
| 993 | /* check that the regex is valid */ |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 994 | precomp = pcre_compile(value, PCRE_NO_AUTO_CAPTURE, &err_ptr, &err_offset, NULL); |
| 995 | if (!precomp) { |
| 996 | LOGVAL(LYE_INREGEX, LOGLINE(node), value, err_ptr); |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 997 | free(type->info.str.patterns); |
| 998 | goto error; |
| 999 | } |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 1000 | free(precomp); |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1001 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1002 | 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] | 1003 | |
| 1004 | /* get possible sub-statements */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1005 | if (read_restr_substmt(module->ctx, &type->info.str.patterns[type->info.str.pat_count], yin->child)) { |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1006 | free(type->info.str.patterns); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1007 | goto error; |
| 1008 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1009 | type->info.str.pat_count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1010 | } |
| 1011 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1012 | break; |
| 1013 | |
| 1014 | case LY_TYPE_UNION: |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1015 | /* RFC 6020 7.4 - type */ |
| 1016 | /* count number of types in union */ |
| 1017 | i = 0; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1018 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 1019 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 1020 | /* garbage */ |
| 1021 | lyxml_free_elem(module->ctx, node); |
| 1022 | continue; |
| 1023 | } |
| 1024 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1025 | if (!strcmp(node->name, "type")) { |
| 1026 | i++; |
| 1027 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1028 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1029 | goto error; |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | if (!i) { |
| 1034 | if (type->der->type.der) { |
| 1035 | /* this is just a derived type with no base specified/required */ |
| 1036 | break; |
| 1037 | } |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1038 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", "(union) type"); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1039 | goto error; |
| 1040 | } |
| 1041 | |
| 1042 | /* allocate array for union's types ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1043 | type->info.uni.types = calloc(i, sizeof *type->info.uni.types); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1044 | /* ... and fill the structures */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1045 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1046 | if (fill_yin_type(module, parent, node, &type->info.uni.types[type->info.uni.count], unres)) { |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1047 | goto error; |
| 1048 | } |
| 1049 | type->info.uni.count++; |
| 1050 | |
| 1051 | /* union's type cannot be empty or leafref */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1052 | if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_EMPTY) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1053 | LOGVAL(LYE_INARG, LOGLINE(node), "empty", node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1054 | goto error; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1055 | } else if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_LEAFREF) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1056 | LOGVAL(LYE_INARG, LOGLINE(node), "leafref", node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1057 | goto error; |
| 1058 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1059 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1060 | break; |
| 1061 | |
| 1062 | default: |
Radek Krejci | 6e328cd | 2015-06-26 16:24:11 +0200 | [diff] [blame] | 1063 | /* no sub-statement allowed in: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1064 | * LY_TYPE_BOOL, LY_TYPE_EMPTY |
| 1065 | */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1066 | LY_TREE_FOR(yin->child, node) { |
| 1067 | if (node->ns && !strcmp(node->ns->value, LY_NSYIN)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1068 | LOGVAL(LYE_INSTMT, LOGLINE(yin->child), yin->child->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1069 | goto error; |
| 1070 | } |
Radek Krejci | 6e328cd | 2015-06-26 16:24:11 +0200 | [diff] [blame] | 1071 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1072 | break; |
| 1073 | } |
| 1074 | |
| 1075 | return EXIT_SUCCESS; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 1076 | |
| 1077 | error: |
| 1078 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1079 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1080 | } |
| 1081 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1082 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1083 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 1084 | 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] | 1085 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1086 | const char *value; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1087 | struct lyxml_elem *node; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1088 | int has_type = 0, dflt_line; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1089 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1090 | GETVAL(value, yin, "name"); |
| 1091 | if (check_identifier(value, LY_IDENT_TYPE, LOGLINE(yin), module, parent)) { |
| 1092 | goto error; |
| 1093 | } |
| 1094 | tpdf->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1095 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1096 | /* generic part - status, description, reference */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1097 | if (read_yin_common(module, NULL, (struct lys_node *)tpdf, yin, OPT_IDENT | OPT_MODULE)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1098 | goto error; |
| 1099 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1100 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1101 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1102 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 1103 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1104 | continue; |
| 1105 | } |
| 1106 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1107 | if (!strcmp(node->name, "type")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1108 | if (tpdf->type.der || has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1109 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1110 | goto error; |
| 1111 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1112 | if (fill_yin_type(module, parent, node, &tpdf->type, unres)) { |
| 1113 | goto error; |
| 1114 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1115 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1116 | } else if (!strcmp(node->name, "default")) { |
| 1117 | if (tpdf->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1118 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1119 | goto error; |
| 1120 | } |
| 1121 | GETVAL(value, node, "value"); |
| 1122 | tpdf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1123 | dflt_line = LOGLINE(node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1124 | } else if (!strcmp(node->name, "units")) { |
| 1125 | if (tpdf->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1126 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1127 | goto error; |
| 1128 | } |
| 1129 | GETVAL(value, node, "name"); |
| 1130 | tpdf->units = lydict_insert(module->ctx, value, strlen(value)); |
| 1131 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1132 | LOGVAL(LYE_INSTMT, LOGLINE(node), value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1133 | goto error; |
| 1134 | } |
| 1135 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 1136 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1137 | /* check mandatory value */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1138 | if (!has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1139 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1140 | goto error; |
| 1141 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1142 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1143 | /* check default value */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1144 | if (tpdf->dflt) { |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 1145 | if (unres_schema_add_str(module, unres, &tpdf->type, UNRES_TYPE_DFLT, tpdf->dflt, dflt_line) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1146 | goto error; |
| 1147 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1148 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1149 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1150 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1151 | |
| 1152 | error: |
| 1153 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1154 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1155 | } |
| 1156 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1157 | /* logs directly */ |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1158 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 1159 | 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] | 1160 | { |
| 1161 | const char *value; |
| 1162 | struct lyxml_elem *child, *next; |
| 1163 | int c = 0; |
| 1164 | |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1165 | GETVAL(value, yin, "name"); |
| 1166 | if (check_identifier(value, LY_IDENT_FEATURE, LOGLINE(yin), module, NULL)) { |
| 1167 | goto error; |
| 1168 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1169 | f->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 1170 | f->module = module; |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1171 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1172 | if (read_yin_common(module, NULL, (struct lys_node *)f, yin, 0)) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1173 | goto error; |
| 1174 | } |
| 1175 | |
| 1176 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1177 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1178 | /* garbage */ |
| 1179 | lyxml_free_elem(module->ctx, child); |
| 1180 | continue; |
| 1181 | } |
| 1182 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1183 | if (!strcmp(child->name, "if-feature")) { |
| 1184 | c++; |
| 1185 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1186 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1187 | goto error; |
| 1188 | } |
| 1189 | } |
| 1190 | |
| 1191 | if (c) { |
| 1192 | f->features = calloc(c, sizeof *f->features); |
| 1193 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1194 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1195 | GETVAL(value, child, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 1196 | if (unres_schema_add_str(module, unres, &f->features[f->features_size++], UNRES_IFFEAT, value, LOGLINE(child)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1197 | goto error; |
| 1198 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1199 | } |
| 1200 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1201 | return EXIT_SUCCESS; |
| 1202 | |
| 1203 | error: |
| 1204 | |
| 1205 | return EXIT_FAILURE; |
| 1206 | } |
| 1207 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1208 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1209 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1210 | 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] | 1211 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1212 | const char *value; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1213 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1214 | GETVAL(value, yin, "condition"); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 1215 | must->expr = transform_expr_xml2json(module->ctx, value, yin, 1); |
| 1216 | if (!must->expr) { |
| 1217 | goto error; |
| 1218 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1219 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 1220 | return read_restr_substmt(module->ctx, must, yin); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1221 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 1222 | error: /* GETVAL requires this label */ |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1223 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1224 | return EXIT_FAILURE; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1225 | } |
| 1226 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1227 | /* logs directly |
| 1228 | * |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1229 | * type: 0 - min, 1 - max |
| 1230 | */ |
| 1231 | static int |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1232 | 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] | 1233 | { |
| 1234 | const char *value; |
| 1235 | char *endptr; |
| 1236 | unsigned long val; |
| 1237 | uint32_t *ui32val; |
| 1238 | |
| 1239 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1240 | if (target->nodetype == LYS_LEAFLIST) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1241 | if (type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1242 | ui32val = &((struct lys_node_leaflist *)target)->max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1243 | } else { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1244 | ui32val = &((struct lys_node_leaflist *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1245 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1246 | } else if (target->nodetype == LYS_LIST) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1247 | if (type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1248 | ui32val = &((struct lys_node_list *)target)->max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1249 | } else { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1250 | ui32val = &((struct lys_node_list *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1251 | } |
| 1252 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1253 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
| 1254 | LOGVAL(LYE_SPEC, 0, "Target node does not allow \"%s\" property.", node->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1255 | goto error; |
| 1256 | } |
| 1257 | |
| 1258 | GETVAL(value, node, "value"); |
| 1259 | while (isspace(value[0])) { |
| 1260 | value++; |
| 1261 | } |
| 1262 | |
| 1263 | /* convert it to uint32_t */ |
| 1264 | errno = 0; |
| 1265 | endptr = NULL; |
| 1266 | val = strtoul(value, &endptr, 10); |
| 1267 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1268 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1269 | goto error; |
| 1270 | } |
| 1271 | if (type) { |
| 1272 | d->max = (uint32_t)val; |
| 1273 | } else { |
| 1274 | d->min = (uint32_t)val; |
| 1275 | } |
| 1276 | |
| 1277 | if (d->mod == LY_DEVIATE_ADD) { |
| 1278 | /* check that there is no current value */ |
| 1279 | if (*ui32val) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1280 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
| 1281 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1282 | goto error; |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | if (d->mod == LY_DEVIATE_DEL) { |
| 1287 | /* check values */ |
| 1288 | if ((uint32_t)val != *ui32val) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1289 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
| 1290 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1291 | goto error; |
| 1292 | } |
| 1293 | /* remove current min-elements value of the target */ |
| 1294 | *ui32val = 0; |
| 1295 | } else { /* add (already checked) and replace */ |
| 1296 | /* set new value specified in deviation */ |
| 1297 | *ui32val = (uint32_t)val; |
| 1298 | } |
| 1299 | |
| 1300 | return EXIT_SUCCESS; |
| 1301 | |
| 1302 | error: |
| 1303 | |
| 1304 | return EXIT_FAILURE; |
| 1305 | } |
| 1306 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1307 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1308 | static int |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1309 | fill_yin_deviation(struct lys_module *module, struct lyxml_elem *yin, struct lys_deviation *dev) |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1310 | { |
| 1311 | const char *value, **stritem; |
| 1312 | struct lyxml_elem *next, *child, *develem; |
| 1313 | int c_dev = 0, c_must, c_uniq; |
| 1314 | int f_min = 0; /* flags */ |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1315 | int i, j, rc; |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1316 | struct lys_deviate *d = NULL; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1317 | struct lys_node *node = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1318 | struct lys_node_choice *choice = NULL; |
| 1319 | struct lys_node_leaf *leaf = NULL; |
| 1320 | struct lys_node_list *list = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1321 | struct lys_type *t = NULL; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1322 | uint8_t *trg_must_size = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1323 | struct lys_restr **trg_must = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1324 | |
| 1325 | GETVAL(value, yin, "target-node"); |
| 1326 | dev->target_name = lydict_insert(module->ctx, value, 0); |
| 1327 | |
| 1328 | /* resolve target node */ |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1329 | rc = resolve_schema_nodeid(dev->target_name, NULL, module, LYS_AUGMENT, &dev->target); |
| 1330 | if (rc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1331 | LOGVAL(LYE_INARG, LOGLINE(yin), dev->target_name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1332 | goto error; |
| 1333 | } |
| 1334 | if (dev->target->module == module) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1335 | LOGVAL(LYE_SPEC, LOGLINE(yin), "Deviating own module is not allowed."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1336 | goto error; |
| 1337 | } |
| 1338 | /* mark the target module as deviated */ |
| 1339 | dev->target->module->deviated = 1; |
| 1340 | |
| 1341 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1342 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1343 | /* garbage */ |
| 1344 | lyxml_free_elem(module->ctx, child); |
| 1345 | continue; |
| 1346 | } |
| 1347 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1348 | if (!strcmp(child->name, "description")) { |
| 1349 | if (dev->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1350 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1351 | goto error; |
| 1352 | } |
| 1353 | dev->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 1354 | if (!dev->dsc) { |
| 1355 | goto error; |
| 1356 | } |
| 1357 | } else if (!strcmp(child->name, "reference")) { |
| 1358 | if (dev->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1359 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1360 | goto error; |
| 1361 | } |
| 1362 | dev->ref = read_yin_subnode(module->ctx, child, "text"); |
| 1363 | if (!dev->ref) { |
| 1364 | goto error; |
| 1365 | } |
| 1366 | } else if (!strcmp(child->name, "deviate")) { |
| 1367 | c_dev++; |
| 1368 | |
| 1369 | /* skip lyxml_free_elem() at the end of the loop, node will be |
| 1370 | * further processed later |
| 1371 | */ |
| 1372 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 1373 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1374 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1375 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1376 | goto error; |
| 1377 | } |
| 1378 | |
| 1379 | lyxml_free_elem(module->ctx, child); |
| 1380 | } |
| 1381 | |
| 1382 | if (c_dev) { |
| 1383 | dev->deviate = calloc(c_dev, sizeof *dev->deviate); |
| 1384 | } |
| 1385 | |
| 1386 | LY_TREE_FOR(yin->child, develem) { |
| 1387 | /* init */ |
| 1388 | f_min = 0; |
| 1389 | c_must = 0; |
| 1390 | c_uniq = 0; |
| 1391 | |
| 1392 | /* get deviation type */ |
| 1393 | GETVAL(value, develem, "value"); |
| 1394 | if (!strcmp(value, "not-supported")) { |
| 1395 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_NO; |
| 1396 | /* no property expected in this case */ |
| 1397 | if (develem->child) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1398 | LOGVAL(LYE_INSTMT, LOGLINE(develem->child), develem->child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1399 | goto error; |
| 1400 | } |
| 1401 | |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1402 | /* and neither any other deviate statement is expected, |
| 1403 | * not-supported deviation must be the only deviation of the target |
| 1404 | */ |
| 1405 | if (dev->deviate_size || develem->next) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1406 | LOGVAL(LYE_INARG, LOGLINE(develem), value, develem->name); |
| 1407 | LOGVAL(LYE_SPEC, 0, "\"not-supported\" deviation cannot be combined with any other deviation."); |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1408 | goto error; |
| 1409 | } |
| 1410 | |
| 1411 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1412 | /* remove target node */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1413 | lys_node_free(dev->target); |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1414 | dev->target = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1415 | |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1416 | dev->deviate_size = 1; |
| 1417 | return EXIT_SUCCESS; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1418 | } else if (!strcmp(value, "add")) { |
| 1419 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_ADD; |
| 1420 | } else if (!strcmp(value, "replace")) { |
| 1421 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_RPL; |
| 1422 | } else if (!strcmp(value, "delete")) { |
| 1423 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_DEL; |
| 1424 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1425 | LOGVAL(LYE_INARG, LOGLINE(develem), value, develem->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1426 | goto error; |
| 1427 | } |
| 1428 | d = &dev->deviate[dev->deviate_size]; |
| 1429 | |
| 1430 | /* process deviation properties */ |
| 1431 | LY_TREE_FOR_SAFE(develem->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1432 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1433 | /* garbage */ |
| 1434 | lyxml_free_elem(module->ctx, child); |
| 1435 | continue; |
| 1436 | } |
| 1437 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1438 | if (!strcmp(child->name, "config")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1439 | if (d->flags & LYS_CONFIG_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1440 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1441 | goto error; |
| 1442 | } |
| 1443 | |
| 1444 | /* for we deviate from RFC 6020 and allow config property even it is/is not |
| 1445 | * specified in the target explicitly since config property inherits. So we expect |
| 1446 | * that config is specified in every node. But for delete, we check that the value |
| 1447 | * is the same as here in deviation |
| 1448 | */ |
| 1449 | GETVAL(value, child, "value"); |
| 1450 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1451 | d->flags |= LYS_CONFIG_R; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1452 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1453 | d->flags |= LYS_CONFIG_W; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1454 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1455 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1456 | goto error; |
| 1457 | } |
| 1458 | |
| 1459 | if (d->mod == LY_DEVIATE_DEL) { |
| 1460 | /* check values */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1461 | if ((d->flags & LYS_CONFIG_MASK) != (dev->target->flags & LYS_CONFIG_MASK)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1462 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1463 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1464 | goto error; |
| 1465 | } |
| 1466 | /* remove current config value of the target ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1467 | dev->target->flags &= ~LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1468 | |
| 1469 | /* ... and inherit config value from the target's parent */ |
| 1470 | if (dev->target->parent) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1471 | dev->target->flags |= dev->target->parent->flags & LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1472 | } else { |
| 1473 | /* default config is true */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1474 | dev->target->flags |= LYS_CONFIG_W; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1475 | } |
| 1476 | } else { /* add and replace are the same in this case */ |
| 1477 | /* remove current config value of the target ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1478 | dev->target->flags &= ~LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1479 | |
| 1480 | /* ... and replace it with the value specified in deviation */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1481 | dev->target->flags |= d->flags & LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1482 | } |
| 1483 | } else if (!strcmp(child->name, "default")) { |
| 1484 | if (d->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1485 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1486 | goto error; |
| 1487 | } |
| 1488 | GETVAL(value, child, "value"); |
| 1489 | d->dflt = lydict_insert(module->ctx, value, 0); |
| 1490 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1491 | if (dev->target->nodetype == LYS_CHOICE) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1492 | choice = (struct lys_node_choice *)dev->target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1493 | |
| 1494 | if (d->mod == LY_DEVIATE_ADD) { |
| 1495 | /* check that there is no current value */ |
| 1496 | if (choice->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1497 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1498 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1499 | goto error; |
| 1500 | } |
| 1501 | } |
| 1502 | |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1503 | rc = resolve_schema_nodeid(d->dflt, choice->child, choice->module, LYS_CHOICE, &node); |
| 1504 | if (rc) { |
| 1505 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1506 | goto error; |
| 1507 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1508 | if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1509 | if (!choice->dflt || choice->dflt != node) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1510 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1511 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1512 | goto error; |
| 1513 | } |
| 1514 | } else { /* add (already checked) and replace */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1515 | choice->dflt = node; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1516 | if (!choice->dflt) { |
| 1517 | /* default branch not found */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1518 | LOGVAL(LYE_INARG, LOGLINE(yin), value, "default"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1519 | goto error; |
| 1520 | } |
| 1521 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1522 | } else if (dev->target->nodetype == LYS_LEAF) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1523 | leaf = (struct lys_node_leaf *)dev->target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1524 | |
| 1525 | if (d->mod == LY_DEVIATE_ADD) { |
| 1526 | /* check that there is no current value */ |
| 1527 | if (leaf->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1528 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1529 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1530 | goto error; |
| 1531 | } |
| 1532 | } |
| 1533 | |
| 1534 | if (d->mod == LY_DEVIATE_DEL) { |
| 1535 | if (!leaf->dflt || leaf->dflt != d->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1536 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1537 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1538 | goto error; |
| 1539 | } |
| 1540 | /* remove value */ |
| 1541 | lydict_remove(leaf->module->ctx, leaf->dflt); |
| 1542 | leaf->dflt = NULL; |
| 1543 | } else { /* add (already checked) and replace */ |
| 1544 | /* remove value */ |
| 1545 | lydict_remove(leaf->module->ctx, leaf->dflt); |
| 1546 | |
| 1547 | /* set new value */ |
| 1548 | leaf->dflt = lydict_insert(leaf->module->ctx, d->dflt, 0); |
| 1549 | } |
| 1550 | } else { |
| 1551 | /* invalid target for default value */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1552 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1553 | LOGVAL(LYE_SPEC, 0, "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 | } else if (!strcmp(child->name, "mandatory")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1557 | if (d->flags & LYS_MAND_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1558 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1559 | goto error; |
| 1560 | } |
| 1561 | |
| 1562 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1563 | if (!(dev->target->nodetype &= (LYS_LEAF | LYS_CHOICE | LYS_ANYXML))) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1564 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1565 | LOGVAL(LYE_SPEC, 0, "Target node does not allow \"%s\" property.", child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1566 | goto error; |
| 1567 | } |
| 1568 | |
| 1569 | GETVAL(value, child, "value"); |
| 1570 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1571 | d->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1572 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1573 | d->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1574 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1575 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1576 | goto error; |
| 1577 | } |
| 1578 | |
| 1579 | if (d->mod == LY_DEVIATE_ADD) { |
| 1580 | /* check that there is no current value */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1581 | if (dev->target->flags & LYS_MAND_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1582 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1583 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1584 | goto error; |
| 1585 | } |
| 1586 | } |
| 1587 | |
| 1588 | if (d->mod == LY_DEVIATE_DEL) { |
| 1589 | /* check values */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1590 | if ((d->flags & LYS_MAND_MASK) != (dev->target->flags & LYS_MAND_MASK)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1591 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1592 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1593 | goto error; |
| 1594 | } |
| 1595 | /* remove current mandatory value of the target */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1596 | dev->target->flags &= ~LYS_MAND_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1597 | } else { /* add (already checked) and replace */ |
| 1598 | /* remove current mandatory value of the target ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1599 | dev->target->flags &= ~LYS_MAND_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1600 | |
| 1601 | /* ... and replace it with the value specified in deviation */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1602 | dev->target->flags |= d->flags & LYS_MAND_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1603 | } |
| 1604 | } else if (!strcmp(child->name, "min-elements")) { |
| 1605 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1606 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1607 | goto error; |
| 1608 | } |
| 1609 | f_min = 1; |
| 1610 | |
| 1611 | if (deviate_minmax(dev->target, child, d, 0)) { |
| 1612 | goto error; |
| 1613 | } |
| 1614 | } else if (!strcmp(child->name, "max-elements")) { |
| 1615 | if (d->max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1616 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1617 | goto error; |
| 1618 | } |
| 1619 | |
| 1620 | if (deviate_minmax(dev->target, child, d, 1)) { |
| 1621 | goto error; |
| 1622 | } |
| 1623 | } else if (!strcmp(child->name, "must")) { |
| 1624 | c_must++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1625 | /* skip lyxml_free_elem() at the end of the loop, this node will be processed later */ |
| 1626 | continue; |
| 1627 | } else if (!strcmp(child->name, "type")) { |
| 1628 | if (d->type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1629 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1630 | goto error; |
| 1631 | } |
| 1632 | |
| 1633 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1634 | if (dev->target->nodetype == LYS_LEAF) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1635 | t = &((struct lys_node_leaf *)dev->target)->type; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1636 | } else if (dev->target->nodetype == LYS_LEAFLIST) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1637 | t = &((struct lys_node_leaflist *)dev->target)->type; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1638 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1639 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1640 | LOGVAL(LYE_SPEC, 0, "Target node does not allow \"%s\" property.", child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1641 | goto error; |
| 1642 | } |
| 1643 | |
| 1644 | if (d->mod == LY_DEVIATE_ADD) { |
| 1645 | /* not allowed, type is always present at the target */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1646 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1647 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1648 | goto error; |
| 1649 | } else if (d->mod == LY_DEVIATE_DEL) { |
| 1650 | /* not allowed, type cannot be deleted from the target */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1651 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1652 | LOGVAL(LYE_SPEC, 0, "Deleteing type from the target is not allowed."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1653 | goto error; |
| 1654 | } |
| 1655 | |
| 1656 | /* replace */ |
| 1657 | /* remove current units value of the target ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1658 | lys_type_free(dev->target->module->ctx, t); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1659 | |
| 1660 | /* ... and replace it with the value specified in deviation */ |
Radek Krejci | 8de7b0f | 2015-07-02 11:43:42 +0200 | [diff] [blame] | 1661 | if (fill_yin_type(module, dev->target, child, t, NULL)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1662 | goto error; |
| 1663 | } |
| 1664 | d->type = t; |
| 1665 | } else if (!strcmp(child->name, "unique")) { |
| 1666 | c_uniq++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1667 | /* skip lyxml_free_elem() at the end of the loop, this node will be processed later */ |
| 1668 | continue; |
| 1669 | } else if (!strcmp(child->name, "units")) { |
| 1670 | if (d->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1671 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1672 | goto error; |
| 1673 | } |
| 1674 | |
| 1675 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1676 | if (dev->target->nodetype == LYS_LEAFLIST) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1677 | stritem = &((struct lys_node_leaflist *)dev->target)->units; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1678 | } else if (dev->target->nodetype == LYS_LEAF) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1679 | stritem = &((struct lys_node_leaf *)dev->target)->units; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1680 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1681 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1682 | LOGVAL(LYE_SPEC, 0, "Target node does not allow \"%s\" property.", child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1683 | goto error; |
| 1684 | } |
| 1685 | |
| 1686 | /* get units value */ |
| 1687 | GETVAL(value, child, "name"); |
| 1688 | d->units = lydict_insert(module->ctx, value, 0); |
| 1689 | |
| 1690 | /* apply to target */ |
| 1691 | if (d->mod == LY_DEVIATE_ADD) { |
| 1692 | /* check that there is no current value */ |
| 1693 | if (*stritem) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1694 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1695 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1696 | goto error; |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | if (d->mod == LY_DEVIATE_DEL) { |
| 1701 | /* check values */ |
| 1702 | if (*stritem != d->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1703 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1704 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1705 | goto error; |
| 1706 | } |
| 1707 | /* remove current units value of the target */ |
| 1708 | lydict_remove(dev->target->module->ctx, *stritem); |
| 1709 | } else { /* add (already checked) and replace */ |
| 1710 | /* remove current units value of the target ... */ |
| 1711 | lydict_remove(dev->target->module->ctx, *stritem); |
| 1712 | |
| 1713 | /* ... and replace it with the value specified in deviation */ |
| 1714 | *stritem = lydict_insert(module->ctx, value, 0); |
| 1715 | } |
| 1716 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1717 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1718 | goto error; |
| 1719 | } |
| 1720 | |
| 1721 | lyxml_free_elem(module->ctx, child); |
| 1722 | } |
| 1723 | |
| 1724 | if (c_must) { |
| 1725 | /* check target node type */ |
| 1726 | switch (dev->target->nodetype) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1727 | case LYS_LEAF: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1728 | trg_must = &((struct lys_node_leaf *)dev->target)->must; |
| 1729 | trg_must_size = &((struct lys_node_leaf *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1730 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1731 | case LYS_CONTAINER: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1732 | trg_must = &((struct lys_node_container *)dev->target)->must; |
| 1733 | trg_must_size = &((struct lys_node_container *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1734 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1735 | case LYS_LEAFLIST: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1736 | trg_must = &((struct lys_node_leaflist *)dev->target)->must; |
| 1737 | trg_must_size = &((struct lys_node_leaflist *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1738 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1739 | case LYS_LIST: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1740 | trg_must = &((struct lys_node_list *)dev->target)->must; |
| 1741 | trg_must_size = &((struct lys_node_list *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1742 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1743 | case LYS_ANYXML: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1744 | trg_must = &((struct lys_node_anyxml *)dev->target)->must; |
| 1745 | trg_must_size = &((struct lys_node_anyxml *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1746 | break; |
| 1747 | default: |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1748 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1749 | LOGVAL(LYE_SPEC, 0, "Target node does not allow \"%s\" property.", child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1750 | goto error; |
| 1751 | } |
| 1752 | |
| 1753 | if (d->mod == LY_DEVIATE_RPL) { |
| 1754 | /* remove target's musts and allocate new array for it */ |
| 1755 | if (!*trg_must) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1756 | LOGVAL(LYE_INARG, LOGLINE(develem), "replace", "deviate"); |
| 1757 | LOGVAL(LYE_SPEC, 0, "Property \"must\" to replace does not exists in target."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1758 | goto error; |
| 1759 | } |
| 1760 | |
| 1761 | for (i = 0; i < list->must_size; i++) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1762 | lys_restr_free(dev->target->module->ctx, &(*trg_must[i])); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1763 | } |
| 1764 | free(*trg_must); |
| 1765 | *trg_must = d->must = calloc(c_must, sizeof *d->must); |
| 1766 | d->must_size = c_must; |
| 1767 | *trg_must_size = 0; |
| 1768 | } else if (d->mod == LY_DEVIATE_ADD) { |
| 1769 | /* reallocate the must array of the target */ |
| 1770 | d->must = realloc(*trg_must, (c_must + *trg_must_size) * sizeof *d->must); |
| 1771 | *trg_must = d->must; |
| 1772 | d->must = &(*trg_must[*trg_must_size]); |
| 1773 | d->must_size = c_must; |
| 1774 | } else { /* LY_DEVIATE_DEL */ |
| 1775 | d->must = calloc(c_must, sizeof *d->must); |
| 1776 | } |
| 1777 | } |
| 1778 | if (c_uniq) { |
| 1779 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1780 | if (dev->target->nodetype != LYS_LIST) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1781 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1782 | LOGVAL(LYE_SPEC, 0, "Target node does not allow \"%s\" property.", child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1783 | goto error; |
| 1784 | } |
| 1785 | |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1786 | list = (struct lys_node_list *)dev->target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1787 | if (d->mod == LY_DEVIATE_RPL) { |
| 1788 | /* remove target's unique and allocate new array for it */ |
| 1789 | if (!list->unique) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1790 | LOGVAL(LYE_INARG, LOGLINE(develem), "replace", "deviate"); |
| 1791 | LOGVAL(LYE_SPEC, 0, "Property \"unique\" to replace does not exists in target."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1792 | goto error; |
| 1793 | } |
| 1794 | |
| 1795 | for (i = 0; i < list->unique_size; i++) { |
| 1796 | free(list->unique[i].leafs); |
| 1797 | } |
| 1798 | free(list->unique); |
| 1799 | list->unique = d->unique = calloc(c_uniq, sizeof *d->unique); |
| 1800 | d->unique_size = c_uniq; |
| 1801 | list->unique_size = 0; |
| 1802 | } else if (d->mod == LY_DEVIATE_ADD) { |
| 1803 | /* reallocate the unique array of the target */ |
| 1804 | d->unique = realloc(list->unique, (c_uniq + list->unique_size) * sizeof *d->unique); |
| 1805 | list->unique = d->unique; |
| 1806 | d->unique = &list->unique[list->unique_size]; |
| 1807 | d->unique_size = c_uniq; |
| 1808 | } else { /* LY_DEVIATE_DEL */ |
| 1809 | d->unique = calloc(c_uniq, sizeof *d->unique); |
| 1810 | } |
| 1811 | } |
| 1812 | |
| 1813 | /* process deviation properties with 0..n cardinality */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1814 | LY_TREE_FOR(develem->child, child) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1815 | if (!strcmp(child->name, "must")) { |
| 1816 | if (d->mod == LY_DEVIATE_DEL) { |
| 1817 | if (fill_yin_must(module, child, &d->must[d->must_size])) { |
| 1818 | goto error; |
| 1819 | } |
| 1820 | |
| 1821 | /* find must to delete, we are ok with just matching conditions */ |
| 1822 | for (i = 0; i < *trg_must_size; i++) { |
| 1823 | if (d->must[d->must_size].expr == (*trg_must)[i].expr) { |
| 1824 | /* we have a match, free the must structure ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1825 | lys_restr_free(dev->target->module->ctx, &(*trg_must[i])); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1826 | /* ... and maintain the array */ |
| 1827 | (*trg_must_size)--; |
| 1828 | if (i != *trg_must_size) { |
| 1829 | (*trg_must)[i].expr = (*trg_must)[*trg_must_size].expr; |
| 1830 | (*trg_must)[i].dsc = (*trg_must)[*trg_must_size].dsc; |
| 1831 | (*trg_must)[i].ref = (*trg_must)[*trg_must_size].ref; |
| 1832 | (*trg_must)[i].eapptag = (*trg_must)[*trg_must_size].eapptag; |
| 1833 | (*trg_must)[i].emsg = (*trg_must)[*trg_must_size].emsg; |
| 1834 | } |
| 1835 | if (!(*trg_must_size)) { |
| 1836 | free(*trg_must); |
| 1837 | *trg_must = NULL; |
| 1838 | } else { |
| 1839 | (*trg_must)[*trg_must_size].expr = NULL; |
| 1840 | (*trg_must)[*trg_must_size].dsc = NULL; |
| 1841 | (*trg_must)[*trg_must_size].ref = NULL; |
| 1842 | (*trg_must)[*trg_must_size].eapptag = NULL; |
| 1843 | (*trg_must)[*trg_must_size].emsg = NULL; |
| 1844 | } |
| 1845 | |
| 1846 | i = -1; /* set match flag */ |
| 1847 | break; |
| 1848 | } |
| 1849 | } |
| 1850 | d->must_size++; |
| 1851 | if (i != -1) { |
| 1852 | /* no match found */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1853 | LOGVAL(LYE_INARG, LOGLINE(child), d->must[d->must_size - 1].expr, child->name); |
| 1854 | LOGVAL(LYE_SPEC, 0, "Value does not match any must from the target."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1855 | goto error; |
| 1856 | } |
| 1857 | } else { /* replace or add */ |
| 1858 | if (fill_yin_must(dev->target->module, child, &((*trg_must)[*trg_must_size]))) { |
| 1859 | goto error; |
| 1860 | } |
| 1861 | (*trg_must_size)++; |
| 1862 | } |
| 1863 | } else if (!strcmp(child->name, "unique")) { |
| 1864 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1865 | GETVAL(value, child, "tag"); |
Michal Vasko | 184521f | 2015-09-24 13:14:26 +0200 | [diff] [blame] | 1866 | if (resolve_unique(dev->target, value, &d->unique[d->unique_size], 0, LOGLINE(child))) { |
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++) { |
| 1872 | if (list->unique[i].leafs_size != d->unique[d->unique_size].leafs_size) { |
| 1873 | continue; |
| 1874 | } |
| 1875 | |
| 1876 | for (j = 0; j < d->unique[d->unique_size].leafs_size; j++) { |
| 1877 | if (list->unique[i].leafs[j] != d->unique[d->unique_size].leafs[j]) { |
| 1878 | break; |
| 1879 | } |
| 1880 | } |
| 1881 | |
| 1882 | if (j == d->unique[d->unique_size].leafs_size) { |
| 1883 | /* we have a match, free the unique structure ... */ |
| 1884 | free(list->unique[i].leafs); |
| 1885 | /* ... and maintain the array */ |
| 1886 | list->unique_size--; |
| 1887 | if (i != list->unique_size) { |
| 1888 | list->unique[i].leafs_size = list->unique[list->unique_size].leafs_size; |
| 1889 | list->unique[i].leafs = list->unique[list->unique_size].leafs; |
| 1890 | } |
| 1891 | |
| 1892 | if (!list->unique_size) { |
| 1893 | free(list->unique); |
| 1894 | list->unique = NULL; |
| 1895 | } else { |
| 1896 | list->unique[list->unique_size].leafs_size = 0; |
| 1897 | list->unique[list->unique_size].leafs = NULL; |
| 1898 | } |
| 1899 | |
| 1900 | i = -1; /* set match flag */ |
| 1901 | break; |
| 1902 | } |
| 1903 | } |
| 1904 | |
| 1905 | d->unique_size++; |
| 1906 | if (i != -1) { |
| 1907 | /* no match found */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1908 | LOGVAL(LYE_INARG, LOGLINE(child), lyxml_get_attr(child, "tag", NULL), child->name); |
| 1909 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1910 | goto error; |
| 1911 | } |
| 1912 | } else { /* replace or add */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1913 | GETVAL(value, child, "tag"); |
Michal Vasko | 184521f | 2015-09-24 13:14:26 +0200 | [diff] [blame] | 1914 | if (resolve_unique(dev->target, value, &list->unique[list->unique_size], 0, LOGLINE(child))) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1915 | goto error; |
| 1916 | } |
| 1917 | list->unique_size++; |
| 1918 | } |
| 1919 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1920 | } |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1921 | |
| 1922 | dev->deviate_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1923 | } |
| 1924 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1925 | return EXIT_SUCCESS; |
| 1926 | |
| 1927 | error: |
| 1928 | |
| 1929 | if (dev->deviate) { |
| 1930 | for (i = 0; i < dev->deviate_size; i++) { |
| 1931 | lydict_remove(module->ctx, dev->deviate[i].dflt); |
| 1932 | lydict_remove(module->ctx, dev->deviate[i].units); |
| 1933 | |
| 1934 | if (dev->deviate[i].mod == LY_DEVIATE_DEL) { |
| 1935 | for (j = 0; j < dev->deviate[i].must_size; j++) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1936 | lys_restr_free(module->ctx, &dev->deviate[i].must[j]); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1937 | } |
| 1938 | free(dev->deviate[i].must); |
| 1939 | |
| 1940 | for (j = 0; j < dev->deviate[i].unique_size; j++) { |
| 1941 | free(dev->deviate[i].unique[j].leafs); |
| 1942 | } |
| 1943 | free(dev->deviate[i].unique); |
| 1944 | } |
| 1945 | } |
| 1946 | free(dev->deviate); |
| 1947 | } |
| 1948 | |
| 1949 | return EXIT_FAILURE; |
| 1950 | } |
| 1951 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1952 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1953 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1954 | 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] | 1955 | struct unres_schema *unres) |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1956 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1957 | const char *value; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1958 | struct lyxml_elem *child, *next; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1959 | struct lys_node *node; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1960 | int c = 0; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1961 | |
Michal Vasko | 591e0b2 | 2015-08-13 13:53:43 +0200 | [diff] [blame] | 1962 | aug->nodetype = LYS_AUGMENT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1963 | GETVAL(value, yin, "target-node"); |
| 1964 | aug->target_name = lydict_insert(module->ctx, value, 0); |
| 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 */ |
| 1974 | lyxml_free_elem(module->ctx, child); |
| 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) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1983 | LOGVAL(LYE_TOOMANY, LOGLINE(child), 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 | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1989 | lyxml_free_elem(module->ctx, child); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1990 | goto error; |
| 1991 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 1992 | if (lyxp_syntax_check(aug->when->cond, LOGLINE(child))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1993 | goto error; |
| 1994 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1995 | lyxml_free_elem(module->ctx, child); |
| 1996 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1997 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1998 | /* check allowed data sub-statements */ |
| 1999 | } else if (!strcmp(child->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2000 | node = read_yin_container(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2001 | } else if (!strcmp(child->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2002 | node = read_yin_leaflist(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2003 | } else if (!strcmp(child->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2004 | node = read_yin_leaf(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2005 | } else if (!strcmp(child->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2006 | node = read_yin_list(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2007 | } else if (!strcmp(child->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2008 | node = read_yin_uses(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2009 | } else if (!strcmp(child->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2010 | node = read_yin_case(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2011 | } else if (!strcmp(child->name, "case")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2012 | node = read_yin_case(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2013 | } else if (!strcmp(child->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2014 | node = read_yin_anyxml(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2015 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2016 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2017 | goto error; |
| 2018 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2019 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2020 | if (!node) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2021 | goto error; |
| 2022 | } |
| 2023 | |
| 2024 | /* check for mandatory nodes - if the target node is in another module |
| 2025 | * the added nodes cannot be mandatory |
| 2026 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2027 | if ((!parent || (parent->nodetype != LYS_USES)) && check_mandatory(node)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2028 | LOGVAL(LYE_SPEC, LOGLINE(child), "When augmenting data in another module, mandatory statement is not allowed."); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2029 | goto error; |
| 2030 | } |
| 2031 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2032 | node = NULL; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2033 | lyxml_free_elem(module->ctx, child); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | if (c) { |
| 2037 | aug->features = calloc(c, sizeof *aug->features); |
| 2038 | } |
| 2039 | |
| 2040 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 2041 | if (!strcmp(child->name, "if-feature")) { |
| 2042 | GETVAL(value, child, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 2043 | if (unres_schema_add_str(module, unres, &aug->features[aug->features_size++], UNRES_IFFEAT, value, LOGLINE(child)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2044 | goto error; |
| 2045 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2046 | lyxml_free_elem(module->ctx, child); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2047 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2048 | } |
| 2049 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2050 | /* aug->child points to the parsed nodes, they must now be |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 2051 | * connected to the tree and adjusted (if possible right now). |
| 2052 | * However, if this is augment in a uses, it gets resolved |
| 2053 | * when the uses does and cannot be resolved now for sure |
| 2054 | * (the grouping was not yet copied into uses). |
| 2055 | */ |
| 2056 | if (!parent || (parent->nodetype != LYS_USES)) { |
Michal Vasko | 1d87a92 | 2015-08-21 12:57:16 +0200 | [diff] [blame] | 2057 | if (resolve_augment(aug, aug->child)) { |
Michal Vasko | 4adc10f | 2015-08-11 15:26:17 +0200 | [diff] [blame] | 2058 | LOGVAL(LYE_INRESOLV, LOGLINE(yin), "augment", aug->target_name); |
| 2059 | goto error; |
| 2060 | } |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 2061 | } |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2062 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2063 | return EXIT_SUCCESS; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2064 | |
| 2065 | error: |
| 2066 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2067 | return EXIT_FAILURE; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2068 | } |
| 2069 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2070 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2071 | static int |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 2072 | 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] | 2073 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2074 | struct lyxml_elem *sub, *next; |
| 2075 | const char *value; |
| 2076 | char *endptr; |
| 2077 | int f_mand = 0, f_min = 0, f_max = 0; |
| 2078 | int c_must = 0; |
| 2079 | int r; |
| 2080 | unsigned long int val; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2081 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2082 | 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] | 2083 | goto error; |
| 2084 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2085 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2086 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2087 | rfn->target_name = lydict_insert(module->ctx, value, 0); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2088 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2089 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2090 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2091 | /* garbage */ |
| 2092 | lyxml_free_elem(module->ctx, sub); |
| 2093 | continue; |
| 2094 | } |
| 2095 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2096 | /* limited applicability */ |
| 2097 | if (!strcmp(sub->name, "default")) { |
| 2098 | /* leaf or choice */ |
| 2099 | if (rfn->mod.dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2100 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2101 | goto error; |
| 2102 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2103 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2104 | /* check possibility of statements combination */ |
| 2105 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2106 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2107 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2108 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2109 | goto error; |
| 2110 | } |
| 2111 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2112 | rfn->target_type = LYS_LEAF | LYS_CHOICE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2113 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2114 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2115 | GETVAL(value, sub, "value"); |
| 2116 | rfn->mod.dflt = lydict_insert(module->ctx, value, strlen(value)); |
| 2117 | } else if (!strcmp(sub->name, "mandatory")) { |
| 2118 | /* leaf, choice or anyxml */ |
| 2119 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2120 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2121 | goto error; |
| 2122 | } |
| 2123 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2124 | * multiple mandatory statements with the "false" value |
| 2125 | */ |
| 2126 | f_mand = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2127 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2128 | /* check possibility of statements combination */ |
| 2129 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2130 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE | LYS_ANYXML); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2131 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2132 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2133 | goto error; |
| 2134 | } |
| 2135 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2136 | rfn->target_type = LYS_LEAF | LYS_CHOICE | LYS_ANYXML; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2137 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2138 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2139 | GETVAL(value, sub, "value"); |
| 2140 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2141 | rfn->flags |= LYS_MAND_TRUE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2142 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2143 | rfn->flags |= LYS_MAND_FALSE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2144 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2145 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2146 | goto error; |
| 2147 | } |
| 2148 | } else if (!strcmp(sub->name, "min-elements")) { |
| 2149 | /* list or leaf-list */ |
| 2150 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2151 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2152 | goto error; |
| 2153 | } |
| 2154 | f_min = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2155 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2156 | /* check possibility of statements combination */ |
| 2157 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2158 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2159 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2160 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2161 | goto error; |
| 2162 | } |
| 2163 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2164 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2165 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2166 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2167 | GETVAL(value, sub, "value"); |
| 2168 | while (isspace(value[0])) { |
| 2169 | value++; |
| 2170 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2171 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2172 | /* convert it to uint32_t */ |
| 2173 | errno = 0; |
| 2174 | endptr = NULL; |
| 2175 | val = strtoul(value, &endptr, 10); |
| 2176 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2177 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2178 | goto error; |
| 2179 | } |
| 2180 | rfn->mod.list.min = (uint32_t) val; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2181 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2182 | /* magic - bit 3 in flags means min set */ |
| 2183 | rfn->flags |= 0x04; |
| 2184 | } else if (!strcmp(sub->name, "max-elements")) { |
| 2185 | /* list or leaf-list */ |
| 2186 | if (f_max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2187 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2188 | goto error; |
| 2189 | } |
| 2190 | f_max = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2191 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2192 | /* check possibility of statements combination */ |
| 2193 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2194 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2195 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2196 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2197 | goto error; |
| 2198 | } |
| 2199 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2200 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2201 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2202 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2203 | GETVAL(value, sub, "value"); |
| 2204 | while (isspace(value[0])) { |
| 2205 | value++; |
| 2206 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2207 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2208 | /* convert it to uint32_t */ |
| 2209 | errno = 0; |
| 2210 | endptr = NULL; |
| 2211 | val = strtoul(value, &endptr, 10); |
| 2212 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2213 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2214 | goto error; |
| 2215 | } |
| 2216 | rfn->mod.list.max = (uint32_t) val; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2217 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2218 | /* magic - bit 4 in flags means min set */ |
| 2219 | rfn->flags |= 0x08; |
| 2220 | } else if (!strcmp(sub->name, "presence")) { |
| 2221 | /* container */ |
| 2222 | if (rfn->mod.presence) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2223 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), 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) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2231 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2232 | goto error; |
| 2233 | } |
| 2234 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2235 | rfn->target_type = LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2236 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2237 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2238 | GETVAL(value, sub, "value"); |
| 2239 | rfn->mod.presence = lydict_insert(module->ctx, value, strlen(value)); |
| 2240 | } else if (!strcmp(sub->name, "must")) { |
| 2241 | /* leaf-list, list, container or anyxml */ |
| 2242 | /* check possibility of statements combination */ |
| 2243 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2244 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST | LYS_CONTAINER | LYS_ANYXML); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2245 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2246 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2247 | goto error; |
| 2248 | } |
| 2249 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2250 | rfn->target_type = LYS_LIST | LYS_LEAFLIST | LYS_CONTAINER | LYS_ANYXML; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2251 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2252 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2253 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 2254 | continue; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2255 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2256 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2257 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2258 | goto error; |
| 2259 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2260 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2261 | lyxml_free_elem(module->ctx, sub); |
| 2262 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2263 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2264 | /* process nodes with cardinality of 0..n */ |
| 2265 | if (c_must) { |
| 2266 | rfn->must = calloc(c_must, sizeof *rfn->must); |
| 2267 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2268 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2269 | r = fill_yin_must(module, sub, &rfn->must[rfn->must_size++]); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2270 | if (r) { |
| 2271 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2272 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 2273 | if (lyxp_syntax_check(rfn->must[rfn->must_size-1].expr, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2274 | goto error; |
| 2275 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2276 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2277 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2278 | return EXIT_SUCCESS; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2279 | |
| 2280 | error: |
| 2281 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2282 | return EXIT_FAILURE; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2283 | } |
| 2284 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2285 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2286 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2287 | 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] | 2288 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2289 | struct lyxml_elem *child; |
| 2290 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2291 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2292 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2293 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2294 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2295 | continue; |
| 2296 | } |
| 2297 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2298 | if (!strcmp(child->name, "prefix")) { |
| 2299 | GETVAL(value, child, "value"); |
| 2300 | if (check_identifier(value, LY_IDENT_PREFIX, LOGLINE(child), module, NULL)) { |
| 2301 | goto error; |
| 2302 | } |
| 2303 | imp->prefix = lydict_insert(module->ctx, value, strlen(value)); |
| 2304 | } else if (!strcmp(child->name, "revision-date")) { |
| 2305 | if (imp->rev[0]) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2306 | LOGVAL(LYE_TOOMANY, LOGLINE(child), "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2307 | goto error; |
| 2308 | } |
| 2309 | GETVAL(value, child, "date"); |
| 2310 | if (check_date(value, LOGLINE(child))) { |
| 2311 | goto error; |
| 2312 | } |
| 2313 | memcpy(imp->rev, value, LY_REV_SIZE - 1); |
| 2314 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2315 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2316 | goto error; |
| 2317 | } |
| 2318 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2319 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2320 | /* check mandatory information */ |
| 2321 | if (!imp->prefix) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2322 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "prefix", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2323 | goto error; |
| 2324 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2325 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2326 | GETVAL(value, yin, "module"); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 2327 | imp->module = ly_ctx_get_module(module->ctx, value, imp->rev[0] ? imp->rev : NULL); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2328 | if (!imp->module) { |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 2329 | imp->module = lyp_search_file(module->ctx, NULL, value, imp->rev[0] ? imp->rev : NULL); |
| 2330 | if (!imp->module) { |
| 2331 | LOGERR(LY_EVALID, "Data model \"%s\" not found (search path is \"%s\")", value, module->ctx->models.search_path); |
| 2332 | LOGERR(LY_EVALID, "Importing \"%s\" module into \"%s\" failed.", value, module->name); |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2333 | LOGVAL(LYE_INARG, LOGLINE(yin), value, yin->name); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 2334 | goto error; |
| 2335 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2336 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2337 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2338 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2339 | |
| 2340 | error: |
| 2341 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2342 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2343 | } |
| 2344 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2345 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2346 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2347 | fill_yin_include(struct lys_module *module, struct lyxml_elem *yin, struct lys_include *inc) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2348 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2349 | struct lyxml_elem *child; |
| 2350 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2351 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2352 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2353 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2354 | /* garbage */ |
| 2355 | continue; |
| 2356 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2357 | if (!strcmp(child->name, "revision-date")) { |
| 2358 | if (inc->rev[0]) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2359 | LOGVAL(LYE_TOOMANY, LOGLINE(child), "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2360 | goto error; |
| 2361 | } |
| 2362 | GETVAL(value, child, "date"); |
| 2363 | if (check_date(value, LOGLINE(child))) { |
| 2364 | goto error; |
| 2365 | } |
| 2366 | memcpy(inc->rev, value, LY_REV_SIZE - 1); |
| 2367 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2368 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2369 | goto error; |
| 2370 | } |
| 2371 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2372 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2373 | GETVAL(value, yin, "module"); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 2374 | inc->submodule = ly_ctx_get_submodule(module, value, inc->rev[0] ? inc->rev : NULL); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2375 | if (!inc->submodule) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2376 | inc->submodule = (struct lys_submodule *) lyp_search_file(module->ctx, module, value, inc->rev[0] ? inc->rev : NULL); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 2377 | if (!inc->submodule) { |
| 2378 | LOGERR(LY_EVALID, "Data model \"%s\" not found (search path is \"%s\")", value, module->ctx->models.search_path); |
| 2379 | LOGERR(LY_EVALID, "Including \"%s\" module into \"%s\" failed.", value, module->name); |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2380 | LOGVAL(LYE_INARG, LOGLINE(yin), value, yin->name); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 2381 | goto error; |
| 2382 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2383 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2384 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2385 | /* check that belongs-to corresponds */ |
| 2386 | if (module->type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2387 | module = ((struct lys_submodule *)module)->belongsto; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2388 | } |
| 2389 | if (inc->submodule->belongsto != module) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2390 | LOGVAL(LYE_INARG, LOGLINE(yin), value, yin->name); |
| 2391 | LOGVAL(LYE_SPEC, 0, "The included module does not belongs-to the \"%s\" module", module->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2392 | goto error; |
| 2393 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2394 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2395 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2396 | |
| 2397 | error: |
| 2398 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2399 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2400 | } |
| 2401 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2402 | /* logs directly |
| 2403 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2404 | * Covers: |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 2405 | * description, reference, status, optionaly config |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 2406 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2407 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2408 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2409 | read_yin_common(struct lys_module *module, struct lys_node *parent, |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2410 | struct lys_node *node, struct lyxml_elem *xmlnode, int opt) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2411 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2412 | const char *value; |
| 2413 | struct lyxml_elem *sub, *next; |
| 2414 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2415 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2416 | if (opt & OPT_MODULE) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2417 | node->module = module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2418 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2419 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2420 | if (opt & OPT_IDENT) { |
| 2421 | GETVAL(value, xmlnode, "name"); |
| 2422 | if (check_identifier(value, LY_IDENT_NAME, LOGLINE(xmlnode), NULL, NULL)) { |
| 2423 | goto error; |
| 2424 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2425 | node->name = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2426 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2427 | |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2428 | /* inherit NACM flags */ |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2429 | if ((opt & OPT_NACMEXT) && parent) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2430 | node->nacm = parent->nacm; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2431 | } |
| 2432 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2433 | /* process local parameters */ |
| 2434 | LY_TREE_FOR_SAFE(xmlnode->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2435 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2436 | /* garbage */ |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2437 | lyxml_free_elem(ctx, sub); |
| 2438 | continue; |
| 2439 | } |
| 2440 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 2441 | /* NACM extensions */ |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2442 | if ((opt & OPT_NACMEXT) && !strcmp(sub->ns->value, LY_NSNACM)) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2443 | if (!strcmp(sub->name, "default-deny-write")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2444 | node->nacm |= LYS_NACM_DENYW; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2445 | } else if (!strcmp(sub->name, "default-deny-all")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2446 | node->nacm |= LYS_NACM_DENYA; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2447 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2448 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2449 | goto error; |
| 2450 | } |
| 2451 | } |
| 2452 | |
| 2453 | /* else garbage */ |
| 2454 | lyxml_free_elem(ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2455 | continue; |
| 2456 | } |
| 2457 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2458 | if (!strcmp(sub->name, "description")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2459 | if (node->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2460 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2461 | goto error; |
| 2462 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2463 | node->dsc = read_yin_subnode(ctx, sub, "text"); |
| 2464 | if (!node->dsc) { |
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 (!strcmp(sub->name, "reference")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2468 | if (node->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2469 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2470 | goto error; |
| 2471 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2472 | node->ref = read_yin_subnode(ctx, sub, "text"); |
| 2473 | if (!node->ref) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2474 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2475 | } |
| 2476 | } else if (!strcmp(sub->name, "status")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2477 | if (node->flags & LYS_STATUS_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2478 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2479 | goto error; |
| 2480 | } |
| 2481 | GETVAL(value, sub, "value"); |
| 2482 | if (!strcmp(value, "current")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2483 | node->flags |= LYS_STATUS_CURR; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2484 | } else if (!strcmp(value, "deprecated")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2485 | node->flags |= LYS_STATUS_DEPRC; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2486 | } else if (!strcmp(value, "obsolete")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2487 | node->flags |= LYS_STATUS_OBSLT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2488 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2489 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2490 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2491 | } |
| 2492 | } else if ((opt & OPT_CONFIG) && !strcmp(sub->name, "config")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2493 | if (node->flags & LYS_CONFIG_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2494 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2495 | goto error; |
| 2496 | } |
| 2497 | GETVAL(value, sub, "value"); |
| 2498 | if (!strcmp(value, "false")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2499 | node->flags |= LYS_CONFIG_R; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2500 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2501 | node->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2502 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2503 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2504 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2505 | } |
| 2506 | } else { |
| 2507 | /* skip the lyxml_free_elem */ |
| 2508 | continue; |
| 2509 | } |
| 2510 | lyxml_free_elem(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2511 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2512 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2513 | if ((opt & OPT_INHERIT) && !(node->flags & LYS_CONFIG_MASK)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2514 | /* get config flag from parent */ |
| 2515 | if (parent) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2516 | node->flags |= parent->flags & LYS_CONFIG_MASK; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2517 | } else { |
| 2518 | /* default config is true */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2519 | node->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2520 | } |
| 2521 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2522 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2523 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 2524 | |
| 2525 | error: |
| 2526 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2527 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2528 | } |
| 2529 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2530 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2531 | static struct lys_when * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2532 | read_yin_when(struct lys_module *module, struct lyxml_elem *yin) |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2533 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2534 | struct lys_when *retval = NULL; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2535 | struct lyxml_elem *child; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2536 | const char *value; |
| 2537 | |
| 2538 | retval = calloc(1, sizeof *retval); |
| 2539 | |
| 2540 | GETVAL(value, yin, "condition"); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 2541 | retval->cond = transform_expr_xml2json(module->ctx, value, yin, 1); |
| 2542 | if (!retval->cond) { |
| 2543 | goto error; |
| 2544 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2545 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2546 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2547 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2548 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2549 | continue; |
| 2550 | } |
| 2551 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2552 | if (!strcmp(child->name, "description")) { |
| 2553 | if (retval->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2554 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2555 | goto error; |
| 2556 | } |
| 2557 | retval->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 2558 | if (!retval->dsc) { |
| 2559 | goto error; |
| 2560 | } |
| 2561 | } else if (!strcmp(child->name, "reference")) { |
| 2562 | if (retval->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2563 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2564 | goto error; |
| 2565 | } |
| 2566 | retval->ref = read_yin_subnode(module->ctx, child, "text"); |
| 2567 | if (!retval->ref) { |
| 2568 | goto error; |
| 2569 | } |
| 2570 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2571 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2572 | goto error; |
| 2573 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2574 | } |
| 2575 | |
| 2576 | return retval; |
| 2577 | |
| 2578 | error: |
| 2579 | |
Michal Vasko | 0308dd6 | 2015-10-07 09:14:40 +0200 | [diff] [blame] | 2580 | lys_when_free(module->ctx, retval); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2581 | return NULL; |
| 2582 | } |
| 2583 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2584 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2585 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 2586 | read_yin_case(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 2587 | struct unres_schema *unres) |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2588 | { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2589 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2590 | struct lys_node_case *cs; |
| 2591 | struct lys_node *retval, *node = NULL; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2592 | int c_ftrs = 0; |
| 2593 | const char *value; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2594 | |
Radek Krejci | e867c85 | 2015-08-27 09:52:34 +0200 | [diff] [blame] | 2595 | /* init */ |
| 2596 | memset(&root, 0, sizeof root); |
| 2597 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2598 | cs = calloc(1, sizeof *cs); |
| 2599 | cs->nodetype = LYS_CASE; |
| 2600 | cs->prev = (struct lys_node *)cs; |
| 2601 | retval = (struct lys_node *)cs; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2602 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2603 | 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] | 2604 | goto error; |
| 2605 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2606 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 2607 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 2608 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2609 | /* insert the node into the schema tree */ |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 2610 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2611 | goto error; |
| 2612 | } |
| 2613 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2614 | /* process choice's specific children */ |
| 2615 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2616 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2617 | /* garbage */ |
| 2618 | lyxml_free_elem(module->ctx, sub); |
| 2619 | continue; |
| 2620 | } |
| 2621 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2622 | if (!strcmp(sub->name, "container") || |
| 2623 | !strcmp(sub->name, "leaf-list") || |
| 2624 | !strcmp(sub->name, "leaf") || |
| 2625 | !strcmp(sub->name, "list") || |
| 2626 | !strcmp(sub->name, "uses") || |
| 2627 | !strcmp(sub->name, "choice") || |
| 2628 | !strcmp(sub->name, "anyxml")) { |
| 2629 | |
| 2630 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 2631 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2632 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2633 | c_ftrs++; |
| 2634 | /* skip lyxml_free_elem() at the end of the loop, sub is processed later */ |
| 2635 | continue; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2636 | } else if (!strcmp(sub->name, "when")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2637 | if (cs->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2638 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2639 | goto error; |
| 2640 | } |
| 2641 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2642 | cs->when = read_yin_when(module, sub); |
| 2643 | if (!cs->when) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2644 | goto error; |
| 2645 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 2646 | if (lyxp_syntax_check(cs->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2647 | goto error; |
| 2648 | } |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2649 | |
| 2650 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2651 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2652 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2653 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2654 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2655 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2656 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2657 | if (c_ftrs) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2658 | cs->features = calloc(c_ftrs, sizeof *cs->features); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2659 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2660 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2661 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 2662 | if (unres_schema_add_str(module, unres, &cs->features[cs->features_size++], UNRES_IFFEAT, value, LOGLINE(sub)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2663 | goto error; |
| 2664 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2665 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 2666 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2667 | /* last part - process data nodes */ |
| 2668 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 2669 | if (!strcmp(sub->name, "container")) { |
| 2670 | node = read_yin_container(module, retval, sub, resolve, unres); |
| 2671 | } else if (!strcmp(sub->name, "leaf-list")) { |
| 2672 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
| 2673 | } else if (!strcmp(sub->name, "leaf")) { |
| 2674 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
| 2675 | } else if (!strcmp(sub->name, "list")) { |
| 2676 | node = read_yin_list(module, retval, sub, resolve, unres); |
| 2677 | } else if (!strcmp(sub->name, "choice")) { |
| 2678 | node = read_yin_choice(module, retval, sub, resolve, unres); |
| 2679 | } else if (!strcmp(sub->name, "uses")) { |
| 2680 | node = read_yin_uses(module, retval, sub, resolve, unres); |
| 2681 | } else if (!strcmp(sub->name, "anyxml")) { |
| 2682 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
| 2683 | } |
| 2684 | if (!node) { |
| 2685 | goto error; |
| 2686 | } |
| 2687 | |
| 2688 | lyxml_free_elem(module->ctx, sub); |
| 2689 | } |
| 2690 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2691 | return retval; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2692 | |
| 2693 | error: |
| 2694 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2695 | while (root.child) { |
| 2696 | lyxml_free_elem(module->ctx, root.child); |
| 2697 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2698 | lys_node_free(retval); |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2699 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2700 | return NULL; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2701 | } |
| 2702 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2703 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2704 | static struct lys_node * |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 2705 | 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] | 2706 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2707 | struct lyxml_elem *sub, *next; |
| 2708 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2709 | struct lys_node *retval, *node = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2710 | struct lys_node_choice *choice; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2711 | const char *value, *dflt_str = NULL; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2712 | int f_mand = 0, c_ftrs = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2713 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2714 | choice = calloc(1, sizeof *choice); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2715 | choice->nodetype = LYS_CHOICE; |
| 2716 | choice->prev = (struct lys_node *)choice; |
| 2717 | retval = (struct lys_node *)choice; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2718 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 2719 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 2720 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2721 | goto error; |
| 2722 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2723 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 2724 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 2725 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2726 | /* insert the node into the schema tree */ |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 2727 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2728 | goto error; |
| 2729 | } |
| 2730 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2731 | /* process choice's specific children */ |
| 2732 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2733 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2734 | /* garbage */ |
| 2735 | lyxml_free_elem(module->ctx, sub); |
| 2736 | continue; |
| 2737 | } |
| 2738 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2739 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2740 | if (!(node = read_yin_container(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, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2744 | if (!(node = read_yin_leaflist(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, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2748 | if (!(node = read_yin_leaf(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, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2752 | if (!(node = read_yin_list(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, "case")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2756 | if (!(node = read_yin_case(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2757 | goto error; |
| 2758 | } |
| 2759 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2760 | if (!(node = read_yin_anyxml(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2761 | goto error; |
| 2762 | } |
| 2763 | } else if (!strcmp(sub->name, "default")) { |
| 2764 | if (dflt_str) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2765 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2766 | goto error; |
| 2767 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2768 | GETVAL(dflt_str, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2769 | } else if (!strcmp(sub->name, "mandatory")) { |
| 2770 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2771 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2772 | goto error; |
| 2773 | } |
| 2774 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2775 | * multiple mandatory statements with the "false" value |
| 2776 | */ |
| 2777 | f_mand = 1; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2778 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2779 | GETVAL(value, sub, "value"); |
| 2780 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2781 | choice->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2782 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2783 | choice->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2784 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2785 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2786 | goto error; |
| 2787 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2788 | } else if (!strcmp(sub->name, "when")) { |
| 2789 | if (choice->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2790 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2791 | goto error; |
| 2792 | } |
| 2793 | |
| 2794 | choice->when = read_yin_when(module, sub); |
| 2795 | if (!choice->when) { |
| 2796 | goto error; |
| 2797 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 2798 | if (lyxp_syntax_check(choice->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2799 | goto error; |
| 2800 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2801 | } else if (!strcmp(sub->name, "if-feature")) { |
| 2802 | c_ftrs++; |
| 2803 | |
| 2804 | /* skip lyxml_free_elem() at the end of the loop, the sub node is processed later */ |
| 2805 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2806 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2807 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2808 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2809 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2810 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2811 | node = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2812 | lyxml_free_elem(ctx, sub); |
| 2813 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2814 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2815 | if (c_ftrs) { |
| 2816 | choice->features = calloc(c_ftrs, sizeof *choice->features); |
| 2817 | } |
| 2818 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2819 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2820 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 2821 | if (unres_schema_add_str(module, unres, &choice->features[choice->features_size++], UNRES_IFFEAT, value, LOGLINE(sub)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2822 | goto error; |
| 2823 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2824 | } |
| 2825 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2826 | /* check - default is prohibited in combination with mandatory */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2827 | if (dflt_str && (choice->flags & LYS_MAND_TRUE)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2828 | LOGVAL(LYE_SPEC, LOGLINE(yin), |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2829 | "The \"default\" statement MUST NOT be present on choices where \"mandatory\" is true."); |
| 2830 | goto error; |
| 2831 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2832 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2833 | /* link default with the case */ |
| 2834 | if (dflt_str) { |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 2835 | if (unres_schema_add_str(module, unres, choice, UNRES_CHOICE_DFLT, dflt_str, LOGLINE(yin)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2836 | goto error; |
| 2837 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2838 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2839 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2840 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2841 | |
| 2842 | error: |
| 2843 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2844 | lys_node_free(retval); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2845 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2846 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2847 | } |
| 2848 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2849 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2850 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2851 | 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] | 2852 | struct unres_schema *unres) |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2853 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2854 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2855 | struct lys_node_leaf *anyxml; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2856 | struct lyxml_elem *sub, *next; |
| 2857 | const char *value; |
| 2858 | int r; |
| 2859 | int f_mand = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2860 | int c_must = 0, c_ftrs = 0; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2861 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2862 | anyxml = calloc(1, sizeof *anyxml); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2863 | anyxml->nodetype = LYS_ANYXML; |
| 2864 | anyxml->prev = (struct lys_node *)anyxml; |
| 2865 | retval = (struct lys_node *)anyxml; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2866 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 2867 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 2868 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2869 | goto error; |
| 2870 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2871 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 2872 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 2873 | |
| 2874 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2875 | goto error; |
| 2876 | } |
| 2877 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2878 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2879 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2880 | /* garbage */ |
| 2881 | lyxml_free_elem(module->ctx, sub); |
| 2882 | continue; |
| 2883 | } |
| 2884 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2885 | if (!strcmp(sub->name, "mandatory")) { |
| 2886 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2887 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2888 | goto error; |
| 2889 | } |
| 2890 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2891 | * multiple mandatory statements with the "false" value |
| 2892 | */ |
| 2893 | f_mand = 1; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2894 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2895 | GETVAL(value, sub, "value"); |
| 2896 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2897 | anyxml->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2898 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2899 | anyxml->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2900 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2901 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2902 | goto error; |
| 2903 | } |
| 2904 | /* else false is the default value, so we can ignore it */ |
| 2905 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2906 | } else if (!strcmp(sub->name, "when")) { |
| 2907 | if (anyxml->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2908 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2909 | goto error; |
| 2910 | } |
| 2911 | |
| 2912 | anyxml->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2913 | if (!anyxml->when) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2914 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2915 | goto error; |
| 2916 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 2917 | if (lyxp_syntax_check(anyxml->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2918 | goto error; |
| 2919 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2920 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2921 | } else if (!strcmp(sub->name, "must")) { |
| 2922 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2923 | } else if (!strcmp(sub->name, "if-feature")) { |
| 2924 | c_ftrs++; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2925 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2926 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2927 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2928 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2929 | } |
| 2930 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2931 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2932 | /* middle part - process nodes with cardinality of 0..n */ |
| 2933 | if (c_must) { |
| 2934 | anyxml->must = calloc(c_must, sizeof *anyxml->must); |
| 2935 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2936 | if (c_ftrs) { |
| 2937 | anyxml->features = calloc(c_ftrs, sizeof *anyxml->features); |
| 2938 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2939 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2940 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2941 | if (!strcmp(sub->name, "must")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2942 | r = fill_yin_must(module, sub, &anyxml->must[anyxml->must_size++]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2943 | if (r) { |
| 2944 | goto error; |
| 2945 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 2946 | if (lyxp_syntax_check(anyxml->must[anyxml->must_size-1].expr, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2947 | goto error; |
| 2948 | } |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 2949 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2950 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 2951 | if (unres_schema_add_str(module, unres, &anyxml->features[anyxml->features_size++], UNRES_IFFEAT, value, LOGLINE(sub)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2952 | goto error; |
| 2953 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2954 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2955 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2956 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2957 | return retval; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2958 | |
| 2959 | error: |
| 2960 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2961 | lys_node_free(retval); |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2962 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2963 | return NULL; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2964 | } |
| 2965 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2966 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2967 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2968 | 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] | 2969 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2970 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2971 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2972 | struct lys_node_leaf *leaf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2973 | struct lyxml_elem *sub, *next; |
| 2974 | const char *value; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2975 | int r, has_type = 0, dflt_line; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2976 | int c_must = 0, c_ftrs = 0, f_mand = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2977 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2978 | leaf = calloc(1, sizeof *leaf); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2979 | leaf->nodetype = LYS_LEAF; |
| 2980 | leaf->prev = (struct lys_node *)leaf; |
| 2981 | retval = (struct lys_node *)leaf; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2982 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 2983 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 2984 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2985 | goto error; |
| 2986 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2987 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 2988 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 2989 | |
| 2990 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2991 | goto error; |
| 2992 | } |
| 2993 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2994 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2995 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2996 | /* garbage */ |
| 2997 | lyxml_free_elem(module->ctx, sub); |
| 2998 | continue; |
| 2999 | } |
| 3000 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3001 | if (!strcmp(sub->name, "type")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3002 | if (leaf->type.der || has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3003 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3004 | goto error; |
| 3005 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3006 | if (fill_yin_type(module, parent, sub, &leaf->type, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3007 | goto error; |
| 3008 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3009 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3010 | } else if (!strcmp(sub->name, "default")) { |
| 3011 | if (leaf->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3012 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3013 | goto error; |
| 3014 | } |
| 3015 | GETVAL(value, sub, "value"); |
| 3016 | leaf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3017 | dflt_line = LOGLINE(sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3018 | } else if (!strcmp(sub->name, "units")) { |
| 3019 | if (leaf->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3020 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3021 | goto error; |
| 3022 | } |
| 3023 | GETVAL(value, sub, "name"); |
| 3024 | leaf->units = lydict_insert(module->ctx, value, strlen(value)); |
| 3025 | } else if (!strcmp(sub->name, "mandatory")) { |
| 3026 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3027 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3028 | goto error; |
| 3029 | } |
| 3030 | /* just checking the flags in leaf is not sufficient, we would allow |
| 3031 | * multiple mandatory statements with the "false" value |
| 3032 | */ |
| 3033 | f_mand = 1; |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3034 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3035 | GETVAL(value, sub, "value"); |
| 3036 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3037 | leaf->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3038 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3039 | leaf->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3040 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3041 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3042 | goto error; |
| 3043 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3044 | } else if (!strcmp(sub->name, "when")) { |
| 3045 | if (leaf->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3046 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3047 | goto error; |
| 3048 | } |
| 3049 | |
| 3050 | leaf->when = read_yin_when(module, sub); |
| 3051 | if (!leaf->when) { |
| 3052 | goto error; |
| 3053 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 3054 | if (lyxp_syntax_check(leaf->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3055 | goto error; |
| 3056 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3057 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3058 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3059 | c_must++; |
| 3060 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3061 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3062 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3063 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3064 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3065 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3066 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3067 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3068 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3069 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3070 | lyxml_free_elem(module->ctx, sub); |
| 3071 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3072 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3073 | /* check mandatory parameters */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3074 | if (!has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3075 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3076 | goto error; |
| 3077 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3078 | if (leaf->dflt) { |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3079 | if (unres_schema_add_str(module, unres, &leaf->type, UNRES_TYPE_DFLT, leaf->dflt, dflt_line) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3080 | goto error; |
| 3081 | } |
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 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3084 | /* middle part - process nodes with cardinality of 0..n */ |
| 3085 | if (c_must) { |
| 3086 | leaf->must = calloc(c_must, sizeof *leaf->must); |
| 3087 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3088 | if (c_ftrs) { |
| 3089 | leaf->features = calloc(c_ftrs, sizeof *leaf->features); |
| 3090 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3091 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3092 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3093 | if (!strcmp(sub->name, "must")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3094 | r = fill_yin_must(module, sub, &leaf->must[leaf->must_size++]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3095 | if (r) { |
| 3096 | goto error; |
| 3097 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 3098 | if (lyxp_syntax_check(leaf->must[leaf->must_size-1].expr, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3099 | goto error; |
| 3100 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3101 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3102 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3103 | if (unres_schema_add_str(module, unres, &leaf->features[leaf->features_size++], UNRES_IFFEAT, value, LOGLINE(sub)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3104 | goto error; |
| 3105 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3106 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3107 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3108 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3109 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3110 | |
| 3111 | error: |
| 3112 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3113 | lys_node_free(retval); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3114 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3115 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3116 | } |
| 3117 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3118 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3119 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3120 | 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] | 3121 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3122 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3123 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3124 | struct lys_node_leaflist *llist; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3125 | struct lyxml_elem *sub, *next; |
| 3126 | const char *value; |
| 3127 | char *endptr; |
| 3128 | unsigned long val; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3129 | int r, has_type = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3130 | int c_must = 0, c_ftrs = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3131 | int f_ordr = 0, f_min = 0, f_max = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3132 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3133 | llist = calloc(1, sizeof *llist); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3134 | llist->nodetype = LYS_LEAFLIST; |
| 3135 | llist->prev = (struct lys_node *)llist; |
| 3136 | retval = (struct lys_node *)llist; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3137 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3138 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3139 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3140 | goto error; |
| 3141 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3142 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3143 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3144 | |
| 3145 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3146 | goto error; |
| 3147 | } |
| 3148 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3149 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3150 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3151 | /* garbage */ |
| 3152 | lyxml_free_elem(module->ctx, sub); |
| 3153 | continue; |
| 3154 | } |
| 3155 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3156 | if (!strcmp(sub->name, "type")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3157 | if (llist->type.der || has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3158 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3159 | goto error; |
| 3160 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3161 | if (fill_yin_type(module, parent, sub, &llist->type, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3162 | goto error; |
| 3163 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3164 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3165 | } else if (!strcmp(sub->name, "units")) { |
| 3166 | if (llist->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3167 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3168 | goto error; |
| 3169 | } |
| 3170 | GETVAL(value, sub, "name"); |
| 3171 | llist->units = lydict_insert(module->ctx, value, strlen(value)); |
| 3172 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 3173 | if (f_ordr) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3174 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3175 | goto error; |
| 3176 | } |
| 3177 | /* just checking the flags in llist is not sufficient, we would |
| 3178 | * allow multiple ordered-by statements with the "system" value |
| 3179 | */ |
| 3180 | f_ordr = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3181 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3182 | if (llist->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3183 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 3184 | * state data |
| 3185 | */ |
| 3186 | lyxml_free_elem(module->ctx, sub); |
| 3187 | continue; |
| 3188 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3189 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3190 | GETVAL(value, sub, "value"); |
| 3191 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3192 | llist->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3193 | } else if (strcmp(value, "system")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3194 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3195 | goto error; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3196 | } /* else system is the default value, so we can ignore it */ |
| 3197 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3198 | } else if (!strcmp(sub->name, "must")) { |
| 3199 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3200 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3201 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3202 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3203 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3204 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3205 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3206 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3207 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3208 | goto error; |
| 3209 | } |
| 3210 | f_min = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3211 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3212 | GETVAL(value, sub, "value"); |
| 3213 | while (isspace(value[0])) { |
| 3214 | value++; |
| 3215 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3216 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3217 | /* convert it to uint32_t */ |
| 3218 | errno = 0; |
| 3219 | endptr = NULL; |
| 3220 | val = strtoul(value, &endptr, 10); |
| 3221 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3222 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3223 | goto error; |
| 3224 | } |
| 3225 | llist->min = (uint32_t) val; |
| 3226 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3227 | if (f_max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3228 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3229 | goto error; |
| 3230 | } |
| 3231 | f_max = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3232 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3233 | GETVAL(value, sub, "value"); |
| 3234 | while (isspace(value[0])) { |
| 3235 | value++; |
| 3236 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3237 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3238 | /* convert it to uint32_t */ |
| 3239 | errno = 0; |
| 3240 | endptr = NULL; |
| 3241 | val = strtoul(value, &endptr, 10); |
| 3242 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3243 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3244 | goto error; |
| 3245 | } |
| 3246 | llist->max = (uint32_t) val; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3247 | } else if (!strcmp(sub->name, "when")) { |
| 3248 | if (llist->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3249 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3250 | goto error; |
| 3251 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3252 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3253 | llist->when = read_yin_when(module, sub); |
| 3254 | if (!llist->when) { |
| 3255 | goto error; |
| 3256 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 3257 | if (lyxp_syntax_check(llist->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3258 | goto error; |
| 3259 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3260 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3261 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3262 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3263 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3264 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3265 | lyxml_free_elem(module->ctx, sub); |
| 3266 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3267 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3268 | /* check constraints */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3269 | if (!has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3270 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3271 | goto error; |
| 3272 | } |
| 3273 | if (llist->max && llist->min > llist->max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3274 | LOGVAL(LYE_SPEC, LOGLINE(yin), "\"min-elements\" is bigger than \"max-elements\"."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3275 | goto error; |
| 3276 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3277 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3278 | /* middle part - process nodes with cardinality of 0..n */ |
| 3279 | if (c_must) { |
| 3280 | llist->must = calloc(c_must, sizeof *llist->must); |
| 3281 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3282 | if (c_ftrs) { |
| 3283 | llist->features = calloc(c_ftrs, sizeof *llist->features); |
| 3284 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3285 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3286 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3287 | if (!strcmp(sub->name, "must")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3288 | r = fill_yin_must(module, sub, &llist->must[llist->must_size++]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3289 | if (r) { |
| 3290 | goto error; |
| 3291 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 3292 | if (lyxp_syntax_check(llist->must[llist->must_size-1].expr, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3293 | goto error; |
| 3294 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3295 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3296 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3297 | if (unres_schema_add_str(module, unres, &llist->features[llist->features_size++], UNRES_IFFEAT, value, |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3298 | LOGLINE(sub)) == -1) { |
| 3299 | goto error; |
| 3300 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3301 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3302 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3303 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3304 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3305 | |
| 3306 | error: |
| 3307 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3308 | lys_node_free(retval); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3309 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3310 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3311 | } |
| 3312 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3313 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3314 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3315 | read_yin_list(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 3316 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3317 | { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3318 | struct lys_node *retval, *node; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3319 | struct lys_node_list *list; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3320 | struct lyxml_elem *sub, *next, root, uniq; |
Michal Vasko | e38af6e | 2015-08-03 14:39:27 +0200 | [diff] [blame] | 3321 | int r, key_line; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3322 | 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] | 3323 | int f_ordr = 0, f_max = 0, f_min = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3324 | const char *key_str = NULL, *value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3325 | char *auxs; |
| 3326 | unsigned long val; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3327 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3328 | /* init */ |
| 3329 | memset(&root, 0, sizeof root); |
| 3330 | memset(&uniq, 0, sizeof uniq); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3331 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3332 | list = calloc(1, sizeof *list); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3333 | list->nodetype = LYS_LIST; |
| 3334 | list->prev = (struct lys_node *)list; |
| 3335 | retval = (struct lys_node *)list; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3336 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3337 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3338 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3339 | goto error; |
| 3340 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3341 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3342 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3343 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3344 | /* process list's specific children */ |
| 3345 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3346 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3347 | /* garbage */ |
| 3348 | lyxml_free_elem(module->ctx, sub); |
| 3349 | continue; |
| 3350 | } |
| 3351 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3352 | /* data statements */ |
| 3353 | if (!strcmp(sub->name, "container") || |
| 3354 | !strcmp(sub->name, "leaf-list") || |
| 3355 | !strcmp(sub->name, "leaf") || |
| 3356 | !strcmp(sub->name, "list") || |
| 3357 | !strcmp(sub->name, "choice") || |
| 3358 | !strcmp(sub->name, "uses") || |
| 3359 | !strcmp(sub->name, "grouping") || |
| 3360 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3361 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 3362 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3363 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3364 | /* array counters */ |
| 3365 | } else if (!strcmp(sub->name, "key")) { |
| 3366 | /* check cardinality 0..1 */ |
| 3367 | if (list->keys_size) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3368 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, list->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3369 | goto error; |
| 3370 | } |
Radek Krejci | d7f0d01 | 2015-05-25 15:04:52 +0200 | [diff] [blame] | 3371 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3372 | /* count the number of keys */ |
| 3373 | GETVAL(value, sub, "value"); |
| 3374 | key_str = value; |
Michal Vasko | e38af6e | 2015-08-03 14:39:27 +0200 | [diff] [blame] | 3375 | key_line = LOGLINE(sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3376 | while ((value = strpbrk(value, " \t\n"))) { |
| 3377 | list->keys_size++; |
| 3378 | while (isspace(*value)) { |
| 3379 | value++; |
| 3380 | } |
| 3381 | } |
| 3382 | list->keys_size++; |
| 3383 | list->keys = calloc(list->keys_size, sizeof *list->keys); |
| 3384 | } else if (!strcmp(sub->name, "unique")) { |
| 3385 | c_uniq++; |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3386 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 3387 | lyxml_add_child(module->ctx, &uniq, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3388 | } else if (!strcmp(sub->name, "typedef")) { |
| 3389 | c_tpdf++; |
| 3390 | } else if (!strcmp(sub->name, "must")) { |
| 3391 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3392 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3393 | c_ftrs++; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3394 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3395 | /* optional stetments */ |
| 3396 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 3397 | if (f_ordr) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3398 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3399 | goto error; |
| 3400 | } |
| 3401 | /* just checking the flags in llist is not sufficient, we would |
| 3402 | * allow multiple ordered-by statements with the "system" value |
| 3403 | */ |
| 3404 | f_ordr = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3405 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3406 | if (list->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3407 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 3408 | * state data |
| 3409 | */ |
| 3410 | lyxml_free_elem(module->ctx, sub); |
| 3411 | continue; |
| 3412 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3413 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3414 | GETVAL(value, sub, "value"); |
| 3415 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3416 | list->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3417 | } else if (strcmp(value, "system")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3418 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3419 | goto error; |
| 3420 | } |
| 3421 | /* else system is the default value, so we can ignore it */ |
| 3422 | lyxml_free_elem(module->ctx, sub); |
| 3423 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3424 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3425 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3426 | goto error; |
| 3427 | } |
| 3428 | f_min = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3429 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3430 | GETVAL(value, sub, "value"); |
| 3431 | while (isspace(value[0])) { |
| 3432 | value++; |
| 3433 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3434 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3435 | /* convert it to uint32_t */ |
| 3436 | errno = 0; |
| 3437 | auxs = NULL; |
| 3438 | val = strtoul(value, &auxs, 10); |
| 3439 | if (*auxs || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3440 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3441 | goto error; |
| 3442 | } |
| 3443 | list->min = (uint32_t) val; |
| 3444 | lyxml_free_elem(module->ctx, sub); |
| 3445 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3446 | if (f_max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3447 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3448 | goto error; |
| 3449 | } |
| 3450 | f_max = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3451 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3452 | GETVAL(value, sub, "value"); |
| 3453 | while (isspace(value[0])) { |
| 3454 | value++; |
| 3455 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3456 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3457 | /* convert it to uint32_t */ |
| 3458 | errno = 0; |
| 3459 | auxs = NULL; |
| 3460 | val = strtoul(value, &auxs, 10); |
| 3461 | if (*auxs || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3462 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3463 | goto error; |
| 3464 | } |
| 3465 | list->max = (uint32_t) val; |
| 3466 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3467 | } else if (!strcmp(sub->name, "when")) { |
| 3468 | if (list->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3469 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3470 | goto error; |
| 3471 | } |
| 3472 | |
| 3473 | list->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3474 | if (!list->when) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3475 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3476 | goto error; |
| 3477 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 3478 | if (lyxp_syntax_check(list->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3479 | goto error; |
| 3480 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3481 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3482 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3483 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3484 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3485 | } |
| 3486 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3487 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3488 | /* check - if list is configuration, key statement is mandatory */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3489 | if ((list->flags & LYS_CONFIG_W) && !key_str) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3490 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "key", "list"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3491 | goto error; |
| 3492 | } |
| 3493 | if (list->max && list->min > list->max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3494 | LOGVAL(LYE_SPEC, LOGLINE(yin), "\"min-elements\" is bigger than \"max-elements\"."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3495 | goto error; |
| 3496 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3497 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3498 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3499 | if (c_tpdf) { |
| 3500 | list->tpdf = calloc(c_tpdf, sizeof *list->tpdf); |
| 3501 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3502 | if (c_must) { |
| 3503 | list->must = calloc(c_must, sizeof *list->must); |
| 3504 | } |
| 3505 | if (c_ftrs) { |
| 3506 | list->features = calloc(c_ftrs, sizeof *list->features); |
| 3507 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3508 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3509 | if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3510 | r = fill_yin_typedef(module, retval, sub, &list->tpdf[list->tpdf_size++], unres); |
Radek Krejci | d7f0d01 | 2015-05-25 15:04:52 +0200 | [diff] [blame] | 3511 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3512 | if (r) { |
| 3513 | goto error; |
| 3514 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3515 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3516 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3517 | if (unres_schema_add_str(module, unres, &list->features[list->features_size++], UNRES_IFFEAT, value, LOGLINE(sub)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3518 | goto error; |
| 3519 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3520 | } else if (!strcmp(sub->name, "must")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3521 | r = fill_yin_must(module, sub, &list->must[list->must_size++]); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3522 | if (r) { |
| 3523 | goto error; |
| 3524 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 3525 | if (lyxp_syntax_check(list->must[list->must_size-1].expr, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3526 | goto error; |
| 3527 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3528 | } |
| 3529 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 3530 | |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3531 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3532 | goto error; |
| 3533 | } |
| 3534 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3535 | /* last part - process data nodes */ |
| 3536 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3537 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3538 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3539 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3540 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3541 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3542 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3543 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3544 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3545 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3546 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3547 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3548 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3549 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3550 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3551 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3552 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Michal Vasko | c07187d | 2015-08-13 15:20:57 +0200 | [diff] [blame] | 3553 | } else { |
| 3554 | LOGINT; |
| 3555 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3556 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3557 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3558 | goto error; |
| 3559 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3560 | |
| 3561 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3562 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3563 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3564 | if (!key_str) { |
| 3565 | /* config false list without a key */ |
| 3566 | return retval; |
| 3567 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3568 | if (unres_schema_add_str(module, unres, list, UNRES_LIST_KEYS, key_str, key_line) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3569 | goto error; |
| 3570 | } |
Radek Krejci | 812b10a | 2015-05-28 16:48:25 +0200 | [diff] [blame] | 3571 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3572 | /* process unique statements */ |
| 3573 | if (c_uniq) { |
| 3574 | list->unique = calloc(c_uniq, sizeof *list->unique); |
| 3575 | } |
| 3576 | LY_TREE_FOR_SAFE(uniq.child, next, sub) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3577 | /* HACK for unres */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3578 | list->unique[list->unique_size++].leafs = (struct lys_node_leaf **)list; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3579 | GETVAL(value, sub, "tag"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3580 | if (unres_schema_add_str(module, unres, &list->unique[list->unique_size-1], UNRES_LIST_UNIQ, value, |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3581 | LOGLINE(sub)) == -1) { |
| 3582 | goto error; |
| 3583 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 3584 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3585 | lyxml_free_elem(module->ctx, sub); |
| 3586 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 3587 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3588 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3589 | |
| 3590 | error: |
| 3591 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3592 | lys_node_free(retval); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3593 | while (root.child) { |
| 3594 | lyxml_free_elem(module->ctx, root.child); |
| 3595 | } |
| 3596 | while (uniq.child) { |
| 3597 | lyxml_free_elem(module->ctx, uniq.child); |
| 3598 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3599 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3600 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3601 | } |
| 3602 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3603 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3604 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3605 | read_yin_container(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 3606 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3607 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3608 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3609 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3610 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3611 | struct lys_node_container *cont; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3612 | const char *value; |
| 3613 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3614 | int c_tpdf = 0, c_must = 0, c_ftrs = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3615 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3616 | /* init */ |
| 3617 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3618 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3619 | cont = calloc(1, sizeof *cont); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3620 | cont->nodetype = LYS_CONTAINER; |
| 3621 | cont->prev = (struct lys_node *)cont; |
| 3622 | retval = (struct lys_node *)cont; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3623 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3624 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3625 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3626 | goto error; |
| 3627 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3628 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3629 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3630 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3631 | /* process container's specific children */ |
| 3632 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3633 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3634 | /* garbage */ |
| 3635 | lyxml_free_elem(module->ctx, sub); |
| 3636 | continue; |
| 3637 | } |
| 3638 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3639 | if (!strcmp(sub->name, "presence")) { |
| 3640 | if (cont->presence) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3641 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3642 | goto error; |
| 3643 | } |
| 3644 | GETVAL(value, sub, "value"); |
| 3645 | cont->presence = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 3646 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3647 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3648 | } else if (!strcmp(sub->name, "when")) { |
| 3649 | if (cont->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3650 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3651 | goto error; |
| 3652 | } |
| 3653 | |
| 3654 | cont->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3655 | if (!cont->when) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3656 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3657 | goto error; |
| 3658 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 3659 | if (lyxp_syntax_check(cont->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3660 | goto error; |
| 3661 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3662 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3663 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3664 | /* data statements */ |
| 3665 | } else if (!strcmp(sub->name, "container") || |
| 3666 | !strcmp(sub->name, "leaf-list") || |
| 3667 | !strcmp(sub->name, "leaf") || |
| 3668 | !strcmp(sub->name, "list") || |
| 3669 | !strcmp(sub->name, "choice") || |
| 3670 | !strcmp(sub->name, "uses") || |
| 3671 | !strcmp(sub->name, "grouping") || |
| 3672 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3673 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 3674 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3675 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3676 | /* array counters */ |
| 3677 | } else if (!strcmp(sub->name, "typedef")) { |
| 3678 | c_tpdf++; |
| 3679 | } else if (!strcmp(sub->name, "must")) { |
| 3680 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3681 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3682 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3683 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3684 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3685 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3686 | } |
| 3687 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3688 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3689 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3690 | if (c_tpdf) { |
| 3691 | cont->tpdf = calloc(c_tpdf, sizeof *cont->tpdf); |
| 3692 | } |
| 3693 | if (c_must) { |
| 3694 | cont->must = calloc(c_must, sizeof *cont->must); |
| 3695 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3696 | if (c_ftrs) { |
| 3697 | cont->features = calloc(c_ftrs, sizeof *cont->features); |
| 3698 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 3699 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3700 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3701 | if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3702 | r = fill_yin_typedef(module, retval, sub, &cont->tpdf[cont->tpdf_size++], unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3703 | if (r) { |
| 3704 | goto error; |
| 3705 | } |
| 3706 | } else if (!strcmp(sub->name, "must")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3707 | r = fill_yin_must(module, sub, &cont->must[cont->must_size++]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3708 | if (r) { |
| 3709 | goto error; |
| 3710 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 3711 | if (lyxp_syntax_check(cont->must[cont->must_size-1].expr, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3712 | goto error; |
| 3713 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3714 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3715 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3716 | if (unres_schema_add_str(module, unres, &cont->features[cont->features_size++], UNRES_IFFEAT, value, |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3717 | LOGLINE(sub)) == -1) { |
| 3718 | goto error; |
| 3719 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3720 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3721 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3722 | |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3723 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3724 | goto error; |
| 3725 | } |
| 3726 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3727 | /* last part - process data nodes */ |
| 3728 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3729 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3730 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3731 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3732 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3733 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3734 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3735 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3736 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3737 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3738 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3739 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3740 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3741 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3742 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3743 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3744 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3745 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3746 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3747 | goto error; |
| 3748 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3749 | |
| 3750 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3751 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3752 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3753 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3754 | |
| 3755 | error: |
| 3756 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3757 | lys_node_free(retval); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3758 | while (root.child) { |
| 3759 | lyxml_free_elem(module->ctx, root.child); |
| 3760 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3761 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3762 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3763 | } |
| 3764 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3765 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3766 | static struct lys_node * |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3767 | 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] | 3768 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3769 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3770 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3771 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3772 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3773 | struct lys_node_grp *grp; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3774 | int r; |
| 3775 | int c_tpdf = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3776 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3777 | /* init */ |
| 3778 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3779 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3780 | grp = calloc(1, sizeof *grp); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3781 | grp->nodetype = LYS_GROUPING; |
| 3782 | grp->prev = (struct lys_node *)grp; |
| 3783 | retval = (struct lys_node *)grp; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3784 | |
Michal Vasko | 71e1aa8 | 2015-08-12 12:17:51 +0200 | [diff] [blame] | 3785 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3786 | goto error; |
| 3787 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3788 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3789 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3790 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3791 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3792 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3793 | /* garbage */ |
| 3794 | lyxml_free_elem(module->ctx, sub); |
| 3795 | continue; |
| 3796 | } |
| 3797 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3798 | /* data statements */ |
| 3799 | if (!strcmp(sub->name, "container") || |
| 3800 | !strcmp(sub->name, "leaf-list") || |
| 3801 | !strcmp(sub->name, "leaf") || |
| 3802 | !strcmp(sub->name, "list") || |
| 3803 | !strcmp(sub->name, "choice") || |
| 3804 | !strcmp(sub->name, "uses") || |
| 3805 | !strcmp(sub->name, "grouping") || |
| 3806 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3807 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 3808 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3809 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3810 | /* array counters */ |
| 3811 | } else if (!strcmp(sub->name, "typedef")) { |
| 3812 | c_tpdf++; |
| 3813 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3814 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3815 | goto error; |
| 3816 | } |
| 3817 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3818 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3819 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3820 | if (c_tpdf) { |
| 3821 | grp->tpdf = calloc(c_tpdf, sizeof *grp->tpdf); |
| 3822 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3823 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3824 | r = fill_yin_typedef(module, retval, sub, &grp->tpdf[grp->tpdf_size++], unres); |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 3825 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3826 | if (r) { |
| 3827 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3828 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3829 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3830 | |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3831 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3832 | goto error; |
| 3833 | } |
| 3834 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3835 | /* last part - process data nodes */ |
| 3836 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3837 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3838 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3839 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3840 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3841 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3842 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3843 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3844 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3845 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3846 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3847 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3848 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3849 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3850 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3851 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3852 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3853 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3854 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3855 | goto error; |
| 3856 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3857 | |
| 3858 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3859 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3860 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3861 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3862 | |
| 3863 | error: |
| 3864 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3865 | lys_node_free(retval); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3866 | while (root.child) { |
| 3867 | lyxml_free_elem(module->ctx, root.child); |
| 3868 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3869 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3870 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3871 | } |
| 3872 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3873 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3874 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3875 | read_yin_input_output(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 3876 | struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3877 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3878 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3879 | struct lys_node *node = NULL; |
Radek Krejci | 31fc30d | 2015-08-13 08:27:38 +0200 | [diff] [blame] | 3880 | struct lys_node *retval = NULL; |
Radek Krejci | 4608ada | 2015-08-05 16:04:37 +0200 | [diff] [blame] | 3881 | struct lys_node_rpc_inout *inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3882 | int r; |
| 3883 | int c_tpdf = 0; |
| 3884 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3885 | /* init */ |
| 3886 | memset(&root, 0, sizeof root); |
| 3887 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3888 | inout = calloc(1, sizeof *inout); |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 3889 | inout->prev = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3890 | |
| 3891 | if (!strcmp(yin->name, "input")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3892 | inout->nodetype = LYS_INPUT; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3893 | } else if (!strcmp(yin->name, "output")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3894 | inout->nodetype = LYS_OUTPUT; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3895 | } else { |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 3896 | LOGINT; |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 3897 | free(inout); |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 3898 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3899 | } |
| 3900 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3901 | retval = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3902 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 3903 | if (read_yin_common(module, parent, retval, yin, OPT_MODULE | OPT_NACMEXT)) { |
Michal Vasko | ebeac94 | 2015-06-15 12:11:50 +0200 | [diff] [blame] | 3904 | goto error; |
| 3905 | } |
| 3906 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3907 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3908 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3909 | /* data statements */ |
| 3910 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3911 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3912 | /* garbage */ |
| 3913 | lyxml_free_elem(module->ctx, sub); |
| 3914 | continue; |
| 3915 | } |
| 3916 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3917 | if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3918 | !strcmp(sub->name, "leaf-list") || |
| 3919 | !strcmp(sub->name, "leaf") || |
| 3920 | !strcmp(sub->name, "list") || |
| 3921 | !strcmp(sub->name, "choice") || |
| 3922 | !strcmp(sub->name, "uses") || |
| 3923 | !strcmp(sub->name, "grouping") || |
| 3924 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3925 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 3926 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3927 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3928 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3929 | } else if (!strcmp(sub->name, "typedef")) { |
| 3930 | c_tpdf++; |
Radek Krejci | d2bfa79 | 2015-07-02 16:45:29 +0200 | [diff] [blame] | 3931 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3932 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3933 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3934 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3935 | } |
| 3936 | } |
| 3937 | |
| 3938 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3939 | if (c_tpdf) { |
| 3940 | inout->tpdf = calloc(c_tpdf, sizeof *inout->tpdf); |
| 3941 | } |
| 3942 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3943 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3944 | r = fill_yin_typedef(module, retval, sub, &inout->tpdf[inout->tpdf_size++], unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3945 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3946 | if (r) { |
| 3947 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3948 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3949 | } |
| 3950 | |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3951 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3952 | goto error; |
| 3953 | } |
| 3954 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3955 | /* last part - process data nodes */ |
| 3956 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3957 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3958 | node = read_yin_container(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3959 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3960 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3961 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3962 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3963 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3964 | node = read_yin_list(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3965 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3966 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3967 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3968 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3969 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3970 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3971 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3972 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3973 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3974 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3975 | goto error; |
| 3976 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3977 | |
| 3978 | lyxml_free_elem(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3979 | } |
| 3980 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3981 | return retval; |
| 3982 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3983 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3984 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3985 | lys_node_free(retval); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 3986 | while (root.child) { |
| 3987 | lyxml_free_elem(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3988 | } |
| 3989 | |
| 3990 | return NULL; |
| 3991 | } |
| 3992 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3993 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3994 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3995 | read_yin_notif(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 3996 | struct unres_schema *unres) |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 3997 | { |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 3998 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3999 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4000 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4001 | struct lys_node_notif *notif; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4002 | const char *value; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4003 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4004 | int c_tpdf = 0, c_ftrs = 0; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4005 | |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 4006 | memset(&root, 0, sizeof root); |
| 4007 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4008 | notif = calloc(1, sizeof *notif); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4009 | notif->nodetype = LYS_NOTIF; |
| 4010 | notif->prev = (struct lys_node *)notif; |
| 4011 | retval = (struct lys_node *)notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4012 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4013 | 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] | 4014 | goto error; |
| 4015 | } |
| 4016 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4017 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4018 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4019 | /* process rpc's specific children */ |
| 4020 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4021 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4022 | /* garbage */ |
| 4023 | lyxml_free_elem(module->ctx, sub); |
| 4024 | continue; |
| 4025 | } |
| 4026 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4027 | /* data statements */ |
| 4028 | if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4029 | !strcmp(sub->name, "leaf-list") || |
| 4030 | !strcmp(sub->name, "leaf") || |
| 4031 | !strcmp(sub->name, "list") || |
| 4032 | !strcmp(sub->name, "choice") || |
| 4033 | !strcmp(sub->name, "uses") || |
| 4034 | !strcmp(sub->name, "grouping") || |
| 4035 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4036 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 4037 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4038 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4039 | /* array counters */ |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4040 | } else if (!strcmp(sub->name, "typedef")) { |
| 4041 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4042 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4043 | c_ftrs++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4044 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4045 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4046 | goto error; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4047 | } |
| 4048 | } |
| 4049 | |
| 4050 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4051 | if (c_tpdf) { |
| 4052 | notif->tpdf = calloc(c_tpdf, sizeof *notif->tpdf); |
| 4053 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4054 | if (c_ftrs) { |
| 4055 | notif->features = calloc(c_ftrs, sizeof *notif->features); |
| 4056 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4057 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4058 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4059 | if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4060 | r = fill_yin_typedef(module, retval, sub, ¬if->tpdf[notif->tpdf_size++], unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4061 | |
| 4062 | if (r) { |
| 4063 | goto error; |
| 4064 | } |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 4065 | } else if (!strcmp(sub->name, "if-features")) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4066 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 4067 | if (unres_schema_add_str(module, unres, ¬if->features[notif->features_size++], UNRES_IFFEAT, value, |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4068 | LOGLINE(sub)) == -1) { |
| 4069 | goto error; |
| 4070 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4071 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4072 | } |
| 4073 | |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4074 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4075 | goto error; |
| 4076 | } |
| 4077 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4078 | /* last part - process data nodes */ |
| 4079 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4080 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4081 | node = read_yin_container(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4082 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4083 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4084 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4085 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4086 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4087 | node = read_yin_list(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4088 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4089 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4090 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4091 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4092 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4093 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4094 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4095 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4096 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4097 | if (!node) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4098 | goto error; |
| 4099 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4100 | |
| 4101 | lyxml_free_elem(module->ctx, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4102 | } |
| 4103 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4104 | return retval; |
| 4105 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4106 | error: |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4107 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4108 | lys_node_free(retval); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4109 | while (root.child) { |
| 4110 | lyxml_free_elem(module->ctx, root.child); |
| 4111 | } |
| 4112 | |
| 4113 | return NULL; |
| 4114 | } |
| 4115 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4116 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4117 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4118 | read_yin_rpc(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 4119 | struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4120 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4121 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4122 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4123 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4124 | struct lys_node_rpc *rpc; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4125 | const char *value; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4126 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4127 | int c_tpdf = 0, c_ftrs = 0; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4128 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4129 | /* init */ |
| 4130 | memset(&root, 0, sizeof root); |
| 4131 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4132 | rpc = calloc(1, sizeof *rpc); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4133 | rpc->nodetype = LYS_RPC; |
| 4134 | rpc->prev = (struct lys_node *)rpc; |
| 4135 | retval = (struct lys_node *)rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4136 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4137 | 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] | 4138 | goto error; |
| 4139 | } |
| 4140 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4141 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4142 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4143 | /* process rpc's specific children */ |
| 4144 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4145 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4146 | /* garbage */ |
| 4147 | lyxml_free_elem(module->ctx, sub); |
| 4148 | continue; |
| 4149 | } |
| 4150 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4151 | if (!strcmp(sub->name, "input")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4152 | if (rpc->child |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4153 | && (rpc->child->nodetype == LYS_INPUT |
| 4154 | || (rpc->child->next && rpc->child->next->nodetype == LYS_INPUT))) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4155 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4156 | goto error; |
| 4157 | } |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4158 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 4159 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4160 | } else if (!strcmp(sub->name, "output")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4161 | if (rpc->child |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4162 | && (rpc->child->nodetype == LYS_INPUT |
| 4163 | || (rpc->child->next && rpc->child->next->nodetype == LYS_INPUT))) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4164 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4165 | goto error; |
| 4166 | } |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4167 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 4168 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4169 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4170 | /* data statements */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4171 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4172 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 4173 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4174 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4175 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4176 | } else if (!strcmp(sub->name, "typedef")) { |
| 4177 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4178 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4179 | c_ftrs++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4180 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4181 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4182 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4183 | } |
| 4184 | } |
| 4185 | |
| 4186 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4187 | if (c_tpdf) { |
| 4188 | rpc->tpdf = calloc(c_tpdf, sizeof *rpc->tpdf); |
| 4189 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4190 | if (c_ftrs) { |
| 4191 | rpc->features = calloc(c_ftrs, sizeof *rpc->features); |
| 4192 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4193 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4194 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4195 | if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4196 | r = fill_yin_typedef(module, retval, sub, &rpc->tpdf[rpc->tpdf_size++], unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4197 | |
| 4198 | if (r) { |
| 4199 | goto error; |
| 4200 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4201 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4202 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 4203 | if (unres_schema_add_str(module, unres, &rpc->features[rpc->features_size++], UNRES_IFFEAT, value, |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4204 | LOGLINE(sub)) == -1) { |
| 4205 | goto error; |
| 4206 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4207 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4208 | } |
| 4209 | |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4210 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4211 | goto error; |
| 4212 | } |
| 4213 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4214 | /* last part - process data nodes */ |
| 4215 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4216 | if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4217 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4218 | } else if (!strcmp(sub->name, "input")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4219 | node = read_yin_input_output(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4220 | } else if (!strcmp(sub->name, "output")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4221 | node = read_yin_input_output(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4222 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4223 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4224 | goto error; |
| 4225 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4226 | |
| 4227 | lyxml_free_elem(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4228 | } |
| 4229 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4230 | return retval; |
| 4231 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4232 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4233 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4234 | lys_node_free(retval); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 4235 | while (root.child) { |
| 4236 | lyxml_free_elem(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4237 | } |
| 4238 | |
| 4239 | return NULL; |
| 4240 | } |
| 4241 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4242 | /* logs directly |
| 4243 | * |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4244 | * resolve - referenced grouping should be bounded to the namespace (resolved) |
| 4245 | * only when uses does not appear in grouping. In a case of grouping's uses, |
| 4246 | * we just get information but we do not apply augment or refine to it. |
| 4247 | */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4248 | static struct lys_node * |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4249 | 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] | 4250 | struct unres_schema *unres) |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4251 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4252 | struct lyxml_elem *sub, *next; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4253 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4254 | struct lys_node_uses *uses; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4255 | const char *value; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4256 | int c_ref = 0, c_aug = 0, c_ftrs = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4257 | int r; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4258 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4259 | uses = calloc(1, sizeof *uses); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4260 | uses->nodetype = LYS_USES; |
| 4261 | uses->prev = (struct lys_node *)uses; |
| 4262 | retval = (struct lys_node *)uses; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4263 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4264 | GETVAL(value, yin, "name"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4265 | uses->name = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 4266 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 4267 | if (read_yin_common(module, parent, retval, yin, OPT_MODULE |
| 4268 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4269 | goto error; |
| 4270 | } |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4271 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4272 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4273 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4274 | /* get other properties of uses */ |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4275 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4276 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4277 | /* garbage */ |
| 4278 | lyxml_free_elem(module->ctx, sub); |
| 4279 | continue; |
| 4280 | } |
| 4281 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4282 | if (!strcmp(sub->name, "refine")) { |
| 4283 | c_ref++; |
| 4284 | } else if (!strcmp(sub->name, "augment")) { |
| 4285 | c_aug++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4286 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 56e8977 | 2015-06-19 10:00:54 +0200 | [diff] [blame] | 4287 | c_ftrs++; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4288 | } else if (!strcmp(sub->name, "when")) { |
| 4289 | if (uses->when) { |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4290 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4291 | goto error; |
| 4292 | } |
| 4293 | |
| 4294 | uses->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4295 | if (!uses->when) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4296 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4297 | goto error; |
| 4298 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 4299 | if (lyxp_syntax_check(uses->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4300 | goto error; |
| 4301 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4302 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4303 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4304 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4305 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4306 | } |
| 4307 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4308 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4309 | /* process properties with cardinality 0..n */ |
| 4310 | if (c_ref) { |
| 4311 | uses->refine = calloc(c_ref, sizeof *uses->refine); |
| 4312 | } |
| 4313 | if (c_aug) { |
| 4314 | uses->augment = calloc(c_aug, sizeof *uses->augment); |
| 4315 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4316 | if (c_ftrs) { |
| 4317 | uses->features = calloc(c_ftrs, sizeof *uses->features); |
| 4318 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4319 | |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4320 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4321 | goto error; |
| 4322 | } |
| 4323 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4324 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4325 | if (!strcmp(sub->name, "refine")) { |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 4326 | r = fill_yin_refine(module, sub, &uses->refine[uses->refine_size++]); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4327 | if (r) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4328 | goto error; |
| 4329 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4330 | } else if (!strcmp(sub->name, "augment")) { |
| 4331 | r = fill_yin_augment(module, retval, sub, &uses->augment[uses->augment_size++], unres); |
| 4332 | if (r) { |
| 4333 | goto error; |
| 4334 | } |
| 4335 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4336 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 4337 | if (unres_schema_add_str(module, unres, &uses->features[uses->features_size++], UNRES_IFFEAT, value, |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4338 | LOGLINE(sub)) == -1) { |
| 4339 | goto error; |
| 4340 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4341 | } |
| 4342 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4343 | |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 4344 | if (unres_schema_add_node(module, unres, uses, UNRES_USES, NULL, LOGLINE(yin)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4345 | goto error; |
| 4346 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4347 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4348 | if (resolve) { |
| 4349 | /* inherit config flag */ |
| 4350 | if (parent) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4351 | retval->flags |= parent->flags & LYS_CONFIG_MASK; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4352 | } else { |
| 4353 | /* default config is true */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4354 | retval->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4355 | } |
| 4356 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 4357 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4358 | return retval; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4359 | |
| 4360 | error: |
| 4361 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4362 | lys_node_free(retval); |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4363 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4364 | return NULL; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4365 | } |
| 4366 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4367 | /* logs directly |
| 4368 | * |
| 4369 | * common code for yin_read_module() and yin_read_submodule() |
| 4370 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4371 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4372 | read_sub_module(struct lys_module *module, struct lyxml_elem *yin, struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4373 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4374 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4375 | struct lys_submodule *submodule = (struct lys_submodule *)module; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4376 | struct lyxml_elem *next, *child, *child2, root, grps, rpcs, notifs; |
| 4377 | struct lys_node *node = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4378 | const char *value; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4379 | int i, r; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4380 | int belongsto_flag = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4381 | /* counters */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4382 | 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] | 4383 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4384 | /* init */ |
| 4385 | memset(&root, 0, sizeof root); |
| 4386 | memset(&grps, 0, sizeof grps); |
| 4387 | memset(&rpcs, 0, sizeof rpcs); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4388 | memset(¬ifs, 0, sizeof notifs); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4389 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4390 | /* |
| 4391 | * in the first run, we process elements with cardinality of 1 or 0..1 and |
| 4392 | * count elements with cardinality 0..n. Data elements (choices, containers, |
| 4393 | * leafs, lists, leaf-lists) are moved aside to be processed last, since we |
| 4394 | * need have all top-level and groupings already prepared at that time. In |
| 4395 | * the middle loop, we process other elements with carinality of 0..n since |
| 4396 | * we need to allocate arrays to store them. |
| 4397 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4398 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 4399 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4400 | /* garbage */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4401 | lyxml_free_elem(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4402 | continue; |
| 4403 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4404 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4405 | if (!module->type && !strcmp(child->name, "namespace")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4406 | if (module->ns) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4407 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4408 | goto error; |
| 4409 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4410 | GETVAL(value, child, "uri"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4411 | module->ns = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4412 | lyxml_free_elem(ctx, child); |
| 4413 | } else if (!module->type && !strcmp(child->name, "prefix")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4414 | if (module->prefix) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4415 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4416 | goto error; |
| 4417 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4418 | GETVAL(value, child, "value"); |
| 4419 | if (check_identifier(value, LY_IDENT_PREFIX, LOGLINE(child), module, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4420 | goto error; |
| 4421 | } |
| 4422 | module->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4423 | lyxml_free_elem(ctx, child); |
| 4424 | } else if (module->type && !strcmp(child->name, "belongs-to")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4425 | if (belongsto_flag) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4426 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4427 | goto error; |
| 4428 | } |
| 4429 | belongsto_flag = 1; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4430 | GETVAL(value, child, "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4431 | while (submodule->belongsto->type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4432 | submodule->belongsto = ((struct lys_submodule *)submodule->belongsto)->belongsto; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4433 | } |
| 4434 | if (value != submodule->belongsto->name) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4435 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4436 | goto error; |
| 4437 | } |
Radek Krejci | f388693 | 2015-06-04 17:36:06 +0200 | [diff] [blame] | 4438 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4439 | /* get the prefix substatement, start with checks */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4440 | if (!child->child) { |
| 4441 | LOGVAL(LYE_MISSSTMT2, LOGLINE(child), "prefix", child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4442 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4443 | } else if (strcmp(child->child->name, "prefix")) { |
| 4444 | LOGVAL(LYE_INSTMT, LOGLINE(child->child), child->child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4445 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4446 | } else if (child->child->next) { |
| 4447 | LOGVAL(LYE_INSTMT, LOGLINE(child->child->next), child->child->next->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4448 | goto error; |
| 4449 | } |
| 4450 | /* and now finally get the value */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4451 | GETVAL(value, child->child, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4452 | /* check here differs from a generic prefix check, since this prefix |
| 4453 | * don't have to be unique |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4454 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4455 | if (check_identifier(value, LY_IDENT_NAME, LOGLINE(child->child), NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4456 | goto error; |
| 4457 | } |
| 4458 | module->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 0af1387 | 2015-05-30 11:50:52 +0200 | [diff] [blame] | 4459 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4460 | /* we are done with belongs-to */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4461 | lyxml_free_elem(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4462 | |
| 4463 | /* counters (statements with n..1 cardinality) */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4464 | } else if (!strcmp(child->name, "import")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4465 | c_imp++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4466 | } else if (!strcmp(child->name, "revision")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4467 | c_rev++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4468 | } else if (!strcmp(child->name, "typedef")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4469 | c_tpdf++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4470 | } else if (!strcmp(child->name, "identity")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4471 | c_ident++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4472 | } else if (!strcmp(child->name, "include")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4473 | c_inc++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4474 | } else if (!strcmp(child->name, "augment")) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4475 | c_aug++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4476 | } else if (!strcmp(child->name, "feature")) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4477 | c_ftrs++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4478 | } else if (!strcmp(child->name, "deviation")) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4479 | c_dev++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4480 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4481 | /* data statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4482 | } else if (!strcmp(child->name, "container") || |
| 4483 | !strcmp(child->name, "leaf-list") || |
| 4484 | !strcmp(child->name, "leaf") || |
| 4485 | !strcmp(child->name, "list") || |
| 4486 | !strcmp(child->name, "choice") || |
| 4487 | !strcmp(child->name, "uses") || |
| 4488 | !strcmp(child->name, "anyxml")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4489 | lyxml_unlink_elem(module->ctx, child, 1); |
| 4490 | lyxml_add_child(module->ctx, &root, child); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4491 | } else if (!strcmp(child->name, "grouping")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4492 | /* keep groupings separated and process them before other data statements */ |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4493 | lyxml_unlink_elem(module->ctx, child, 1); |
| 4494 | lyxml_add_child(module->ctx, &grps, child); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4495 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4496 | /* optional statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4497 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4498 | if (module->dsc) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4499 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4500 | goto error; |
| 4501 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4502 | module->dsc = read_yin_subnode(ctx, child, "text"); |
| 4503 | lyxml_free_elem(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4504 | if (!module->dsc) { |
| 4505 | goto error; |
| 4506 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4507 | } else if (!strcmp(child->name, "reference")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4508 | if (module->ref) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4509 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4510 | goto error; |
| 4511 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4512 | module->ref = read_yin_subnode(ctx, child, "text"); |
| 4513 | lyxml_free_elem(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4514 | if (!module->ref) { |
| 4515 | goto error; |
| 4516 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4517 | } else if (!strcmp(child->name, "organization")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4518 | if (module->org) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4519 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4520 | goto error; |
| 4521 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4522 | module->org = read_yin_subnode(ctx, child, "text"); |
| 4523 | lyxml_free_elem(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4524 | if (!module->org) { |
| 4525 | goto error; |
| 4526 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4527 | } else if (!strcmp(child->name, "contact")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4528 | if (module->contact) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4529 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4530 | goto error; |
| 4531 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4532 | module->contact = read_yin_subnode(ctx, child, "text"); |
| 4533 | lyxml_free_elem(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4534 | if (!module->contact) { |
| 4535 | goto error; |
| 4536 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4537 | } else if (!strcmp(child->name, "yang-version")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4538 | /* TODO: support YANG 1.1 ? */ |
| 4539 | if (module->version) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4540 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4541 | goto error; |
| 4542 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4543 | GETVAL(value, child, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4544 | if (strcmp(value, "1")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4545 | LOGVAL(LYE_INARG, LOGLINE(child), value, "yang-version"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4546 | goto error; |
| 4547 | } |
| 4548 | module->version = 1; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4549 | lyxml_free_elem(ctx, child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4550 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4551 | /* rpcs & notifications */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4552 | } else if (!strcmp(child->name, "rpc")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4553 | lyxml_unlink_elem(module->ctx, child, 1); |
| 4554 | lyxml_add_child(module->ctx, &rpcs, child); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4555 | } else if (!strcmp(child->name, "notification")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4556 | lyxml_unlink_elem(module->ctx, child, 1); |
| 4557 | lyxml_add_child(module->ctx, ¬ifs, child); |
Radek Krejci | 5166a89 | 2015-07-02 16:44:24 +0200 | [diff] [blame] | 4558 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4559 | } else if (!strcmp(child->name, "extension")) { |
| 4560 | GETVAL(value, child, "name"); |
Radek Krejci | 5166a89 | 2015-07-02 16:44:24 +0200 | [diff] [blame] | 4561 | |
Radek Krejci | 3d46812 | 2015-10-02 13:36:12 +0200 | [diff] [blame] | 4562 | /* we have the following supported (hardcoded) extensions: */ |
| 4563 | /* ietf-netconf's get-filter-element-attributes */ |
| 4564 | if (!strcmp(module->ns, LY_NSNC) && |
| 4565 | !strcmp(value, "get-filter-element-attributes")) { |
| 4566 | LOGDBG("NETCONF filter extension found"); |
| 4567 | /* NACM's default-deny-write and default-deny-all */ |
| 4568 | } else if (!strcmp(module->ns, LY_NSNACM) && |
| 4569 | (!strcmp(value, "default-deny-write") || !strcmp(value, "default-deny-all"))) { |
| 4570 | LOGDBG("NACM extension found"); |
| 4571 | /* other extensions are not supported, so inform about such an extension */ |
| 4572 | } else { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 4573 | LOGWRN("Not supported \"%s\" extension statement found, ignoring.", value); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4574 | lyxml_free_elem(ctx, child); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 4575 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4576 | } else { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4577 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4578 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4579 | } |
| 4580 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4581 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4582 | if (!submodule) { |
| 4583 | /* check for mandatory statements */ |
| 4584 | if (!module->ns) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4585 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "namespace", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4586 | goto error; |
| 4587 | } |
| 4588 | if (!module->prefix) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4589 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "prefix", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4590 | goto error; |
| 4591 | } |
| 4592 | } |
Radek Krejci | bb3257d | 2015-05-21 23:03:51 +0200 | [diff] [blame] | 4593 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4594 | /* allocate arrays for elements with cardinality of 0..n */ |
| 4595 | if (c_imp) { |
| 4596 | module->imp = calloc(c_imp, sizeof *module->imp); |
| 4597 | } |
| 4598 | if (c_rev) { |
| 4599 | module->rev = calloc(c_rev, sizeof *module->rev); |
| 4600 | } |
| 4601 | if (c_tpdf) { |
| 4602 | module->tpdf = calloc(c_tpdf, sizeof *module->tpdf); |
| 4603 | } |
| 4604 | if (c_ident) { |
| 4605 | module->ident = calloc(c_ident, sizeof *module->ident); |
| 4606 | } |
| 4607 | if (c_inc) { |
| 4608 | module->inc = calloc(c_inc, sizeof *module->inc); |
| 4609 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4610 | if (c_aug) { |
| 4611 | module->augment = calloc(c_aug, sizeof *module->augment); |
| 4612 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4613 | if (c_ftrs) { |
| 4614 | module->features = calloc(c_ftrs, sizeof *module->features); |
| 4615 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4616 | if (c_dev) { |
| 4617 | module->deviation = calloc(c_dev, sizeof *module->deviation); |
| 4618 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4619 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4620 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4621 | LY_TREE_FOR(yin->child, child) { |
| 4622 | if (!strcmp(child->name, "import")) { |
| 4623 | r = fill_yin_import(module, child, &module->imp[module->imp_size]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4624 | module->imp_size++; |
| 4625 | if (r) { |
| 4626 | goto error; |
| 4627 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4628 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4629 | /* check duplicities in imported modules */ |
| 4630 | for (i = 0; i < module->imp_size - 1; i++) { |
| 4631 | if (!strcmp(module->imp[i].module->name, module->imp[module->imp_size - 1].module->name)) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4632 | LOGVAL(LYE_SPEC, LOGLINE(child), "Importing module \"%s\" repeatedly.", module->imp[i].module->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4633 | goto error; |
| 4634 | } |
| 4635 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4636 | } else if (!strcmp(child->name, "include")) { |
| 4637 | r = fill_yin_include(module, child, &module->inc[module->inc_size]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4638 | module->inc_size++; |
| 4639 | if (r) { |
| 4640 | goto error; |
| 4641 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4642 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4643 | /* check duplications in include submodules */ |
| 4644 | for (i = 0; i < module->inc_size - 1; i++) { |
| 4645 | if (!strcmp(module->inc[i].submodule->name, module->inc[module->inc_size - 1].submodule->name)) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4646 | LOGVAL(LYE_SPEC, LOGLINE(child), "Importing module \"%s\" repeatedly.", |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4647 | module->inc[i].submodule->name); |
| 4648 | goto error; |
| 4649 | } |
| 4650 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4651 | } else if (!strcmp(child->name, "revision")) { |
| 4652 | GETVAL(value, child, "date"); |
| 4653 | if (check_date(value, LOGLINE(child))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4654 | goto error; |
| 4655 | } |
| 4656 | memcpy(module->rev[module->rev_size].date, value, LY_REV_SIZE - 1); |
| 4657 | /* check uniqueness of the revision date - not required by RFC */ |
| 4658 | for (i = 0; i < module->rev_size; i++) { |
| 4659 | if (!strcmp(value, module->rev[i].date)) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4660 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4661 | LOGVAL(LYE_SPEC, 0, "Revision is not unique."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4662 | } |
| 4663 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4664 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4665 | LY_TREE_FOR(child->child, child2) { |
| 4666 | if (!strcmp(child2->name, "description")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4667 | if (module->rev[module->rev_size].dsc) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4668 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child2->name, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4669 | goto error; |
| 4670 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4671 | module->rev[module->rev_size].dsc = read_yin_subnode(ctx, child2, "text"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4672 | if (!module->rev[module->rev_size].dsc) { |
| 4673 | goto error; |
| 4674 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4675 | } else if (!strcmp(child2->name, "reference")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4676 | if (module->rev[module->rev_size].ref) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4677 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child2->name, child->name); |
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 | module->rev[module->rev_size].ref = read_yin_subnode(ctx, child2, "text"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4681 | if (!module->rev[module->rev_size].ref) { |
| 4682 | goto error; |
| 4683 | } |
| 4684 | } else { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4685 | LOGVAL(LYE_INSTMT, LOGLINE(child2), child2->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4686 | goto error; |
| 4687 | } |
| 4688 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4689 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4690 | /* keep the latest revision at position 0 */ |
| 4691 | if (module->rev_size && strcmp(module->rev[module->rev_size].date, module->rev[0].date) > 0) { |
| 4692 | /* switch their position */ |
| 4693 | value = strdup(module->rev[0].date); |
| 4694 | memcpy(module->rev[0].date, module->rev[module->rev_size].date, LY_REV_SIZE - 1); |
| 4695 | memcpy(module->rev[module->rev_size].date, value, LY_REV_SIZE - 1); |
| 4696 | free((char *)value); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4697 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4698 | if (module->rev[0].dsc != module->rev[module->rev_size].dsc) { |
| 4699 | value = module->rev[0].dsc; |
| 4700 | module->rev[0].dsc = module->rev[module->rev_size].dsc; |
| 4701 | module->rev[module->rev_size].dsc = value; |
| 4702 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4703 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4704 | if (module->rev[0].ref != module->rev[module->rev_size].ref) { |
| 4705 | value = module->rev[0].ref; |
| 4706 | module->rev[0].ref = module->rev[module->rev_size].ref; |
| 4707 | module->rev[module->rev_size].ref = value; |
| 4708 | } |
| 4709 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4710 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4711 | module->rev_size++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4712 | } else if (!strcmp(child->name, "typedef")) { |
| 4713 | r = fill_yin_typedef(module, NULL, child, &module->tpdf[module->tpdf_size], unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4714 | module->tpdf_size++; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 4715 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4716 | if (r) { |
| 4717 | goto error; |
| 4718 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4719 | } else if (!strcmp(child->name, "identity")) { |
| 4720 | r = fill_yin_identity(module, child, &module->ident[module->ident_size], unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4721 | module->ident_size++; |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 4722 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4723 | if (r) { |
| 4724 | goto error; |
| 4725 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4726 | } else if (!strcmp(child->name, "feature")) { |
| 4727 | r = fill_yin_feature(module, child, &module->features[module->features_size], unres); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4728 | module->features_size++; |
| 4729 | |
| 4730 | if (r) { |
| 4731 | goto error; |
| 4732 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4733 | } else if (!strcmp(child->name, "augment")) { |
| 4734 | r = fill_yin_augment(module, NULL, child, &module->augment[module->augment_size], unres); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4735 | module->augment_size++; |
| 4736 | |
| 4737 | if (r) { |
| 4738 | goto error; |
| 4739 | } |
| 4740 | |
| 4741 | /* node is reconnected into the augment, so we have to skip its free at the end of the loop */ |
| 4742 | continue; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4743 | } else if (!strcmp(child->name, "deviation")) { |
| 4744 | r = fill_yin_deviation(module, child, &module->deviation[module->deviation_size]); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4745 | module->deviation_size++; |
| 4746 | |
| 4747 | if (r) { |
| 4748 | goto error; |
| 4749 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4750 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4751 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4752 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4753 | /* process data nodes. Start with groupings to allow uses |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4754 | * refer to them |
| 4755 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4756 | LY_TREE_FOR_SAFE(grps.child, next, child) { |
| 4757 | node = read_yin_grouping(module, NULL, child, 0, unres); |
| 4758 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4759 | goto error; |
| 4760 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4761 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4762 | lyxml_free_elem(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4763 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4764 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4765 | /* parse data nodes, ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4766 | LY_TREE_FOR_SAFE(root.child, next, child) { |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4767 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4768 | if (!strcmp(child->name, "container")) { |
| 4769 | node = read_yin_container(module, NULL, child, 1, unres); |
| 4770 | } else if (!strcmp(child->name, "leaf-list")) { |
| 4771 | node = read_yin_leaflist(module, NULL, child, 1, unres); |
| 4772 | } else if (!strcmp(child->name, "leaf")) { |
| 4773 | node = read_yin_leaf(module, NULL, child, 1, unres); |
| 4774 | } else if (!strcmp(child->name, "list")) { |
| 4775 | node = read_yin_list(module, NULL, child, 1, unres); |
| 4776 | } else if (!strcmp(child->name, "choice")) { |
| 4777 | node = read_yin_choice(module, NULL, child, 1, unres); |
| 4778 | } else if (!strcmp(child->name, "uses")) { |
| 4779 | node = read_yin_uses(module, NULL, child, 1, unres); |
| 4780 | } else if (!strcmp(child->name, "anyxml")) { |
| 4781 | node = read_yin_anyxml(module, NULL, child, 1, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4782 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4783 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4784 | goto error; |
| 4785 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 4786 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4787 | lyxml_free_elem(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4788 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4789 | |
| 4790 | /* ... rpcs ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4791 | LY_TREE_FOR_SAFE(rpcs.child, next, child) { |
| 4792 | node = read_yin_rpc(module, NULL, child, 0, unres); |
| 4793 | if (!node) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4794 | goto error; |
| 4795 | } |
| 4796 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4797 | lyxml_free_elem(ctx, child); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4798 | } |
| 4799 | |
| 4800 | /* ... and notifications */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4801 | LY_TREE_FOR_SAFE(notifs.child, next, child) { |
| 4802 | node = read_yin_notif(module, NULL, child, 0, unres); |
| 4803 | if (!node) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4804 | goto error; |
| 4805 | } |
| 4806 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4807 | lyxml_free_elem(ctx, child); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4808 | } |
| 4809 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4810 | return EXIT_SUCCESS; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4811 | |
| 4812 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4813 | /* cleanup */ |
| 4814 | while (root.child) { |
| 4815 | lyxml_free_elem(module->ctx, root.child); |
| 4816 | } |
| 4817 | while (grps.child) { |
| 4818 | lyxml_free_elem(module->ctx, grps.child); |
| 4819 | } |
| 4820 | while (rpcs.child) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4821 | lyxml_free_elem(module->ctx, rpcs.child); |
| 4822 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4823 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4824 | free(unres->item); |
| 4825 | unres->item = NULL; |
| 4826 | free(unres->type); |
| 4827 | unres->type = NULL; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4828 | free(unres->str_snode); |
| 4829 | unres->str_snode = NULL; |
Michal Vasko | c07187d | 2015-08-13 15:20:57 +0200 | [diff] [blame] | 4830 | #ifndef NDEBUG |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4831 | free(unres->line); |
| 4832 | unres->line = NULL; |
Michal Vasko | c07187d | 2015-08-13 15:20:57 +0200 | [diff] [blame] | 4833 | #endif |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4834 | unres->count = 0; |
Radek Krejci | 8de7b0f | 2015-07-02 11:43:42 +0200 | [diff] [blame] | 4835 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4836 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4837 | } |
| 4838 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4839 | /* logs directly */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4840 | struct lys_submodule * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4841 | yin_read_submodule(struct lys_module *module, const char *data, int implement, struct unres_schema *unres) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4842 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4843 | struct lyxml_elem *yin; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4844 | struct lys_submodule *submodule = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4845 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4846 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4847 | assert(module->ctx); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4848 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4849 | yin = lyxml_read(module->ctx, data, 0); |
| 4850 | if (!yin) { |
| 4851 | return NULL; |
| 4852 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4853 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4854 | /* check root element */ |
| 4855 | if (!yin->name || strcmp(yin->name, "submodule")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4856 | LOGVAL(LYE_INSTMT, LOGLINE(yin), yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4857 | goto error; |
| 4858 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4859 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4860 | GETVAL(value, yin, "name"); |
| 4861 | if (check_identifier(value, LY_IDENT_NAME, LOGLINE(yin), NULL, NULL)) { |
| 4862 | goto error; |
| 4863 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4864 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4865 | submodule = calloc(1, sizeof *submodule); |
| 4866 | if (!submodule) { |
| 4867 | LOGMEM; |
| 4868 | goto error; |
| 4869 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4870 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4871 | submodule->ctx = module->ctx; |
| 4872 | submodule->name = lydict_insert(submodule->ctx, value, strlen(value)); |
| 4873 | submodule->type = 1; |
| 4874 | submodule->belongsto = module; |
Michal Vasko | d8aa32d | 2015-07-24 11:50:01 +0200 | [diff] [blame] | 4875 | submodule->implemented = (implement ? 1 : 0); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4876 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4877 | LOGVRB("reading submodule %s", submodule->name); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4878 | if (read_sub_module((struct lys_module *)submodule, yin, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4879 | goto error; |
| 4880 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4881 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4882 | /* cleanup */ |
| 4883 | lyxml_free_elem(module->ctx, yin); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4884 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4885 | LOGVRB("submodule %s successfully parsed", submodule->name); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4886 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4887 | return submodule; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4888 | |
| 4889 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4890 | /* cleanup */ |
| 4891 | lyxml_free_elem(module->ctx, yin); |
Michal Vasko | 13b1583 | 2015-08-19 11:04:48 +0200 | [diff] [blame] | 4892 | lys_submodule_free(submodule, 0); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4893 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4894 | return NULL; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4895 | } |
| 4896 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4897 | /* logs directly */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4898 | struct lys_module * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4899 | yin_read_module(struct ly_ctx *ctx, const char *data, int implement, struct unres_schema *unres) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4900 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4901 | struct lyxml_elem *yin; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4902 | struct lys_module *module = NULL, **newlist = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4903 | const char *value; |
| 4904 | int i; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4905 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4906 | yin = lyxml_read(ctx, data, 0); |
| 4907 | if (!yin) { |
| 4908 | return NULL; |
| 4909 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4910 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4911 | /* check root element */ |
| 4912 | if (!yin->name || strcmp(yin->name, "module")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4913 | LOGVAL(LYE_INSTMT, LOGLINE(yin), yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4914 | goto error; |
| 4915 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4916 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4917 | GETVAL(value, yin, "name"); |
| 4918 | if (check_identifier(value, LY_IDENT_NAME, LOGLINE(yin), NULL, NULL)) { |
| 4919 | goto error; |
| 4920 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4921 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4922 | module = calloc(1, sizeof *module); |
| 4923 | if (!module) { |
| 4924 | LOGMEM; |
| 4925 | goto error; |
| 4926 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4927 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4928 | module->ctx = ctx; |
| 4929 | module->name = lydict_insert(ctx, value, strlen(value)); |
| 4930 | module->type = 0; |
Michal Vasko | d8aa32d | 2015-07-24 11:50:01 +0200 | [diff] [blame] | 4931 | module->implemented = (implement ? 1 : 0); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4932 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4933 | LOGVRB("reading module %s", module->name); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4934 | if (read_sub_module(module, yin, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4935 | goto error; |
| 4936 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4937 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4938 | /* add to the context's list of modules */ |
| 4939 | if (ctx->models.used == ctx->models.size) { |
| 4940 | newlist = realloc(ctx->models.list, ctx->models.size * 2); |
| 4941 | if (!newlist) { |
| 4942 | LOGMEM; |
| 4943 | goto error; |
| 4944 | } |
| 4945 | for (i = ctx->models.size; i < ctx->models.size * 2; i++) { |
| 4946 | newlist[i] = NULL; |
| 4947 | } |
| 4948 | ctx->models.size *= 2; |
| 4949 | ctx->models.list = newlist; |
| 4950 | } |
| 4951 | for (i = 0; ctx->models.list[i]; i++) { |
| 4952 | /* check name (name/revision) and namespace uniqueness */ |
| 4953 | if (!strcmp(ctx->models.list[i]->name, module->name)) { |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 4954 | if (ctx->models.list[i]->rev_size == module->rev_size) { |
| 4955 | /* both have the same number of revisions */ |
| 4956 | if (!module->rev_size || !strcmp(ctx->models.list[i]->rev[0].date, module->rev[0].date)) { |
| 4957 | /* both have the same revision -> we already have the same module */ |
| 4958 | /* so free the new one and update the old one's implement flag if needed */ |
| 4959 | lyxml_free_elem(ctx, yin); |
Michal Vasko | 13b1583 | 2015-08-19 11:04:48 +0200 | [diff] [blame] | 4960 | lys_free(module, 0); |
Michal Vasko | aa21157 | 2015-08-13 13:55:39 +0200 | [diff] [blame] | 4961 | unres->count = 0; |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 4962 | |
| 4963 | LOGVRB("module %s already in context", ctx->models.list[i]->name); |
| 4964 | |
| 4965 | if (implement && !ctx->models.list[i]->implemented) { |
| 4966 | lyp_set_implemented(ctx->models.list[i]); |
| 4967 | } |
| 4968 | return ctx->models.list[i]; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4969 | } |
| 4970 | } |
Radek Krejci | f647e61 | 2015-07-30 11:36:07 +0200 | [diff] [blame] | 4971 | /* else (both elses) keep searching, for now the caller is just adding |
| 4972 | * another revision of an already present schema |
| 4973 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4974 | } else if (!strcmp(ctx->models.list[i]->ns, module->ns)) { |
| 4975 | LOGERR(LY_EINVAL, "Two different modules (\"%s\" and \"%s\") have the same namespace \"%s\"", |
| 4976 | ctx->models.list[i]->name, module->name, module->ns); |
| 4977 | goto error; |
| 4978 | } |
| 4979 | } |
| 4980 | ctx->models.list[i] = module; |
| 4981 | ctx->models.used++; |
Michal Vasko | 68cffd7 | 2015-08-03 12:50:11 +0200 | [diff] [blame] | 4982 | ctx->models.module_set_id++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4983 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4984 | /* cleanup */ |
| 4985 | lyxml_free_elem(ctx, yin); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4986 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4987 | LOGVRB("module %s successfully parsed", module->name); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4988 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4989 | return module; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4990 | |
| 4991 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4992 | /* cleanup */ |
| 4993 | lyxml_free_elem(ctx, yin); |
Michal Vasko | 13b1583 | 2015-08-19 11:04:48 +0200 | [diff] [blame] | 4994 | lys_free(module, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4995 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4996 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4997 | } |