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" |
| 36 | #include "dict.h" |
| 37 | #include "parser.h" |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 38 | #include "resolve.h" |
| 39 | #include "tree_internal.h" |
| 40 | #include "xml.h" |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 41 | |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 42 | enum LY_IDENT { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 43 | LY_IDENT_SIMPLE, /* only syntax rules */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 44 | LY_IDENT_FEATURE, |
| 45 | LY_IDENT_IDENTITY, |
| 46 | LY_IDENT_TYPE, |
| 47 | LY_IDENT_NODE, |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 48 | LY_IDENT_NAME, /* uniqueness across the siblings */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 49 | LY_IDENT_PREFIX |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 50 | }; |
| 51 | |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 52 | #define LY_NSYIN "urn:ietf:params:xml:ns:yang:yin:1" |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 53 | #define LY_NSNACM "urn:ietf:params:xml:ns:yang:ietf-netconf-acm" |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 54 | |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 55 | #define GETVAL(value, node, arg) \ |
| 56 | value = lyxml_get_attr(node, arg, NULL); \ |
| 57 | if (!value) { \ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 58 | LOGVAL(LYE_MISSARG, LOGLINE(node), arg, node->name); \ |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 59 | goto error; \ |
| 60 | } |
| 61 | |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 62 | #define OPT_IDENT 0x01 |
| 63 | #define OPT_CONFIG 0x02 |
| 64 | #define OPT_MODULE 0x04 |
| 65 | #define OPT_INHERIT 0x08 |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 66 | #define OPT_NACMEXT 0x10 |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 67 | 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] | 68 | |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 69 | 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] | 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_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] | 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_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] | 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_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] | 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_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] | 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_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] | 80 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 81 | 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] | 82 | int resolve, struct unres_schema *unres); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 83 | 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] | 84 | int resolve, struct unres_schema *unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 85 | 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] | 86 | int resolve, struct unres_schema *unres); |
| 87 | 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] | 88 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 89 | /* does not log */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 90 | static int |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 91 | dup_typedef_check(const char *type, struct lys_tpdf *tpdf, int size) |
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 | int i; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 94 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 95 | for (i = 0; i < size; i++) { |
| 96 | if (!strcmp(type, tpdf[i].name)) { |
| 97 | /* name collision */ |
| 98 | return EXIT_FAILURE; |
| 99 | } |
| 100 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 101 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 102 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 103 | } |
| 104 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 105 | /* does not log */ |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 106 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 107 | dup_feature_check(const char *id, struct lys_module *module) |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 108 | { |
| 109 | int i; |
| 110 | |
| 111 | for (i = 0; i < module->features_size; i++) { |
| 112 | if (!strcmp(id, module->features[i].name)) { |
| 113 | return EXIT_FAILURE; |
| 114 | } |
| 115 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 116 | |
| 117 | return EXIT_SUCCESS; |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 118 | } |
| 119 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 120 | /* does not log */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 121 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 122 | dup_prefix_check(const char *prefix, struct lys_module *module) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 123 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 124 | int i; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 125 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 126 | if (!module->type && module->prefix && !strcmp(module->prefix, prefix)) { |
| 127 | return EXIT_FAILURE; |
| 128 | } |
| 129 | for (i = 0; i < module->imp_size; i++) { |
| 130 | if (!strcmp(module->imp[i].prefix, prefix)) { |
| 131 | return EXIT_FAILURE; |
| 132 | } |
| 133 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 134 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 135 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 136 | } |
| 137 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 138 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 139 | static int |
| 140 | check_identifier(const char *id, enum LY_IDENT type, unsigned int line, |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 141 | struct lys_module *module, struct lys_node *parent) |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 142 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 143 | int i; |
| 144 | int size; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 145 | struct lys_tpdf *tpdf; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 146 | struct lys_node *node; |
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 | assert(id); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 149 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 150 | /* check id syntax */ |
| 151 | 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] | 152 | LOGVAL(LYE_INID, line, id, "invalid start character"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 153 | return EXIT_FAILURE; |
| 154 | } |
| 155 | for (i = 1; id[i]; i++) { |
| 156 | if (!(id[i] >= 'A' && id[i] <= 'Z') && !(id[i] >= 'a' && id[i] <= 'z') |
| 157 | && !(id[i] >= '0' && id[i] <= '9') && id[i] != '_' && id[i] != '-' && id[i] != '.') { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 158 | LOGVAL(LYE_INID, line, id, "invalid character"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 159 | return EXIT_FAILURE; |
| 160 | } |
| 161 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 162 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 163 | if (i > 64) { |
| 164 | LOGWRN("Identifier \"%s\" is long, you should use something shorter.", id); |
| 165 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 166 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 167 | switch (type) { |
| 168 | case LY_IDENT_NAME: |
| 169 | /* check uniqueness of the node within its siblings */ |
| 170 | if (!parent) { |
| 171 | break; |
| 172 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 173 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 174 | LY_TREE_FOR(parent->child, node) { |
| 175 | if (node->name == id) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 176 | LOGVAL(LYE_INID, line, id, "name duplication"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 177 | return EXIT_FAILURE; |
| 178 | } |
| 179 | } |
| 180 | break; |
| 181 | case LY_IDENT_TYPE: |
| 182 | assert(module); |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 183 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 184 | /* check collision with the built-in types */ |
| 185 | if (!strcmp(id, "binary") || !strcmp(id, "bits") || |
| 186 | !strcmp(id, "boolean") || !strcmp(id, "decimal64") || |
| 187 | !strcmp(id, "empty") || !strcmp(id, "enumeration") || |
| 188 | !strcmp(id, "identityref") || !strcmp(id, "instance-identifier") || |
| 189 | !strcmp(id, "int8") || !strcmp(id, "int16") || |
| 190 | !strcmp(id, "int32") || !strcmp(id, "int64") || |
| 191 | !strcmp(id, "leafref") || !strcmp(id, "string") || |
| 192 | !strcmp(id, "uint8") || !strcmp(id, "uint16") || |
| 193 | !strcmp(id, "uint32") || !strcmp(id, "uint64") || !strcmp(id, "union")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 194 | LOGVAL(LYE_SPEC, line, "Typedef name duplicates built-in type."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 195 | return EXIT_FAILURE; |
| 196 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 197 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 198 | /* check locally scoped typedefs (avoid name shadowing) */ |
| 199 | for (; parent; parent = parent->parent) { |
| 200 | switch (parent->nodetype) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 201 | case LYS_CONTAINER: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 202 | size = ((struct lys_node_container *)parent)->tpdf_size; |
| 203 | tpdf = ((struct lys_node_container *)parent)->tpdf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 204 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 205 | case LYS_LIST: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 206 | size = ((struct lys_node_list *)parent)->tpdf_size; |
| 207 | tpdf = ((struct lys_node_list *)parent)->tpdf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 208 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 209 | case LYS_GROUPING: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 210 | size = ((struct lys_node_grp *)parent)->tpdf_size; |
| 211 | tpdf = ((struct lys_node_grp *)parent)->tpdf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 212 | break; |
| 213 | default: |
| 214 | continue; |
| 215 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 216 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 217 | if (dup_typedef_check(id, tpdf, size)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 218 | LOGVAL(LYE_DUPID, line, "typedef", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 219 | return EXIT_FAILURE; |
| 220 | } |
| 221 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 222 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 223 | /* check top-level names */ |
| 224 | if (dup_typedef_check(id, module->tpdf, module->tpdf_size)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 225 | LOGVAL(LYE_DUPID, line, "typedef", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 226 | return EXIT_FAILURE; |
| 227 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 228 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 229 | /* check submodule's top-level names */ |
| 230 | for (i = 0; i < module->inc_size; i++) { |
| 231 | 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] | 232 | LOGVAL(LYE_DUPID, line, "typedef", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 233 | return EXIT_FAILURE; |
| 234 | } |
| 235 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 236 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 237 | /* check top-level names in the main module */ |
| 238 | if (module->type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 239 | if (dup_typedef_check(id, ((struct lys_submodule *)module)->belongsto->tpdf, |
| 240 | ((struct lys_submodule *)module)->belongsto->tpdf_size)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 241 | LOGVAL(LYE_DUPID, line, "typedef", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 242 | return EXIT_FAILURE; |
| 243 | } |
| 244 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 245 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 246 | break; |
| 247 | case LY_IDENT_PREFIX: |
| 248 | assert(module); |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 249 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 250 | if (module->type) { |
| 251 | /* go to the main module */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 252 | module = ((struct lys_submodule *)module)->belongsto; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 253 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 254 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 255 | /* check the main module itself */ |
| 256 | if (dup_prefix_check(id, module)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 257 | LOGVAL(LYE_DUPID, line, "prefix", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 258 | return EXIT_FAILURE; |
| 259 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 260 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 261 | /* and all its submodules */ |
| 262 | for (i = 0; i < module->inc_size; i++) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 263 | if (dup_prefix_check(id, (struct lys_module *)module->inc[i].submodule)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 264 | LOGVAL(LYE_DUPID, line, "prefix", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 265 | return EXIT_FAILURE; |
| 266 | } |
| 267 | } |
| 268 | break; |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 269 | case LY_IDENT_FEATURE: |
| 270 | assert(module); |
| 271 | |
| 272 | /* check feature name uniqness*/ |
Radek Krejci | 49babf3 | 2015-06-18 13:56:17 +0200 | [diff] [blame] | 273 | /* check features in the current module */ |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 274 | if (dup_feature_check(id, module)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 275 | LOGVAL(LYE_DUPID, line, "feature", id); |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 276 | return EXIT_FAILURE; |
| 277 | } |
| 278 | |
| 279 | /* and all its submodules */ |
| 280 | for (i = 0; i < module->inc_size; i++) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 281 | if (dup_feature_check(id, (struct lys_module *)module->inc[i].submodule)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 282 | LOGVAL(LYE_DUPID, line, "feature", id); |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 283 | return EXIT_FAILURE; |
| 284 | } |
| 285 | } |
| 286 | break; |
| 287 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 288 | default: |
| 289 | /* no check required */ |
| 290 | break; |
| 291 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 292 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 293 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 294 | } |
| 295 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 296 | /* does not log */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 297 | static int |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 298 | check_mandatory(struct lys_node *node) |
Radek Krejci | 3de29a7 | 2015-06-16 15:23:03 +0200 | [diff] [blame] | 299 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 300 | struct lys_node *child; |
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 | assert(node); |
Radek Krejci | 3de29a7 | 2015-06-16 15:23:03 +0200 | [diff] [blame] | 303 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 304 | if (node->flags & LYS_MAND_TRUE) { |
Radek Krejci | 3de29a7 | 2015-06-16 15:23:03 +0200 | [diff] [blame] | 305 | return EXIT_FAILURE; |
| 306 | } |
| 307 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 308 | if (node->nodetype == LYS_CASE || node->nodetype == LYS_CHOICE) { |
| 309 | LY_TREE_FOR(node->child, child) { |
Radek Krejci | fd0bb0a | 2015-06-18 13:18:24 +0200 | [diff] [blame] | 310 | if (check_mandatory(child)) { |
| 311 | return EXIT_FAILURE; |
| 312 | } |
Radek Krejci | 3de29a7 | 2015-06-16 15:23:03 +0200 | [diff] [blame] | 313 | } |
| 314 | } |
| 315 | |
| 316 | return EXIT_SUCCESS; |
| 317 | } |
| 318 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 319 | /* logs directly */ |
Radek Krejci | 3de29a7 | 2015-06-16 15:23:03 +0200 | [diff] [blame] | 320 | static int |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 321 | check_date(const char *date, unsigned int line) |
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 | int i; |
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 | assert(date); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 326 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 327 | if (strlen(date) != LY_REV_SIZE - 1) { |
| 328 | goto error; |
| 329 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 330 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 331 | for (i = 0; i < LY_REV_SIZE - 1; i++) { |
| 332 | if (i == 4 || i == 7) { |
| 333 | if (date[i] != '-') { |
| 334 | goto error; |
| 335 | } |
| 336 | } else if (!isdigit(date[i])) { |
| 337 | goto error; |
| 338 | } |
| 339 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 340 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 341 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 342 | |
| 343 | error: |
| 344 | |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 345 | LOGVAL(LYE_INDATE, line, date); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 346 | return EXIT_FAILURE; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 347 | } |
| 348 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 349 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 350 | static const char * |
| 351 | 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] | 352 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 353 | int len; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 354 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 355 | /* there should be <text> child */ |
| 356 | if (!node->child || !node->child->name || strcmp(node->child->name, name)) { |
| 357 | LOGWRN("Expected \"%s\" element in \"%s\" element.", name, node->name); |
| 358 | } else if (node->child->content) { |
| 359 | len = strlen(node->child->content); |
| 360 | return lydict_insert(ctx, node->child->content, len); |
| 361 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 362 | |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 363 | LOGVAL(LYE_INARG, LOGLINE(node), name, node->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 364 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 365 | } |
| 366 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 367 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 368 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 369 | 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] | 370 | { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 371 | struct lyxml_elem *node; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 372 | const char *value; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 373 | |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 374 | GETVAL(value, yin, "name"); |
| 375 | ident->name = lydict_insert(module->ctx, value, 0); |
| 376 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 377 | 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] | 378 | return EXIT_FAILURE; |
| 379 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 380 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 381 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 382 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 383 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 384 | continue; |
| 385 | } |
| 386 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 387 | if (!strcmp(node->name, "base")) { |
| 388 | if (ident->base) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 389 | LOGVAL(LYE_TOOMANY, LOGLINE(node), "base", "identity"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 390 | return EXIT_FAILURE; |
| 391 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 392 | GETVAL(value, node, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 393 | 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] | 394 | return EXIT_FAILURE; |
| 395 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 396 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 397 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name, "identity"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 398 | return EXIT_FAILURE; |
| 399 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 400 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 401 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 402 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 403 | return EXIT_SUCCESS; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 404 | } |
| 405 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 406 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 407 | static int |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 408 | 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] | 409 | { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 410 | struct lyxml_elem *child; |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 411 | const char *value; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 412 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 413 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 414 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 415 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 416 | continue; |
| 417 | } |
| 418 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 419 | if (!strcmp(child->name, "description")) { |
| 420 | if (restr->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 421 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 422 | return EXIT_FAILURE; |
| 423 | } |
| 424 | restr->dsc = read_yin_subnode(ctx, child, "text"); |
| 425 | if (!restr->dsc) { |
| 426 | return EXIT_FAILURE; |
| 427 | } |
| 428 | } else if (!strcmp(child->name, "reference")) { |
| 429 | if (restr->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 430 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 431 | return EXIT_FAILURE; |
| 432 | } |
| 433 | restr->ref = read_yin_subnode(ctx, child, "text"); |
| 434 | if (!restr->ref) { |
| 435 | return EXIT_FAILURE; |
| 436 | } |
| 437 | } else if (!strcmp(child->name, "error-app-tag")) { |
| 438 | if (restr->eapptag) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 439 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 440 | return EXIT_FAILURE; |
| 441 | } |
Michal Vasko | 54e426f | 2015-07-07 15:38:02 +0200 | [diff] [blame] | 442 | GETVAL(value, child, "value"); |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 443 | restr->eapptag = lydict_insert(ctx, value, 0); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 444 | } else if (!strcmp(child->name, "error-message")) { |
| 445 | if (restr->emsg) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 446 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 447 | return EXIT_FAILURE; |
| 448 | } |
| 449 | restr->emsg = read_yin_subnode(ctx, child, "value"); |
| 450 | if (!restr->emsg) { |
| 451 | return EXIT_FAILURE; |
| 452 | } |
| 453 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 454 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 455 | return EXIT_FAILURE; |
| 456 | } |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | return EXIT_SUCCESS; |
Michal Vasko | c8ef47f | 2015-06-29 14:56:19 +0200 | [diff] [blame] | 460 | |
| 461 | error: |
| 462 | return EXIT_FAILURE; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 463 | } |
| 464 | |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 465 | /* logs directly */ |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 466 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 467 | 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] | 468 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 469 | { |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 470 | #define REGEX_ERR_LEN 128 |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 471 | const char *value, *delim, *name, *err_ptr; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 472 | struct lyxml_elem *next, *node; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 473 | struct lys_restr **restr; |
| 474 | struct lys_type_bit bit; |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 475 | pcre *precomp; |
| 476 | int i, j, rc, err_offset; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 477 | int64_t v, v_; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 478 | int64_t p, p_; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 479 | |
Radek Krejci | 8de7b0f | 2015-07-02 11:43:42 +0200 | [diff] [blame] | 480 | GETVAL(value, yin, "name"); |
| 481 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 482 | delim = strchr(value, ':'); |
| 483 | if (delim) { |
| 484 | type->prefix = lydict_insert(module->ctx, value, delim - value); |
| 485 | delim++; |
| 486 | value += delim-value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 487 | } |
Radek Krejci | 667b97f | 2015-05-25 15:03:30 +0200 | [diff] [blame] | 488 | |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 489 | rc = resolve_superior_type(value, type->prefix, module, parent, &type->der); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 490 | if (rc == -1) { |
| 491 | LOGVAL(LYE_INPREF, LOGLINE(yin), type->prefix); |
| 492 | goto error; |
| 493 | } else if (rc == EXIT_FAILURE) { |
| 494 | /* HACK for unres */ |
| 495 | type->der = (struct lys_tpdf *)parent; |
| 496 | 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] | 497 | if (rc == -1) { |
| 498 | goto error; |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 499 | } else { |
| 500 | return EXIT_SUCCESS; |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 501 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 502 | } |
| 503 | type->base = type->der->type.base; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 504 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 505 | switch (type->base) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 506 | case LY_TYPE_BITS: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 507 | /* RFC 6020 9.7.4 - bit */ |
| 508 | |
| 509 | /* get bit specifications, at least one must be present */ |
| 510 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 511 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 512 | /* garbage */ |
| 513 | lyxml_free_elem(module->ctx, node); |
| 514 | continue; |
| 515 | } |
| 516 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 517 | if (!strcmp(node->name, "bit")) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 518 | type->info.bits.count++; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 519 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 520 | LOGVAL(LYE_INSTMT, LOGLINE(yin->child), yin->child->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 521 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 522 | } |
| 523 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 524 | if (!type->der->type.der && !type->info.bits.count) { |
| 525 | /* 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] | 526 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "bit", "type"); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 527 | goto error; |
| 528 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 529 | if (type->der->type.der && type->info.bits.count) { |
| 530 | /* 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] | 531 | LOGVAL(LYE_INSTMT, LOGLINE(yin), "bit"); |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 532 | goto error; |
| 533 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 534 | |
| 535 | 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] | 536 | p = 0; |
| 537 | i = -1; |
| 538 | LY_TREE_FOR(yin->child, next) { |
| 539 | i++; |
| 540 | |
| 541 | GETVAL(value, next, "name"); |
| 542 | if (check_identifier(value, LY_IDENT_SIMPLE, LOGLINE(next), NULL, NULL)) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 543 | goto error; |
| 544 | } |
| 545 | 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] | 546 | 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] | 547 | type->info.bits.count = i + 1; |
| 548 | goto error; |
| 549 | } |
| 550 | |
| 551 | /* check the name uniqueness */ |
| 552 | for (j = 0; j < i; j++) { |
| 553 | 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] | 554 | LOGVAL(LYE_BITS_DUPNAME, LOGLINE(next), type->info.bits.bit[i].name); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 555 | type->info.bits.count = i + 1; |
| 556 | goto error; |
| 557 | } |
| 558 | } |
| 559 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 560 | p_ = -1; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 561 | LY_TREE_FOR(next->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 562 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 563 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 564 | continue; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 565 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 566 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 567 | if (!strcmp(node->name, "position")) { |
| 568 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 569 | p_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 570 | |
| 571 | /* range check */ |
Radek Krejci | b8ca108 | 2015-07-10 11:24:11 +0200 | [diff] [blame] | 572 | if (p_ < 0 || p_ > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 573 | LOGVAL(LYE_INARG, LOGLINE(node), value, "bit/position"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 574 | type->info.bits.count = i + 1; |
| 575 | goto error; |
| 576 | } |
| 577 | type->info.bits.bit[i].pos = (uint32_t)p_; |
| 578 | |
| 579 | /* keep the highest enum value for automatic increment */ |
Michal Vasko | 9ab0594 | 2015-07-07 15:38:26 +0200 | [diff] [blame] | 580 | if (type->info.bits.bit[i].pos >= p) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 581 | p = type->info.bits.bit[i].pos; |
| 582 | p++; |
| 583 | } else { |
| 584 | /* check that the value is unique */ |
| 585 | for (j = 0; j < i; j++) { |
| 586 | 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] | 587 | 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] | 588 | type->info.bits.count = i + 1; |
| 589 | goto error; |
| 590 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 591 | } |
| 592 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 593 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 594 | LOGVAL(LYE_INSTMT, LOGLINE(next), next->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 595 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 596 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 597 | } |
| 598 | if (p_ == -1) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 599 | /* assign value automatically */ |
| 600 | if (p > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 601 | LOGVAL(LYE_INARG, LOGLINE(next), "4294967295", "bit/position"); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 602 | type->info.bits.count = i + 1; |
| 603 | goto error; |
| 604 | } |
| 605 | type->info.bits.bit[i].pos = (uint32_t)p; |
| 606 | p++; |
| 607 | } |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 608 | |
| 609 | /* keep them ordered by position */ |
| 610 | j = i; |
| 611 | while (j && type->info.bits.bit[j - 1].pos > type->info.bits.bit[j].pos) { |
| 612 | /* switch them */ |
| 613 | memcpy(&bit, &type->info.bits.bit[j], sizeof bit); |
| 614 | memcpy(&type->info.bits.bit[j], &type->info.bits.bit[j - 1], sizeof bit); |
| 615 | memcpy(&type->info.bits.bit[j - 1], &bit, sizeof bit); |
| 616 | j--; |
| 617 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 618 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 619 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 620 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 621 | case LY_TYPE_DEC64: |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 622 | /* RFC 6020 9.2.4 - range and 9.3.4 - fraction-digits */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 623 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 624 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 625 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 626 | continue; |
| 627 | } |
| 628 | |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 629 | if (!strcmp(node->name, "range")) { |
| 630 | if (type->info.dec64.range) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 631 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 632 | goto error; |
| 633 | } |
| 634 | |
| 635 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 636 | if (lyp_check_length_range(value, type)) { |
Michal Vasko | 9c1bc64 | 2015-08-05 16:25:53 +0200 | [diff] [blame] | 637 | LOGVAL(LYE_INARG, LOGLINE(node), value, "range"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 638 | goto error; |
| 639 | } |
| 640 | type->info.dec64.range = calloc(1, sizeof *type->info.dec64.range); |
| 641 | type->info.dec64.range->expr = lydict_insert(module->ctx, value, 0); |
| 642 | |
| 643 | /* get possible substatements */ |
| 644 | if (read_restr_substmt(module->ctx, type->info.dec64.range, node)) { |
| 645 | goto error; |
| 646 | } |
| 647 | } else if (!strcmp(node->name, "fraction-digits")) { |
| 648 | if (type->info.dec64.dig) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 649 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 650 | goto error; |
| 651 | } |
| 652 | GETVAL(value, node, "value"); |
| 653 | v = strtol(value, NULL, 10); |
| 654 | |
| 655 | /* range check */ |
| 656 | if (v < 1 || v > 18) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 657 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 658 | goto error; |
| 659 | } |
| 660 | type->info.dec64.dig = (uint8_t)v; |
| 661 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 662 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 663 | goto error; |
| 664 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | /* mandatory sub-statement(s) check */ |
| 668 | if (!type->info.dec64.dig && !type->der->type.der) { |
| 669 | /* decimal64 type directly derived from built-in type requires fraction-digits */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 670 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "fraction-digits", "type"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 671 | goto error; |
| 672 | } |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 673 | if (type->info.dec64.dig && type->der->type.der) { |
| 674 | /* 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] | 675 | LOGVAL(LYE_INSTMT, LOGLINE(yin), "fraction-digits"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 676 | goto error; |
| 677 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 678 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 679 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 680 | case LY_TYPE_ENUM: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 681 | /* RFC 6020 9.6 - enum */ |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 682 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 683 | /* get enum specifications, at least one must be present */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 684 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 685 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 686 | /* garbage */ |
| 687 | lyxml_free_elem(module->ctx, node); |
| 688 | continue; |
| 689 | } |
| 690 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 691 | if (!strcmp(node->name, "enum")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 692 | type->info.enums.count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 693 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 694 | LOGVAL(LYE_INSTMT, LOGLINE(yin->child), yin->child->name); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 695 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 696 | } |
| 697 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 698 | if (!type->der->type.der && !type->info.enums.count) { |
| 699 | /* 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] | 700 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "enum", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 701 | goto error; |
| 702 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 703 | if (type->der->type.der && type->info.enums.count) { |
| 704 | /* 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] | 705 | LOGVAL(LYE_INSTMT, LOGLINE(yin), "enum"); |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 706 | goto error; |
| 707 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 708 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 709 | 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] | 710 | v = 0; |
| 711 | i = -1; |
| 712 | LY_TREE_FOR(yin->child, next) { |
| 713 | i++; |
| 714 | |
| 715 | GETVAL(value, next, "name"); |
| 716 | if (check_identifier(value, LY_IDENT_SIMPLE, LOGLINE(next), NULL, NULL)) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 717 | goto error; |
| 718 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 719 | 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] | 720 | 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] | 721 | type->info.enums.count = i + 1; |
| 722 | goto error; |
| 723 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 724 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 725 | /* the assigned name MUST NOT have any leading or trailing whitespace characters */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 726 | value = type->info.enums.enm[i].name; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 727 | if (isspace(value[0]) || isspace(value[strlen(value) - 1])) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 728 | LOGVAL(LYE_ENUM_WS, LOGLINE(next), value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 729 | type->info.enums.count = i + 1; |
| 730 | goto error; |
| 731 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 732 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 733 | /* check the name uniqueness */ |
| 734 | for (j = 0; j < i; j++) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 735 | 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] | 736 | LOGVAL(LYE_ENUM_DUPNAME, LOGLINE(next), type->info.enums.enm[i].name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 737 | type->info.enums.count = i + 1; |
| 738 | goto error; |
| 739 | } |
| 740 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 741 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 742 | v_ = -1; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 743 | LY_TREE_FOR(next->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 744 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 745 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 746 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 747 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 748 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 749 | if (!strcmp(node->name, "value")) { |
| 750 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 751 | v_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 752 | |
| 753 | /* range check */ |
| 754 | if (v_ < INT32_MIN || v_ > INT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 755 | LOGVAL(LYE_INARG, LOGLINE(node), value, "enum/value"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 756 | type->info.enums.count = i + 1; |
| 757 | goto error; |
| 758 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 759 | type->info.enums.enm[i].value = v_; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 760 | |
| 761 | /* keep the highest enum value for automatic increment */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 762 | if (type->info.enums.enm[i].value > v) { |
| 763 | v = type->info.enums.enm[i].value; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 764 | v++; |
| 765 | } else { |
| 766 | /* check that the value is unique */ |
| 767 | for (j = 0; j < i; j++) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 768 | 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] | 769 | LOGVAL(LYE_ENUM_DUPVAL, LOGLINE(node), type->info.enums.enm[i].value, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 770 | type->info.enums.enm[i].name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 771 | type->info.enums.count = i + 1; |
| 772 | goto error; |
| 773 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 774 | } |
| 775 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 776 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 777 | LOGVAL(LYE_INSTMT, LOGLINE(next), next->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 778 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 779 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 780 | } |
| 781 | if (v_ == -1) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 782 | /* assign value automatically */ |
| 783 | if (v > INT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 784 | LOGVAL(LYE_INARG, LOGLINE(next), "2147483648", "enum/value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 785 | type->info.enums.count = i + 1; |
| 786 | goto error; |
| 787 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 788 | type->info.enums.enm[i].value = v; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 789 | v++; |
| 790 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 791 | } |
| 792 | break; |
| 793 | |
| 794 | case LY_TYPE_IDENT: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 795 | /* RFC 6020 9.10 - base */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 796 | |
| 797 | /* get base specification, exactly one must be present */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 798 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 799 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 800 | /* garbage */ |
| 801 | lyxml_free_elem(module->ctx, node); |
| 802 | continue; |
| 803 | } |
| 804 | |
| 805 | if (strcmp(yin->child->name, "base")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 806 | LOGVAL(LYE_INSTMT, LOGLINE(yin->child), yin->child->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 807 | goto error; |
| 808 | } |
| 809 | } |
| 810 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 811 | if (!yin->child) { |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 812 | if (type->der->type.der) { |
| 813 | /* this is just a derived type with no base specified/required */ |
| 814 | break; |
| 815 | } |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 816 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "base", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 817 | goto error; |
| 818 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 819 | if (yin->child->next) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 820 | 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] | 821 | goto error; |
| 822 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 823 | GETVAL(value, yin->child, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 824 | 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] | 825 | goto error; |
| 826 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 827 | break; |
| 828 | |
| 829 | case LY_TYPE_INST: |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 830 | /* RFC 6020 9.13.2 - require-instance */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 831 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 832 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 833 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 834 | continue; |
| 835 | } |
| 836 | |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 837 | if (!strcmp(node->name, "require-instance")) { |
| 838 | if (type->info.inst.req) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 839 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 840 | goto error; |
| 841 | } |
| 842 | GETVAL(value, node, "value"); |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 843 | if (!strcmp(value, "true")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 844 | type->info.inst.req = 1; |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 845 | } else if (!strcmp(value, "false")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 846 | type->info.inst.req = -1; |
| 847 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 848 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 849 | goto error; |
| 850 | } |
| 851 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 852 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 853 | goto error; |
| 854 | } |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 855 | } |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 856 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 857 | break; |
| 858 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 859 | case LY_TYPE_BINARY: |
| 860 | /* 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] | 861 | case LY_TYPE_INT8: |
| 862 | case LY_TYPE_INT16: |
| 863 | case LY_TYPE_INT32: |
| 864 | case LY_TYPE_INT64: |
| 865 | case LY_TYPE_UINT8: |
| 866 | case LY_TYPE_UINT16: |
| 867 | case LY_TYPE_UINT32: |
| 868 | case LY_TYPE_UINT64: |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 869 | /* RFC 6020 9.2.4 - range */ |
| 870 | |
| 871 | /* length and range are actually the same restriction, so process |
| 872 | * them by this common code, we just need to differ the name and |
| 873 | * structure where the information will be stored |
| 874 | */ |
| 875 | if (type->base == LY_TYPE_BINARY) { |
| 876 | restr = &type->info.binary.length; |
| 877 | name = "length"; |
| 878 | } else { |
| 879 | restr = &type->info.num.range; |
| 880 | name = "range"; |
| 881 | } |
| 882 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 883 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 884 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 885 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 886 | continue; |
| 887 | } |
| 888 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 889 | if (!strcmp(node->name, name)) { |
| 890 | if (*restr) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 891 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 892 | goto error; |
| 893 | } |
| 894 | |
| 895 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 896 | if (lyp_check_length_range(value, type)) { |
Michal Vasko | 9c1bc64 | 2015-08-05 16:25:53 +0200 | [diff] [blame] | 897 | LOGVAL(LYE_INARG, LOGLINE(node), value, name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 898 | goto error; |
| 899 | } |
| 900 | *restr = calloc(1, sizeof **restr); |
| 901 | (*restr)->expr = lydict_insert(module->ctx, value, 0); |
| 902 | |
| 903 | /* get possible substatements */ |
| 904 | if (read_restr_substmt(module->ctx, *restr, node)) { |
| 905 | goto error; |
| 906 | } |
| 907 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 908 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 909 | goto error; |
| 910 | } |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 911 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 912 | break; |
| 913 | |
| 914 | case LY_TYPE_LEAFREF: |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 915 | /* RFC 6020 9.9.2 - path */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 916 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 917 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 918 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 919 | continue; |
| 920 | } |
| 921 | |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 922 | if (!strcmp(node->name, "path")) { |
| 923 | if (type->info.lref.path) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 924 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 925 | goto error; |
| 926 | } |
| 927 | |
| 928 | GETVAL(value, node, "value"); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 929 | type->info.lref.path = lydict_insert(module->ctx, value, 0); |
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"); |
Radek Krejci | 0bd5db4 | 2015-06-19 13:30:07 +0200 | [diff] [blame] | 1215 | must->expr = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1216 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 1217 | return read_restr_substmt(module->ctx, must, yin); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1218 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 1219 | error: /* GETVAL requires this label */ |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1220 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1221 | return EXIT_FAILURE; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1222 | } |
| 1223 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1224 | /* logs directly |
| 1225 | * |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1226 | * type: 0 - min, 1 - max |
| 1227 | */ |
| 1228 | static int |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1229 | 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] | 1230 | { |
| 1231 | const char *value; |
| 1232 | char *endptr; |
| 1233 | unsigned long val; |
| 1234 | uint32_t *ui32val; |
| 1235 | |
| 1236 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1237 | if (target->nodetype == LYS_LEAFLIST) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1238 | if (type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1239 | ui32val = &((struct lys_node_leaflist *)target)->max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1240 | } else { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1241 | ui32val = &((struct lys_node_leaflist *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1242 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1243 | } else if (target->nodetype == LYS_LIST) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1244 | if (type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1245 | ui32val = &((struct lys_node_list *)target)->max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1246 | } else { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1247 | ui32val = &((struct lys_node_list *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1248 | } |
| 1249 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1250 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
| 1251 | 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] | 1252 | goto error; |
| 1253 | } |
| 1254 | |
| 1255 | GETVAL(value, node, "value"); |
| 1256 | while (isspace(value[0])) { |
| 1257 | value++; |
| 1258 | } |
| 1259 | |
| 1260 | /* convert it to uint32_t */ |
| 1261 | errno = 0; |
| 1262 | endptr = NULL; |
| 1263 | val = strtoul(value, &endptr, 10); |
| 1264 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1265 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1266 | goto error; |
| 1267 | } |
| 1268 | if (type) { |
| 1269 | d->max = (uint32_t)val; |
| 1270 | } else { |
| 1271 | d->min = (uint32_t)val; |
| 1272 | } |
| 1273 | |
| 1274 | if (d->mod == LY_DEVIATE_ADD) { |
| 1275 | /* check that there is no current value */ |
| 1276 | if (*ui32val) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1277 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
| 1278 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1279 | goto error; |
| 1280 | } |
| 1281 | } |
| 1282 | |
| 1283 | if (d->mod == LY_DEVIATE_DEL) { |
| 1284 | /* check values */ |
| 1285 | if ((uint32_t)val != *ui32val) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1286 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
| 1287 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1288 | goto error; |
| 1289 | } |
| 1290 | /* remove current min-elements value of the target */ |
| 1291 | *ui32val = 0; |
| 1292 | } else { /* add (already checked) and replace */ |
| 1293 | /* set new value specified in deviation */ |
| 1294 | *ui32val = (uint32_t)val; |
| 1295 | } |
| 1296 | |
| 1297 | return EXIT_SUCCESS; |
| 1298 | |
| 1299 | error: |
| 1300 | |
| 1301 | return EXIT_FAILURE; |
| 1302 | } |
| 1303 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1304 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1305 | static int |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1306 | 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] | 1307 | { |
| 1308 | const char *value, **stritem; |
| 1309 | struct lyxml_elem *next, *child, *develem; |
| 1310 | int c_dev = 0, c_must, c_uniq; |
| 1311 | int f_min = 0; /* flags */ |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1312 | int i, j, rc; |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1313 | struct lys_deviate *d = NULL; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1314 | struct lys_node *node = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1315 | struct lys_node_choice *choice = NULL; |
| 1316 | struct lys_node_leaf *leaf = NULL; |
| 1317 | struct lys_node_list *list = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1318 | struct lys_type *t = NULL; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1319 | uint8_t *trg_must_size = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1320 | struct lys_restr **trg_must = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1321 | |
| 1322 | GETVAL(value, yin, "target-node"); |
| 1323 | dev->target_name = lydict_insert(module->ctx, value, 0); |
| 1324 | |
| 1325 | /* resolve target node */ |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1326 | rc = resolve_schema_nodeid(dev->target_name, NULL, module, LYS_AUGMENT, &dev->target); |
| 1327 | if (rc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1328 | LOGVAL(LYE_INARG, LOGLINE(yin), dev->target_name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1329 | goto error; |
| 1330 | } |
| 1331 | if (dev->target->module == module) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1332 | LOGVAL(LYE_SPEC, LOGLINE(yin), "Deviating own module is not allowed."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1333 | goto error; |
| 1334 | } |
| 1335 | /* mark the target module as deviated */ |
| 1336 | dev->target->module->deviated = 1; |
| 1337 | |
| 1338 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1339 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1340 | /* garbage */ |
| 1341 | lyxml_free_elem(module->ctx, child); |
| 1342 | continue; |
| 1343 | } |
| 1344 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1345 | if (!strcmp(child->name, "description")) { |
| 1346 | if (dev->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1347 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1348 | goto error; |
| 1349 | } |
| 1350 | dev->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 1351 | if (!dev->dsc) { |
| 1352 | goto error; |
| 1353 | } |
| 1354 | } else if (!strcmp(child->name, "reference")) { |
| 1355 | if (dev->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1356 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1357 | goto error; |
| 1358 | } |
| 1359 | dev->ref = read_yin_subnode(module->ctx, child, "text"); |
| 1360 | if (!dev->ref) { |
| 1361 | goto error; |
| 1362 | } |
| 1363 | } else if (!strcmp(child->name, "deviate")) { |
| 1364 | c_dev++; |
| 1365 | |
| 1366 | /* skip lyxml_free_elem() at the end of the loop, node will be |
| 1367 | * further processed later |
| 1368 | */ |
| 1369 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 1370 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1371 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1372 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1373 | goto error; |
| 1374 | } |
| 1375 | |
| 1376 | lyxml_free_elem(module->ctx, child); |
| 1377 | } |
| 1378 | |
| 1379 | if (c_dev) { |
| 1380 | dev->deviate = calloc(c_dev, sizeof *dev->deviate); |
| 1381 | } |
| 1382 | |
| 1383 | LY_TREE_FOR(yin->child, develem) { |
| 1384 | /* init */ |
| 1385 | f_min = 0; |
| 1386 | c_must = 0; |
| 1387 | c_uniq = 0; |
| 1388 | |
| 1389 | /* get deviation type */ |
| 1390 | GETVAL(value, develem, "value"); |
| 1391 | if (!strcmp(value, "not-supported")) { |
| 1392 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_NO; |
| 1393 | /* no property expected in this case */ |
| 1394 | if (develem->child) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1395 | LOGVAL(LYE_INSTMT, LOGLINE(develem->child), develem->child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1396 | goto error; |
| 1397 | } |
| 1398 | |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1399 | /* and neither any other deviate statement is expected, |
| 1400 | * not-supported deviation must be the only deviation of the target |
| 1401 | */ |
| 1402 | if (dev->deviate_size || develem->next) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1403 | LOGVAL(LYE_INARG, LOGLINE(develem), value, develem->name); |
| 1404 | 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] | 1405 | goto error; |
| 1406 | } |
| 1407 | |
| 1408 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1409 | /* remove target node */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1410 | lys_node_free(dev->target); |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1411 | dev->target = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1412 | |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1413 | dev->deviate_size = 1; |
| 1414 | return EXIT_SUCCESS; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1415 | } else if (!strcmp(value, "add")) { |
| 1416 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_ADD; |
| 1417 | } else if (!strcmp(value, "replace")) { |
| 1418 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_RPL; |
| 1419 | } else if (!strcmp(value, "delete")) { |
| 1420 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_DEL; |
| 1421 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1422 | LOGVAL(LYE_INARG, LOGLINE(develem), value, develem->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1423 | goto error; |
| 1424 | } |
| 1425 | d = &dev->deviate[dev->deviate_size]; |
| 1426 | |
| 1427 | /* process deviation properties */ |
| 1428 | LY_TREE_FOR_SAFE(develem->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1429 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1430 | /* garbage */ |
| 1431 | lyxml_free_elem(module->ctx, child); |
| 1432 | continue; |
| 1433 | } |
| 1434 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1435 | if (!strcmp(child->name, "config")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1436 | if (d->flags & LYS_CONFIG_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1437 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1438 | goto error; |
| 1439 | } |
| 1440 | |
| 1441 | /* for we deviate from RFC 6020 and allow config property even it is/is not |
| 1442 | * specified in the target explicitly since config property inherits. So we expect |
| 1443 | * that config is specified in every node. But for delete, we check that the value |
| 1444 | * is the same as here in deviation |
| 1445 | */ |
| 1446 | GETVAL(value, child, "value"); |
| 1447 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1448 | d->flags |= LYS_CONFIG_R; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1449 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1450 | d->flags |= LYS_CONFIG_W; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1451 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1452 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1453 | goto error; |
| 1454 | } |
| 1455 | |
| 1456 | if (d->mod == LY_DEVIATE_DEL) { |
| 1457 | /* check values */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1458 | if ((d->flags & LYS_CONFIG_MASK) != (dev->target->flags & LYS_CONFIG_MASK)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1459 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1460 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1461 | goto error; |
| 1462 | } |
| 1463 | /* remove current config value of the target ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1464 | dev->target->flags &= ~LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1465 | |
| 1466 | /* ... and inherit config value from the target's parent */ |
| 1467 | if (dev->target->parent) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1468 | dev->target->flags |= dev->target->parent->flags & LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1469 | } else { |
| 1470 | /* default config is true */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1471 | dev->target->flags |= LYS_CONFIG_W; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1472 | } |
| 1473 | } else { /* add and replace are the same in this case */ |
| 1474 | /* remove current config value of the target ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1475 | dev->target->flags &= ~LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1476 | |
| 1477 | /* ... and replace it with the value specified in deviation */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1478 | dev->target->flags |= d->flags & LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1479 | } |
| 1480 | } else if (!strcmp(child->name, "default")) { |
| 1481 | if (d->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1482 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1483 | goto error; |
| 1484 | } |
| 1485 | GETVAL(value, child, "value"); |
| 1486 | d->dflt = lydict_insert(module->ctx, value, 0); |
| 1487 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1488 | if (dev->target->nodetype == LYS_CHOICE) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1489 | choice = (struct lys_node_choice *)dev->target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1490 | |
| 1491 | if (d->mod == LY_DEVIATE_ADD) { |
| 1492 | /* check that there is no current value */ |
| 1493 | if (choice->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1494 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1495 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1496 | goto error; |
| 1497 | } |
| 1498 | } |
| 1499 | |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1500 | rc = resolve_schema_nodeid(d->dflt, choice->child, choice->module, LYS_CHOICE, &node); |
| 1501 | if (rc) { |
| 1502 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1503 | goto error; |
| 1504 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1505 | if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1506 | if (!choice->dflt || choice->dflt != node) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1507 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1508 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1509 | goto error; |
| 1510 | } |
| 1511 | } else { /* add (already checked) and replace */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1512 | choice->dflt = node; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1513 | if (!choice->dflt) { |
| 1514 | /* default branch not found */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1515 | LOGVAL(LYE_INARG, LOGLINE(yin), value, "default"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1516 | goto error; |
| 1517 | } |
| 1518 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1519 | } else if (dev->target->nodetype == LYS_LEAF) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1520 | leaf = (struct lys_node_leaf *)dev->target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1521 | |
| 1522 | if (d->mod == LY_DEVIATE_ADD) { |
| 1523 | /* check that there is no current value */ |
| 1524 | if (leaf->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1525 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1526 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1527 | goto error; |
| 1528 | } |
| 1529 | } |
| 1530 | |
| 1531 | if (d->mod == LY_DEVIATE_DEL) { |
| 1532 | if (!leaf->dflt || leaf->dflt != d->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1533 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1534 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1535 | goto error; |
| 1536 | } |
| 1537 | /* remove value */ |
| 1538 | lydict_remove(leaf->module->ctx, leaf->dflt); |
| 1539 | leaf->dflt = NULL; |
| 1540 | } else { /* add (already checked) and replace */ |
| 1541 | /* remove value */ |
| 1542 | lydict_remove(leaf->module->ctx, leaf->dflt); |
| 1543 | |
| 1544 | /* set new value */ |
| 1545 | leaf->dflt = lydict_insert(leaf->module->ctx, d->dflt, 0); |
| 1546 | } |
| 1547 | } else { |
| 1548 | /* invalid target for default value */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1549 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1550 | 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] | 1551 | goto error; |
| 1552 | } |
| 1553 | } else if (!strcmp(child->name, "mandatory")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1554 | if (d->flags & LYS_MAND_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1555 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1556 | goto error; |
| 1557 | } |
| 1558 | |
| 1559 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1560 | if (!(dev->target->nodetype &= (LYS_LEAF | LYS_CHOICE | LYS_ANYXML))) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1561 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1562 | 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] | 1563 | goto error; |
| 1564 | } |
| 1565 | |
| 1566 | GETVAL(value, child, "value"); |
| 1567 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1568 | d->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1569 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1570 | d->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1571 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1572 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1573 | goto error; |
| 1574 | } |
| 1575 | |
| 1576 | if (d->mod == LY_DEVIATE_ADD) { |
| 1577 | /* check that there is no current value */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1578 | if (dev->target->flags & LYS_MAND_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1579 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1580 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1581 | goto error; |
| 1582 | } |
| 1583 | } |
| 1584 | |
| 1585 | if (d->mod == LY_DEVIATE_DEL) { |
| 1586 | /* check values */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1587 | if ((d->flags & LYS_MAND_MASK) != (dev->target->flags & LYS_MAND_MASK)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1588 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1589 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1590 | goto error; |
| 1591 | } |
| 1592 | /* remove current mandatory value of the target */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1593 | dev->target->flags &= ~LYS_MAND_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1594 | } else { /* add (already checked) and replace */ |
| 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 | |
| 1598 | /* ... and replace it with the value specified in deviation */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1599 | dev->target->flags |= d->flags & LYS_MAND_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1600 | } |
| 1601 | } else if (!strcmp(child->name, "min-elements")) { |
| 1602 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1603 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1604 | goto error; |
| 1605 | } |
| 1606 | f_min = 1; |
| 1607 | |
| 1608 | if (deviate_minmax(dev->target, child, d, 0)) { |
| 1609 | goto error; |
| 1610 | } |
| 1611 | } else if (!strcmp(child->name, "max-elements")) { |
| 1612 | if (d->max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1613 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1614 | goto error; |
| 1615 | } |
| 1616 | |
| 1617 | if (deviate_minmax(dev->target, child, d, 1)) { |
| 1618 | goto error; |
| 1619 | } |
| 1620 | } else if (!strcmp(child->name, "must")) { |
| 1621 | c_must++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1622 | /* skip lyxml_free_elem() at the end of the loop, this node will be processed later */ |
| 1623 | continue; |
| 1624 | } else if (!strcmp(child->name, "type")) { |
| 1625 | if (d->type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1626 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1627 | goto error; |
| 1628 | } |
| 1629 | |
| 1630 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1631 | if (dev->target->nodetype == LYS_LEAF) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1632 | t = &((struct lys_node_leaf *)dev->target)->type; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1633 | } else if (dev->target->nodetype == LYS_LEAFLIST) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1634 | t = &((struct lys_node_leaflist *)dev->target)->type; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1635 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1636 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1637 | 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] | 1638 | goto error; |
| 1639 | } |
| 1640 | |
| 1641 | if (d->mod == LY_DEVIATE_ADD) { |
| 1642 | /* not allowed, type is always present at the target */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1643 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1644 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1645 | goto error; |
| 1646 | } else if (d->mod == LY_DEVIATE_DEL) { |
| 1647 | /* not allowed, type cannot be deleted from the target */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1648 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1649 | LOGVAL(LYE_SPEC, 0, "Deleteing type from the target is not allowed."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1650 | goto error; |
| 1651 | } |
| 1652 | |
| 1653 | /* replace */ |
| 1654 | /* remove current units value of the target ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1655 | lys_type_free(dev->target->module->ctx, t); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1656 | |
| 1657 | /* ... and replace it with the value specified in deviation */ |
Radek Krejci | 8de7b0f | 2015-07-02 11:43:42 +0200 | [diff] [blame] | 1658 | if (fill_yin_type(module, dev->target, child, t, NULL)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1659 | goto error; |
| 1660 | } |
| 1661 | d->type = t; |
| 1662 | } else if (!strcmp(child->name, "unique")) { |
| 1663 | c_uniq++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1664 | /* skip lyxml_free_elem() at the end of the loop, this node will be processed later */ |
| 1665 | continue; |
| 1666 | } else if (!strcmp(child->name, "units")) { |
| 1667 | if (d->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1668 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1669 | goto error; |
| 1670 | } |
| 1671 | |
| 1672 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1673 | if (dev->target->nodetype == LYS_LEAFLIST) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1674 | stritem = &((struct lys_node_leaflist *)dev->target)->units; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1675 | } else if (dev->target->nodetype == LYS_LEAF) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1676 | stritem = &((struct lys_node_leaf *)dev->target)->units; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1677 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1678 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1679 | 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] | 1680 | goto error; |
| 1681 | } |
| 1682 | |
| 1683 | /* get units value */ |
| 1684 | GETVAL(value, child, "name"); |
| 1685 | d->units = lydict_insert(module->ctx, value, 0); |
| 1686 | |
| 1687 | /* apply to target */ |
| 1688 | if (d->mod == LY_DEVIATE_ADD) { |
| 1689 | /* check that there is no current value */ |
| 1690 | if (*stritem) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1691 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1692 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1693 | goto error; |
| 1694 | } |
| 1695 | } |
| 1696 | |
| 1697 | if (d->mod == LY_DEVIATE_DEL) { |
| 1698 | /* check values */ |
| 1699 | if (*stritem != d->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1700 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1701 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1702 | goto error; |
| 1703 | } |
| 1704 | /* remove current units value of the target */ |
| 1705 | lydict_remove(dev->target->module->ctx, *stritem); |
| 1706 | } else { /* add (already checked) and replace */ |
| 1707 | /* remove current units value of the target ... */ |
| 1708 | lydict_remove(dev->target->module->ctx, *stritem); |
| 1709 | |
| 1710 | /* ... and replace it with the value specified in deviation */ |
| 1711 | *stritem = lydict_insert(module->ctx, value, 0); |
| 1712 | } |
| 1713 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1714 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1715 | goto error; |
| 1716 | } |
| 1717 | |
| 1718 | lyxml_free_elem(module->ctx, child); |
| 1719 | } |
| 1720 | |
| 1721 | if (c_must) { |
| 1722 | /* check target node type */ |
| 1723 | switch (dev->target->nodetype) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1724 | case LYS_LEAF: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1725 | trg_must = &((struct lys_node_leaf *)dev->target)->must; |
| 1726 | trg_must_size = &((struct lys_node_leaf *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1727 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1728 | case LYS_CONTAINER: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1729 | trg_must = &((struct lys_node_container *)dev->target)->must; |
| 1730 | trg_must_size = &((struct lys_node_container *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1731 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1732 | case LYS_LEAFLIST: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1733 | trg_must = &((struct lys_node_leaflist *)dev->target)->must; |
| 1734 | trg_must_size = &((struct lys_node_leaflist *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1735 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1736 | case LYS_LIST: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1737 | trg_must = &((struct lys_node_list *)dev->target)->must; |
| 1738 | trg_must_size = &((struct lys_node_list *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1739 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1740 | case LYS_ANYXML: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1741 | trg_must = &((struct lys_node_anyxml *)dev->target)->must; |
| 1742 | trg_must_size = &((struct lys_node_anyxml *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1743 | break; |
| 1744 | default: |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1745 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1746 | 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] | 1747 | goto error; |
| 1748 | } |
| 1749 | |
| 1750 | if (d->mod == LY_DEVIATE_RPL) { |
| 1751 | /* remove target's musts and allocate new array for it */ |
| 1752 | if (!*trg_must) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1753 | LOGVAL(LYE_INARG, LOGLINE(develem), "replace", "deviate"); |
| 1754 | 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] | 1755 | goto error; |
| 1756 | } |
| 1757 | |
| 1758 | for (i = 0; i < list->must_size; i++) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1759 | lys_restr_free(dev->target->module->ctx, &(*trg_must[i])); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1760 | } |
| 1761 | free(*trg_must); |
| 1762 | *trg_must = d->must = calloc(c_must, sizeof *d->must); |
| 1763 | d->must_size = c_must; |
| 1764 | *trg_must_size = 0; |
| 1765 | } else if (d->mod == LY_DEVIATE_ADD) { |
| 1766 | /* reallocate the must array of the target */ |
| 1767 | d->must = realloc(*trg_must, (c_must + *trg_must_size) * sizeof *d->must); |
| 1768 | *trg_must = d->must; |
| 1769 | d->must = &(*trg_must[*trg_must_size]); |
| 1770 | d->must_size = c_must; |
| 1771 | } else { /* LY_DEVIATE_DEL */ |
| 1772 | d->must = calloc(c_must, sizeof *d->must); |
| 1773 | } |
| 1774 | } |
| 1775 | if (c_uniq) { |
| 1776 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1777 | if (dev->target->nodetype != LYS_LIST) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1778 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1779 | 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] | 1780 | goto error; |
| 1781 | } |
| 1782 | |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1783 | list = (struct lys_node_list *)dev->target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1784 | if (d->mod == LY_DEVIATE_RPL) { |
| 1785 | /* remove target's unique and allocate new array for it */ |
| 1786 | if (!list->unique) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1787 | LOGVAL(LYE_INARG, LOGLINE(develem), "replace", "deviate"); |
| 1788 | 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] | 1789 | goto error; |
| 1790 | } |
| 1791 | |
| 1792 | for (i = 0; i < list->unique_size; i++) { |
| 1793 | free(list->unique[i].leafs); |
| 1794 | } |
| 1795 | free(list->unique); |
| 1796 | list->unique = d->unique = calloc(c_uniq, sizeof *d->unique); |
| 1797 | d->unique_size = c_uniq; |
| 1798 | list->unique_size = 0; |
| 1799 | } else if (d->mod == LY_DEVIATE_ADD) { |
| 1800 | /* reallocate the unique array of the target */ |
| 1801 | d->unique = realloc(list->unique, (c_uniq + list->unique_size) * sizeof *d->unique); |
| 1802 | list->unique = d->unique; |
| 1803 | d->unique = &list->unique[list->unique_size]; |
| 1804 | d->unique_size = c_uniq; |
| 1805 | } else { /* LY_DEVIATE_DEL */ |
| 1806 | d->unique = calloc(c_uniq, sizeof *d->unique); |
| 1807 | } |
| 1808 | } |
| 1809 | |
| 1810 | /* process deviation properties with 0..n cardinality */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1811 | LY_TREE_FOR(develem->child, child) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1812 | if (!strcmp(child->name, "must")) { |
| 1813 | if (d->mod == LY_DEVIATE_DEL) { |
| 1814 | if (fill_yin_must(module, child, &d->must[d->must_size])) { |
| 1815 | goto error; |
| 1816 | } |
| 1817 | |
| 1818 | /* find must to delete, we are ok with just matching conditions */ |
| 1819 | for (i = 0; i < *trg_must_size; i++) { |
| 1820 | if (d->must[d->must_size].expr == (*trg_must)[i].expr) { |
| 1821 | /* we have a match, free the must structure ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1822 | lys_restr_free(dev->target->module->ctx, &(*trg_must[i])); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1823 | /* ... and maintain the array */ |
| 1824 | (*trg_must_size)--; |
| 1825 | if (i != *trg_must_size) { |
| 1826 | (*trg_must)[i].expr = (*trg_must)[*trg_must_size].expr; |
| 1827 | (*trg_must)[i].dsc = (*trg_must)[*trg_must_size].dsc; |
| 1828 | (*trg_must)[i].ref = (*trg_must)[*trg_must_size].ref; |
| 1829 | (*trg_must)[i].eapptag = (*trg_must)[*trg_must_size].eapptag; |
| 1830 | (*trg_must)[i].emsg = (*trg_must)[*trg_must_size].emsg; |
| 1831 | } |
| 1832 | if (!(*trg_must_size)) { |
| 1833 | free(*trg_must); |
| 1834 | *trg_must = NULL; |
| 1835 | } else { |
| 1836 | (*trg_must)[*trg_must_size].expr = NULL; |
| 1837 | (*trg_must)[*trg_must_size].dsc = NULL; |
| 1838 | (*trg_must)[*trg_must_size].ref = NULL; |
| 1839 | (*trg_must)[*trg_must_size].eapptag = NULL; |
| 1840 | (*trg_must)[*trg_must_size].emsg = NULL; |
| 1841 | } |
| 1842 | |
| 1843 | i = -1; /* set match flag */ |
| 1844 | break; |
| 1845 | } |
| 1846 | } |
| 1847 | d->must_size++; |
| 1848 | if (i != -1) { |
| 1849 | /* no match found */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1850 | LOGVAL(LYE_INARG, LOGLINE(child), d->must[d->must_size - 1].expr, child->name); |
| 1851 | 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] | 1852 | goto error; |
| 1853 | } |
| 1854 | } else { /* replace or add */ |
| 1855 | if (fill_yin_must(dev->target->module, child, &((*trg_must)[*trg_must_size]))) { |
| 1856 | goto error; |
| 1857 | } |
| 1858 | (*trg_must_size)++; |
| 1859 | } |
| 1860 | } else if (!strcmp(child->name, "unique")) { |
| 1861 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1862 | GETVAL(value, child, "tag"); |
| 1863 | if (resolve_unique(dev->target, value, &d->unique[d->unique_size], LOGLINE(child))) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1864 | goto error; |
| 1865 | } |
| 1866 | |
| 1867 | /* find unique structures to delete */ |
| 1868 | for (i = 0; i < list->unique_size; i++) { |
| 1869 | if (list->unique[i].leafs_size != d->unique[d->unique_size].leafs_size) { |
| 1870 | continue; |
| 1871 | } |
| 1872 | |
| 1873 | for (j = 0; j < d->unique[d->unique_size].leafs_size; j++) { |
| 1874 | if (list->unique[i].leafs[j] != d->unique[d->unique_size].leafs[j]) { |
| 1875 | break; |
| 1876 | } |
| 1877 | } |
| 1878 | |
| 1879 | if (j == d->unique[d->unique_size].leafs_size) { |
| 1880 | /* we have a match, free the unique structure ... */ |
| 1881 | free(list->unique[i].leafs); |
| 1882 | /* ... and maintain the array */ |
| 1883 | list->unique_size--; |
| 1884 | if (i != list->unique_size) { |
| 1885 | list->unique[i].leafs_size = list->unique[list->unique_size].leafs_size; |
| 1886 | list->unique[i].leafs = list->unique[list->unique_size].leafs; |
| 1887 | } |
| 1888 | |
| 1889 | if (!list->unique_size) { |
| 1890 | free(list->unique); |
| 1891 | list->unique = NULL; |
| 1892 | } else { |
| 1893 | list->unique[list->unique_size].leafs_size = 0; |
| 1894 | list->unique[list->unique_size].leafs = NULL; |
| 1895 | } |
| 1896 | |
| 1897 | i = -1; /* set match flag */ |
| 1898 | break; |
| 1899 | } |
| 1900 | } |
| 1901 | |
| 1902 | d->unique_size++; |
| 1903 | if (i != -1) { |
| 1904 | /* no match found */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1905 | LOGVAL(LYE_INARG, LOGLINE(child), lyxml_get_attr(child, "tag", NULL), child->name); |
| 1906 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1907 | goto error; |
| 1908 | } |
| 1909 | } else { /* replace or add */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1910 | GETVAL(value, child, "tag"); |
| 1911 | if (resolve_unique(dev->target, value, &list->unique[list->unique_size], LOGLINE(child))) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1912 | goto error; |
| 1913 | } |
| 1914 | list->unique_size++; |
| 1915 | } |
| 1916 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1917 | } |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1918 | |
| 1919 | dev->deviate_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1920 | } |
| 1921 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1922 | return EXIT_SUCCESS; |
| 1923 | |
| 1924 | error: |
| 1925 | |
| 1926 | if (dev->deviate) { |
| 1927 | for (i = 0; i < dev->deviate_size; i++) { |
| 1928 | lydict_remove(module->ctx, dev->deviate[i].dflt); |
| 1929 | lydict_remove(module->ctx, dev->deviate[i].units); |
| 1930 | |
| 1931 | if (dev->deviate[i].mod == LY_DEVIATE_DEL) { |
| 1932 | for (j = 0; j < dev->deviate[i].must_size; j++) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1933 | lys_restr_free(module->ctx, &dev->deviate[i].must[j]); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1934 | } |
| 1935 | free(dev->deviate[i].must); |
| 1936 | |
| 1937 | for (j = 0; j < dev->deviate[i].unique_size; j++) { |
| 1938 | free(dev->deviate[i].unique[j].leafs); |
| 1939 | } |
| 1940 | free(dev->deviate[i].unique); |
| 1941 | } |
| 1942 | } |
| 1943 | free(dev->deviate); |
| 1944 | } |
| 1945 | |
| 1946 | return EXIT_FAILURE; |
| 1947 | } |
| 1948 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1949 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1950 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1951 | fill_yin_augment(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_node_augment *aug, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 1952 | struct unres_schema *unres) |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1953 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1954 | const char *value; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1955 | struct lyxml_elem *child, *next; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1956 | struct lys_node *node; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1957 | int c = 0; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1958 | |
Michal Vasko | 591e0b2 | 2015-08-13 13:53:43 +0200 | [diff] [blame] | 1959 | aug->nodetype = LYS_AUGMENT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1960 | GETVAL(value, yin, "target-node"); |
| 1961 | aug->target_name = lydict_insert(module->ctx, value, 0); |
| 1962 | aug->parent = parent; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1963 | |
Michal Vasko | 1d87a92 | 2015-08-21 12:57:16 +0200 | [diff] [blame] | 1964 | 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] | 1965 | goto error; |
| 1966 | } |
| 1967 | |
| 1968 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1969 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1970 | /* garbage */ |
| 1971 | lyxml_free_elem(module->ctx, child); |
| 1972 | continue; |
| 1973 | } |
| 1974 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1975 | if (!strcmp(child->name, "if-feature")) { |
| 1976 | c++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1977 | continue; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1978 | } else if (!strcmp(child->name, "when")) { |
| 1979 | if (aug->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1980 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1981 | goto error; |
| 1982 | } |
| 1983 | |
| 1984 | aug->when = read_yin_when(module, child); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1985 | if (!aug->when) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1986 | lyxml_free_elem(module->ctx, child); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1987 | goto error; |
| 1988 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 1989 | if (unres_schema_add_node(module, unres, aug->when, UNRES_WHEN, (struct lys_node *)aug, LOGLINE(child)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1990 | goto error; |
| 1991 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1992 | lyxml_free_elem(module->ctx, child); |
| 1993 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1994 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1995 | /* check allowed data sub-statements */ |
| 1996 | } else if (!strcmp(child->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1997 | node = read_yin_container(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1998 | } else if (!strcmp(child->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1999 | node = read_yin_leaflist(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2000 | } else if (!strcmp(child->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2001 | node = read_yin_leaf(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2002 | } else if (!strcmp(child->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2003 | node = read_yin_list(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2004 | } else if (!strcmp(child->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2005 | node = read_yin_uses(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2006 | } else if (!strcmp(child->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2007 | node = read_yin_case(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2008 | } else if (!strcmp(child->name, "case")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2009 | node = read_yin_case(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2010 | } else if (!strcmp(child->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2011 | node = read_yin_anyxml(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2012 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2013 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2014 | goto error; |
| 2015 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2016 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2017 | if (!node) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2018 | goto error; |
| 2019 | } |
| 2020 | |
| 2021 | /* check for mandatory nodes - if the target node is in another module |
| 2022 | * the added nodes cannot be mandatory |
| 2023 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2024 | if ((!parent || (parent->nodetype != LYS_USES)) && check_mandatory(node)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2025 | 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] | 2026 | goto error; |
| 2027 | } |
| 2028 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2029 | node = NULL; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2030 | lyxml_free_elem(module->ctx, child); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2031 | } |
| 2032 | |
| 2033 | if (c) { |
| 2034 | aug->features = calloc(c, sizeof *aug->features); |
| 2035 | } |
| 2036 | |
| 2037 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 2038 | if (!strcmp(child->name, "if-feature")) { |
| 2039 | GETVAL(value, child, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 2040 | 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] | 2041 | goto error; |
| 2042 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2043 | lyxml_free_elem(module->ctx, child); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2044 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2045 | } |
| 2046 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2047 | /* aug->child points to the parsed nodes, they must now be |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 2048 | * connected to the tree and adjusted (if possible right now). |
| 2049 | * However, if this is augment in a uses, it gets resolved |
| 2050 | * when the uses does and cannot be resolved now for sure |
| 2051 | * (the grouping was not yet copied into uses). |
| 2052 | */ |
| 2053 | if (!parent || (parent->nodetype != LYS_USES)) { |
Michal Vasko | 1d87a92 | 2015-08-21 12:57:16 +0200 | [diff] [blame] | 2054 | if (resolve_augment(aug, aug->child)) { |
Michal Vasko | 4adc10f | 2015-08-11 15:26:17 +0200 | [diff] [blame] | 2055 | LOGVAL(LYE_INRESOLV, LOGLINE(yin), "augment", aug->target_name); |
| 2056 | goto error; |
| 2057 | } |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 2058 | } |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2059 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2060 | return EXIT_SUCCESS; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2061 | |
| 2062 | error: |
| 2063 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2064 | return EXIT_FAILURE; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2065 | } |
| 2066 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2067 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2068 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2069 | fill_yin_refine(struct lys_module *module, struct lyxml_elem *yin, struct lys_refine *rfn, struct lys_node_uses *uses, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 2070 | struct unres_schema *unres) |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2071 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2072 | struct lyxml_elem *sub, *next; |
| 2073 | const char *value; |
| 2074 | char *endptr; |
| 2075 | int f_mand = 0, f_min = 0, f_max = 0; |
| 2076 | int c_must = 0; |
| 2077 | int r; |
| 2078 | unsigned long int val; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2079 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2080 | 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] | 2081 | goto error; |
| 2082 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2083 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2084 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2085 | rfn->target_name = lydict_insert(module->ctx, value, 0); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2086 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2087 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2088 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2089 | /* garbage */ |
| 2090 | lyxml_free_elem(module->ctx, sub); |
| 2091 | continue; |
| 2092 | } |
| 2093 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2094 | /* limited applicability */ |
| 2095 | if (!strcmp(sub->name, "default")) { |
| 2096 | /* leaf or choice */ |
| 2097 | if (rfn->mod.dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2098 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2099 | goto error; |
| 2100 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2101 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2102 | /* check possibility of statements combination */ |
| 2103 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2104 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2105 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2106 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2107 | goto error; |
| 2108 | } |
| 2109 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2110 | rfn->target_type = LYS_LEAF | LYS_CHOICE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2111 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2112 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2113 | GETVAL(value, sub, "value"); |
| 2114 | rfn->mod.dflt = lydict_insert(module->ctx, value, strlen(value)); |
| 2115 | } else if (!strcmp(sub->name, "mandatory")) { |
| 2116 | /* leaf, choice or anyxml */ |
| 2117 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2118 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2119 | goto error; |
| 2120 | } |
| 2121 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2122 | * multiple mandatory statements with the "false" value |
| 2123 | */ |
| 2124 | f_mand = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2125 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2126 | /* check possibility of statements combination */ |
| 2127 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2128 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE | LYS_ANYXML); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2129 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2130 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2131 | goto error; |
| 2132 | } |
| 2133 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2134 | rfn->target_type = LYS_LEAF | LYS_CHOICE | LYS_ANYXML; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2135 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2136 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2137 | GETVAL(value, sub, "value"); |
| 2138 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2139 | rfn->flags |= LYS_MAND_TRUE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2140 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2141 | rfn->flags |= LYS_MAND_FALSE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2142 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2143 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2144 | goto error; |
| 2145 | } |
| 2146 | } else if (!strcmp(sub->name, "min-elements")) { |
| 2147 | /* list or leaf-list */ |
| 2148 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2149 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2150 | goto error; |
| 2151 | } |
| 2152 | f_min = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2153 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2154 | /* check possibility of statements combination */ |
| 2155 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2156 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2157 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2158 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2159 | goto error; |
| 2160 | } |
| 2161 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2162 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2163 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2164 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2165 | GETVAL(value, sub, "value"); |
| 2166 | while (isspace(value[0])) { |
| 2167 | value++; |
| 2168 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2169 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2170 | /* convert it to uint32_t */ |
| 2171 | errno = 0; |
| 2172 | endptr = NULL; |
| 2173 | val = strtoul(value, &endptr, 10); |
| 2174 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2175 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2176 | goto error; |
| 2177 | } |
| 2178 | rfn->mod.list.min = (uint32_t) val; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2179 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2180 | /* magic - bit 3 in flags means min set */ |
| 2181 | rfn->flags |= 0x04; |
| 2182 | } else if (!strcmp(sub->name, "max-elements")) { |
| 2183 | /* list or leaf-list */ |
| 2184 | if (f_max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2185 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2186 | goto error; |
| 2187 | } |
| 2188 | f_max = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2189 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2190 | /* check possibility of statements combination */ |
| 2191 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2192 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2193 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2194 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2195 | goto error; |
| 2196 | } |
| 2197 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2198 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2199 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2200 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2201 | GETVAL(value, sub, "value"); |
| 2202 | while (isspace(value[0])) { |
| 2203 | value++; |
| 2204 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2205 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2206 | /* convert it to uint32_t */ |
| 2207 | errno = 0; |
| 2208 | endptr = NULL; |
| 2209 | val = strtoul(value, &endptr, 10); |
| 2210 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2211 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2212 | goto error; |
| 2213 | } |
| 2214 | rfn->mod.list.max = (uint32_t) val; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2215 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2216 | /* magic - bit 4 in flags means min set */ |
| 2217 | rfn->flags |= 0x08; |
| 2218 | } else if (!strcmp(sub->name, "presence")) { |
| 2219 | /* container */ |
| 2220 | if (rfn->mod.presence) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2221 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2222 | goto error; |
| 2223 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2224 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2225 | /* check possibility of statements combination */ |
| 2226 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2227 | rfn->target_type &= LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2228 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2229 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2230 | goto error; |
| 2231 | } |
| 2232 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2233 | rfn->target_type = LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2234 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2235 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2236 | GETVAL(value, sub, "value"); |
| 2237 | rfn->mod.presence = lydict_insert(module->ctx, value, strlen(value)); |
| 2238 | } else if (!strcmp(sub->name, "must")) { |
| 2239 | /* leaf-list, list, container or anyxml */ |
| 2240 | /* check possibility of statements combination */ |
| 2241 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2242 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST | LYS_CONTAINER | LYS_ANYXML); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2243 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2244 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2245 | goto error; |
| 2246 | } |
| 2247 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2248 | rfn->target_type = LYS_LIST | LYS_LEAFLIST | LYS_CONTAINER | LYS_ANYXML; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2249 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2250 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2251 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 2252 | continue; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2253 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2254 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2255 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2256 | goto error; |
| 2257 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2258 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2259 | lyxml_free_elem(module->ctx, sub); |
| 2260 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2261 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2262 | /* process nodes with cardinality of 0..n */ |
| 2263 | if (c_must) { |
| 2264 | rfn->must = calloc(c_must, sizeof *rfn->must); |
| 2265 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2266 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2267 | r = fill_yin_must(module, sub, &rfn->must[rfn->must_size++]); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2268 | if (r) { |
| 2269 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2270 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 2271 | if (unres_schema_add_node(module, unres, &rfn->must[rfn->must_size-1], UNRES_MUST, (struct lys_node *)uses, |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2272 | LOGLINE(sub)) == -1) { |
| 2273 | goto error; |
| 2274 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2275 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2276 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2277 | return EXIT_SUCCESS; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2278 | |
| 2279 | error: |
| 2280 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2281 | return EXIT_FAILURE; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2282 | } |
| 2283 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2284 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2285 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2286 | 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] | 2287 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2288 | struct lyxml_elem *child; |
| 2289 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2290 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2291 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2292 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2293 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2294 | continue; |
| 2295 | } |
| 2296 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2297 | if (!strcmp(child->name, "prefix")) { |
| 2298 | GETVAL(value, child, "value"); |
| 2299 | if (check_identifier(value, LY_IDENT_PREFIX, LOGLINE(child), module, NULL)) { |
| 2300 | goto error; |
| 2301 | } |
| 2302 | imp->prefix = lydict_insert(module->ctx, value, strlen(value)); |
| 2303 | } else if (!strcmp(child->name, "revision-date")) { |
| 2304 | if (imp->rev[0]) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2305 | LOGVAL(LYE_TOOMANY, LOGLINE(child), "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2306 | goto error; |
| 2307 | } |
| 2308 | GETVAL(value, child, "date"); |
| 2309 | if (check_date(value, LOGLINE(child))) { |
| 2310 | goto error; |
| 2311 | } |
| 2312 | memcpy(imp->rev, value, LY_REV_SIZE - 1); |
| 2313 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2314 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2315 | goto error; |
| 2316 | } |
| 2317 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2318 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2319 | /* check mandatory information */ |
| 2320 | if (!imp->prefix) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2321 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "prefix", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2322 | goto error; |
| 2323 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2324 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2325 | GETVAL(value, yin, "module"); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 2326 | 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] | 2327 | if (!imp->module) { |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 2328 | imp->module = lyp_search_file(module->ctx, NULL, value, imp->rev[0] ? imp->rev : NULL); |
| 2329 | if (!imp->module) { |
| 2330 | LOGERR(LY_EVALID, "Data model \"%s\" not found (search path is \"%s\")", value, module->ctx->models.search_path); |
| 2331 | LOGERR(LY_EVALID, "Importing \"%s\" module into \"%s\" failed.", value, module->name); |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2332 | LOGVAL(LYE_INARG, LOGLINE(yin), value, yin->name); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 2333 | goto error; |
| 2334 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2335 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2336 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2337 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2338 | |
| 2339 | error: |
| 2340 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2341 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2342 | } |
| 2343 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2344 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2345 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2346 | 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] | 2347 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2348 | struct lyxml_elem *child; |
| 2349 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2350 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2351 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2352 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2353 | /* garbage */ |
| 2354 | continue; |
| 2355 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2356 | if (!strcmp(child->name, "revision-date")) { |
| 2357 | if (inc->rev[0]) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2358 | LOGVAL(LYE_TOOMANY, LOGLINE(child), "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2359 | goto error; |
| 2360 | } |
| 2361 | GETVAL(value, child, "date"); |
| 2362 | if (check_date(value, LOGLINE(child))) { |
| 2363 | goto error; |
| 2364 | } |
| 2365 | memcpy(inc->rev, value, LY_REV_SIZE - 1); |
| 2366 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2367 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2368 | goto error; |
| 2369 | } |
| 2370 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2371 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2372 | GETVAL(value, yin, "module"); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 2373 | 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] | 2374 | if (!inc->submodule) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2375 | 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] | 2376 | if (!inc->submodule) { |
| 2377 | LOGERR(LY_EVALID, "Data model \"%s\" not found (search path is \"%s\")", value, module->ctx->models.search_path); |
| 2378 | LOGERR(LY_EVALID, "Including \"%s\" module into \"%s\" failed.", value, module->name); |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2379 | LOGVAL(LYE_INARG, LOGLINE(yin), value, yin->name); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 2380 | goto error; |
| 2381 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2382 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2383 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2384 | /* check that belongs-to corresponds */ |
| 2385 | if (module->type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2386 | module = ((struct lys_submodule *)module)->belongsto; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2387 | } |
| 2388 | if (inc->submodule->belongsto != module) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2389 | LOGVAL(LYE_INARG, LOGLINE(yin), value, yin->name); |
| 2390 | 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] | 2391 | goto error; |
| 2392 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2393 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2394 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2395 | |
| 2396 | error: |
| 2397 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2398 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2399 | } |
| 2400 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2401 | /* logs directly |
| 2402 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2403 | * Covers: |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 2404 | * description, reference, status, optionaly config |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 2405 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2406 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2407 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2408 | read_yin_common(struct lys_module *module, struct lys_node *parent, |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2409 | struct lys_node *node, struct lyxml_elem *xmlnode, int opt) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2410 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2411 | const char *value; |
| 2412 | struct lyxml_elem *sub, *next; |
| 2413 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2414 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2415 | if (opt & OPT_MODULE) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2416 | node->module = module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2417 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2418 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2419 | if (opt & OPT_IDENT) { |
| 2420 | GETVAL(value, xmlnode, "name"); |
| 2421 | if (check_identifier(value, LY_IDENT_NAME, LOGLINE(xmlnode), NULL, NULL)) { |
| 2422 | goto error; |
| 2423 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2424 | node->name = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2425 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2426 | |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2427 | /* inherit NACM flags */ |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2428 | if ((opt & OPT_NACMEXT) && parent) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2429 | node->nacm = parent->nacm; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2430 | } |
| 2431 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2432 | /* process local parameters */ |
| 2433 | LY_TREE_FOR_SAFE(xmlnode->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2434 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2435 | /* garbage */ |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2436 | lyxml_free_elem(ctx, sub); |
| 2437 | continue; |
| 2438 | } |
| 2439 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 2440 | /* NACM extensions */ |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2441 | if ((opt & OPT_NACMEXT) && !strcmp(sub->ns->value, LY_NSNACM)) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2442 | if (!strcmp(sub->name, "default-deny-write")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2443 | node->nacm |= LYS_NACM_DENYW; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2444 | } else if (!strcmp(sub->name, "default-deny-all")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2445 | node->nacm |= LYS_NACM_DENYA; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2446 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2447 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2448 | goto error; |
| 2449 | } |
| 2450 | } |
| 2451 | |
| 2452 | /* else garbage */ |
| 2453 | lyxml_free_elem(ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2454 | continue; |
| 2455 | } |
| 2456 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2457 | if (!strcmp(sub->name, "description")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2458 | if (node->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2459 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2460 | goto error; |
| 2461 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2462 | node->dsc = read_yin_subnode(ctx, sub, "text"); |
| 2463 | if (!node->dsc) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2464 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2465 | } |
| 2466 | } else if (!strcmp(sub->name, "reference")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2467 | if (node->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2468 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2469 | goto error; |
| 2470 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2471 | node->ref = read_yin_subnode(ctx, sub, "text"); |
| 2472 | if (!node->ref) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2473 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2474 | } |
| 2475 | } else if (!strcmp(sub->name, "status")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2476 | if (node->flags & LYS_STATUS_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2477 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2478 | goto error; |
| 2479 | } |
| 2480 | GETVAL(value, sub, "value"); |
| 2481 | if (!strcmp(value, "current")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2482 | node->flags |= LYS_STATUS_CURR; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2483 | } else if (!strcmp(value, "deprecated")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2484 | node->flags |= LYS_STATUS_DEPRC; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2485 | } else if (!strcmp(value, "obsolete")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2486 | node->flags |= LYS_STATUS_OBSLT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2487 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2488 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2489 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2490 | } |
| 2491 | } else if ((opt & OPT_CONFIG) && !strcmp(sub->name, "config")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2492 | if (node->flags & LYS_CONFIG_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2493 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2494 | goto error; |
| 2495 | } |
| 2496 | GETVAL(value, sub, "value"); |
| 2497 | if (!strcmp(value, "false")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2498 | node->flags |= LYS_CONFIG_R; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2499 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2500 | node->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2501 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2502 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2503 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2504 | } |
| 2505 | } else { |
| 2506 | /* skip the lyxml_free_elem */ |
| 2507 | continue; |
| 2508 | } |
| 2509 | lyxml_free_elem(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2510 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2511 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2512 | if ((opt & OPT_INHERIT) && !(node->flags & LYS_CONFIG_MASK)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2513 | /* get config flag from parent */ |
| 2514 | if (parent) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2515 | node->flags |= parent->flags & LYS_CONFIG_MASK; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2516 | } else { |
| 2517 | /* default config is true */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2518 | node->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2519 | } |
| 2520 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2521 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2522 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 2523 | |
| 2524 | error: |
| 2525 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2526 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2527 | } |
| 2528 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2529 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2530 | static struct lys_when * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2531 | read_yin_when(struct lys_module *module, struct lyxml_elem *yin) |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2532 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2533 | struct lys_when *retval = NULL; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2534 | struct lyxml_elem *child; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2535 | const char *value; |
| 2536 | |
| 2537 | retval = calloc(1, sizeof *retval); |
| 2538 | |
| 2539 | GETVAL(value, yin, "condition"); |
| 2540 | retval->cond = lydict_insert(module->ctx, value, 0); |
| 2541 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2542 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2543 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2544 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2545 | continue; |
| 2546 | } |
| 2547 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2548 | if (!strcmp(child->name, "description")) { |
| 2549 | if (retval->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2550 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2551 | goto error; |
| 2552 | } |
| 2553 | retval->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 2554 | if (!retval->dsc) { |
| 2555 | goto error; |
| 2556 | } |
| 2557 | } else if (!strcmp(child->name, "reference")) { |
| 2558 | if (retval->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2559 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2560 | goto error; |
| 2561 | } |
| 2562 | retval->ref = read_yin_subnode(module->ctx, child, "text"); |
| 2563 | if (!retval->ref) { |
| 2564 | goto error; |
| 2565 | } |
| 2566 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2567 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2568 | goto error; |
| 2569 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2570 | } |
| 2571 | |
| 2572 | return retval; |
| 2573 | |
| 2574 | error: |
| 2575 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2576 | lys_node_free((struct lys_node *)retval); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2577 | return NULL; |
| 2578 | } |
| 2579 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2580 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2581 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 2582 | read_yin_case(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 2583 | struct unres_schema *unres) |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2584 | { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2585 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2586 | struct lys_node_case *cs; |
| 2587 | struct lys_node *retval, *node = NULL; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2588 | int c_ftrs = 0; |
| 2589 | const char *value; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2590 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2591 | cs = calloc(1, sizeof *cs); |
| 2592 | cs->nodetype = LYS_CASE; |
| 2593 | cs->prev = (struct lys_node *)cs; |
| 2594 | retval = (struct lys_node *)cs; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2595 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2596 | 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] | 2597 | goto error; |
| 2598 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2599 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 2600 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 2601 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2602 | /* insert the node into the schema tree */ |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 2603 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2604 | goto error; |
| 2605 | } |
| 2606 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2607 | /* process choice's specific children */ |
| 2608 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2609 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2610 | /* garbage */ |
| 2611 | lyxml_free_elem(module->ctx, sub); |
| 2612 | continue; |
| 2613 | } |
| 2614 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2615 | if (!strcmp(sub->name, "container") || |
| 2616 | !strcmp(sub->name, "leaf-list") || |
| 2617 | !strcmp(sub->name, "leaf") || |
| 2618 | !strcmp(sub->name, "list") || |
| 2619 | !strcmp(sub->name, "uses") || |
| 2620 | !strcmp(sub->name, "choice") || |
| 2621 | !strcmp(sub->name, "anyxml")) { |
| 2622 | |
| 2623 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 2624 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2625 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2626 | c_ftrs++; |
| 2627 | /* skip lyxml_free_elem() at the end of the loop, sub is processed later */ |
| 2628 | continue; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2629 | } else if (!strcmp(sub->name, "when")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2630 | if (cs->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2631 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2632 | goto error; |
| 2633 | } |
| 2634 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2635 | cs->when = read_yin_when(module, sub); |
| 2636 | if (!cs->when) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2637 | goto error; |
| 2638 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 2639 | if (unres_schema_add_node(module, unres, cs->when, UNRES_WHEN, retval, LOGLINE(sub)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2640 | goto error; |
| 2641 | } |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2642 | |
| 2643 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2644 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2645 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2646 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2647 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2648 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2649 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2650 | if (c_ftrs) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2651 | cs->features = calloc(c_ftrs, sizeof *cs->features); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2652 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2653 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2654 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 2655 | 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] | 2656 | goto error; |
| 2657 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2658 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 2659 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2660 | /* last part - process data nodes */ |
| 2661 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 2662 | if (!strcmp(sub->name, "container")) { |
| 2663 | node = read_yin_container(module, retval, sub, resolve, unres); |
| 2664 | } else if (!strcmp(sub->name, "leaf-list")) { |
| 2665 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
| 2666 | } else if (!strcmp(sub->name, "leaf")) { |
| 2667 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
| 2668 | } else if (!strcmp(sub->name, "list")) { |
| 2669 | node = read_yin_list(module, retval, sub, resolve, unres); |
| 2670 | } else if (!strcmp(sub->name, "choice")) { |
| 2671 | node = read_yin_choice(module, retval, sub, resolve, unres); |
| 2672 | } else if (!strcmp(sub->name, "uses")) { |
| 2673 | node = read_yin_uses(module, retval, sub, resolve, unres); |
| 2674 | } else if (!strcmp(sub->name, "anyxml")) { |
| 2675 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
| 2676 | } |
| 2677 | if (!node) { |
| 2678 | goto error; |
| 2679 | } |
| 2680 | |
| 2681 | lyxml_free_elem(module->ctx, sub); |
| 2682 | } |
| 2683 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2684 | return retval; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2685 | |
| 2686 | error: |
| 2687 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2688 | while (root.child) { |
| 2689 | lyxml_free_elem(module->ctx, root.child); |
| 2690 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2691 | lys_node_free(retval); |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2692 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2693 | return NULL; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2694 | } |
| 2695 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2696 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2697 | static struct lys_node * |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 2698 | 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] | 2699 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2700 | struct lyxml_elem *sub, *next; |
| 2701 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2702 | struct lys_node *retval, *node = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2703 | struct lys_node_choice *choice; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2704 | const char *value, *dflt_str = NULL; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2705 | int f_mand = 0, c_ftrs = 0; |
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 | choice = calloc(1, sizeof *choice); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2708 | choice->nodetype = LYS_CHOICE; |
| 2709 | choice->prev = (struct lys_node *)choice; |
| 2710 | retval = (struct lys_node *)choice; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2711 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2712 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG | OPT_NACMEXT |
| 2713 | | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2714 | goto error; |
| 2715 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2716 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 2717 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 2718 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2719 | /* insert the node into the schema tree */ |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 2720 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2721 | goto error; |
| 2722 | } |
| 2723 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2724 | /* process choice's specific children */ |
| 2725 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2726 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2727 | /* garbage */ |
| 2728 | lyxml_free_elem(module->ctx, sub); |
| 2729 | continue; |
| 2730 | } |
| 2731 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2732 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2733 | if (!(node = read_yin_container(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2734 | goto error; |
| 2735 | } |
| 2736 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2737 | if (!(node = read_yin_leaflist(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2738 | goto error; |
| 2739 | } |
| 2740 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2741 | if (!(node = read_yin_leaf(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2742 | goto error; |
| 2743 | } |
| 2744 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2745 | if (!(node = read_yin_list(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2746 | goto error; |
| 2747 | } |
| 2748 | } else if (!strcmp(sub->name, "case")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2749 | if (!(node = read_yin_case(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2750 | goto error; |
| 2751 | } |
| 2752 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2753 | if (!(node = read_yin_anyxml(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2754 | goto error; |
| 2755 | } |
| 2756 | } else if (!strcmp(sub->name, "default")) { |
| 2757 | if (dflt_str) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2758 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2759 | goto error; |
| 2760 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2761 | GETVAL(dflt_str, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2762 | } else if (!strcmp(sub->name, "mandatory")) { |
| 2763 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2764 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2765 | goto error; |
| 2766 | } |
| 2767 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2768 | * multiple mandatory statements with the "false" value |
| 2769 | */ |
| 2770 | f_mand = 1; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2771 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2772 | GETVAL(value, sub, "value"); |
| 2773 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2774 | choice->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2775 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2776 | choice->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2777 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2778 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2779 | goto error; |
| 2780 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2781 | } else if (!strcmp(sub->name, "when")) { |
| 2782 | if (choice->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2783 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2784 | goto error; |
| 2785 | } |
| 2786 | |
| 2787 | choice->when = read_yin_when(module, sub); |
| 2788 | if (!choice->when) { |
| 2789 | goto error; |
| 2790 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 2791 | if (unres_schema_add_node(module, unres, choice->when, UNRES_WHEN, retval, LOGLINE(sub)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2792 | goto error; |
| 2793 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2794 | } else if (!strcmp(sub->name, "if-feature")) { |
| 2795 | c_ftrs++; |
| 2796 | |
| 2797 | /* skip lyxml_free_elem() at the end of the loop, the sub node is processed later */ |
| 2798 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2799 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2800 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2801 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2802 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2803 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2804 | node = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2805 | lyxml_free_elem(ctx, sub); |
| 2806 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2807 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2808 | if (c_ftrs) { |
| 2809 | choice->features = calloc(c_ftrs, sizeof *choice->features); |
| 2810 | } |
| 2811 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2812 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2813 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 2814 | 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] | 2815 | goto error; |
| 2816 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2817 | } |
| 2818 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2819 | /* check - default is prohibited in combination with mandatory */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2820 | if (dflt_str && (choice->flags & LYS_MAND_TRUE)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2821 | LOGVAL(LYE_SPEC, LOGLINE(yin), |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2822 | "The \"default\" statement MUST NOT be present on choices where \"mandatory\" is true."); |
| 2823 | goto error; |
| 2824 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2825 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2826 | /* link default with the case */ |
| 2827 | if (dflt_str) { |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 2828 | 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] | 2829 | goto error; |
| 2830 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2831 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2832 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2833 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2834 | |
| 2835 | error: |
| 2836 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2837 | lys_node_free(retval); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2838 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2839 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2840 | } |
| 2841 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2842 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2843 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2844 | 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] | 2845 | struct unres_schema *unres) |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2846 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2847 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2848 | struct lys_node_leaf *anyxml; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2849 | struct lyxml_elem *sub, *next; |
| 2850 | const char *value; |
| 2851 | int r; |
| 2852 | int f_mand = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2853 | int c_must = 0, c_ftrs = 0; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2854 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2855 | anyxml = calloc(1, sizeof *anyxml); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2856 | anyxml->nodetype = LYS_ANYXML; |
| 2857 | anyxml->prev = (struct lys_node *)anyxml; |
| 2858 | retval = (struct lys_node *)anyxml; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2859 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2860 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG | OPT_NACMEXT |
| 2861 | | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2862 | goto error; |
| 2863 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2864 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 2865 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 2866 | |
| 2867 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2868 | goto error; |
| 2869 | } |
| 2870 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2871 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2872 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2873 | /* garbage */ |
| 2874 | lyxml_free_elem(module->ctx, sub); |
| 2875 | continue; |
| 2876 | } |
| 2877 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2878 | if (!strcmp(sub->name, "mandatory")) { |
| 2879 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2880 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2881 | goto error; |
| 2882 | } |
| 2883 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2884 | * multiple mandatory statements with the "false" value |
| 2885 | */ |
| 2886 | f_mand = 1; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2887 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2888 | GETVAL(value, sub, "value"); |
| 2889 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2890 | anyxml->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2891 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2892 | anyxml->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2893 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2894 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2895 | goto error; |
| 2896 | } |
| 2897 | /* else false is the default value, so we can ignore it */ |
| 2898 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2899 | } else if (!strcmp(sub->name, "when")) { |
| 2900 | if (anyxml->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2901 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2902 | goto error; |
| 2903 | } |
| 2904 | |
| 2905 | anyxml->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2906 | if (!anyxml->when) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2907 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2908 | goto error; |
| 2909 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 2910 | if (unres_schema_add_node(module, unres, anyxml->when, UNRES_WHEN, retval, LOGLINE(sub)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2911 | goto error; |
| 2912 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2913 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2914 | } else if (!strcmp(sub->name, "must")) { |
| 2915 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2916 | } else if (!strcmp(sub->name, "if-feature")) { |
| 2917 | c_ftrs++; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2918 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2919 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2920 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2921 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2922 | } |
| 2923 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2924 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2925 | /* middle part - process nodes with cardinality of 0..n */ |
| 2926 | if (c_must) { |
| 2927 | anyxml->must = calloc(c_must, sizeof *anyxml->must); |
| 2928 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2929 | if (c_ftrs) { |
| 2930 | anyxml->features = calloc(c_ftrs, sizeof *anyxml->features); |
| 2931 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2932 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2933 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2934 | if (!strcmp(sub->name, "must")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2935 | r = fill_yin_must(module, sub, &anyxml->must[anyxml->must_size++]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2936 | if (r) { |
| 2937 | goto error; |
| 2938 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 2939 | if (unres_schema_add_node(module, unres, &anyxml->must[anyxml->must_size-1], UNRES_MUST, retval, LOGLINE(sub)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2940 | goto error; |
| 2941 | } |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 2942 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2943 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 2944 | 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] | 2945 | goto error; |
| 2946 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2947 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2948 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2949 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2950 | return retval; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2951 | |
| 2952 | error: |
| 2953 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2954 | lys_node_free(retval); |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2955 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2956 | return NULL; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2957 | } |
| 2958 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2959 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2960 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2961 | 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] | 2962 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2963 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2964 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2965 | struct lys_node_leaf *leaf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2966 | struct lyxml_elem *sub, *next; |
| 2967 | const char *value; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2968 | int r, has_type = 0, dflt_line; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2969 | int c_must = 0, c_ftrs = 0, f_mand = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2970 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2971 | leaf = calloc(1, sizeof *leaf); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2972 | leaf->nodetype = LYS_LEAF; |
| 2973 | leaf->prev = (struct lys_node *)leaf; |
| 2974 | retval = (struct lys_node *)leaf; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2975 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2976 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG | OPT_NACMEXT |
| 2977 | | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2978 | goto error; |
| 2979 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2980 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 2981 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 2982 | |
| 2983 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2984 | goto error; |
| 2985 | } |
| 2986 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2987 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2988 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2989 | /* garbage */ |
| 2990 | lyxml_free_elem(module->ctx, sub); |
| 2991 | continue; |
| 2992 | } |
| 2993 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2994 | if (!strcmp(sub->name, "type")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2995 | if (leaf->type.der || has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2996 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2997 | goto error; |
| 2998 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2999 | if (fill_yin_type(module, parent, sub, &leaf->type, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3000 | goto error; |
| 3001 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3002 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3003 | } else if (!strcmp(sub->name, "default")) { |
| 3004 | if (leaf->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3005 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3006 | goto error; |
| 3007 | } |
| 3008 | GETVAL(value, sub, "value"); |
| 3009 | leaf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3010 | dflt_line = LOGLINE(sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3011 | } else if (!strcmp(sub->name, "units")) { |
| 3012 | if (leaf->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3013 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3014 | goto error; |
| 3015 | } |
| 3016 | GETVAL(value, sub, "name"); |
| 3017 | leaf->units = lydict_insert(module->ctx, value, strlen(value)); |
| 3018 | } else if (!strcmp(sub->name, "mandatory")) { |
| 3019 | if (f_mand) { |
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 | /* just checking the flags in leaf is not sufficient, we would allow |
| 3024 | * multiple mandatory statements with the "false" value |
| 3025 | */ |
| 3026 | f_mand = 1; |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3027 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3028 | GETVAL(value, sub, "value"); |
| 3029 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3030 | leaf->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3031 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3032 | leaf->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3033 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3034 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3035 | goto error; |
| 3036 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3037 | } else if (!strcmp(sub->name, "when")) { |
| 3038 | if (leaf->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3039 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3040 | goto error; |
| 3041 | } |
| 3042 | |
| 3043 | leaf->when = read_yin_when(module, sub); |
| 3044 | if (!leaf->when) { |
| 3045 | goto error; |
| 3046 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3047 | if (unres_schema_add_node(module, unres, leaf->when, UNRES_WHEN, retval, LOGLINE(sub)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3048 | goto error; |
| 3049 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3050 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3051 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3052 | c_must++; |
| 3053 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3054 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3055 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3056 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3057 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3058 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3059 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3060 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3061 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3062 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3063 | lyxml_free_elem(module->ctx, sub); |
| 3064 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3065 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3066 | /* check mandatory parameters */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3067 | if (!has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3068 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3069 | goto error; |
| 3070 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3071 | if (leaf->dflt) { |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3072 | 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] | 3073 | goto error; |
| 3074 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3075 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3076 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3077 | /* middle part - process nodes with cardinality of 0..n */ |
| 3078 | if (c_must) { |
| 3079 | leaf->must = calloc(c_must, sizeof *leaf->must); |
| 3080 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3081 | if (c_ftrs) { |
| 3082 | leaf->features = calloc(c_ftrs, sizeof *leaf->features); |
| 3083 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3084 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3085 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3086 | if (!strcmp(sub->name, "must")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3087 | r = fill_yin_must(module, sub, &leaf->must[leaf->must_size++]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3088 | if (r) { |
| 3089 | goto error; |
| 3090 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3091 | if (unres_schema_add_node(module, unres, &leaf->must[leaf->must_size-1], UNRES_MUST, retval, LOGLINE(sub)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3092 | goto error; |
| 3093 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3094 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3095 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3096 | 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] | 3097 | goto error; |
| 3098 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3099 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3100 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3101 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3102 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3103 | |
| 3104 | error: |
| 3105 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3106 | lys_node_free(retval); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3107 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3108 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3109 | } |
| 3110 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3111 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3112 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3113 | 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] | 3114 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3115 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3116 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3117 | struct lys_node_leaflist *llist; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3118 | struct lyxml_elem *sub, *next; |
| 3119 | const char *value; |
| 3120 | char *endptr; |
| 3121 | unsigned long val; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3122 | int r, has_type = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3123 | int c_must = 0, c_ftrs = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3124 | int f_ordr = 0, f_min = 0, f_max = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3125 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3126 | llist = calloc(1, sizeof *llist); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3127 | llist->nodetype = LYS_LEAFLIST; |
| 3128 | llist->prev = (struct lys_node *)llist; |
| 3129 | retval = (struct lys_node *)llist; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3130 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3131 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG | OPT_NACMEXT |
| 3132 | | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3133 | goto error; |
| 3134 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3135 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3136 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3137 | |
| 3138 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3139 | goto error; |
| 3140 | } |
| 3141 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3142 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3143 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3144 | /* garbage */ |
| 3145 | lyxml_free_elem(module->ctx, sub); |
| 3146 | continue; |
| 3147 | } |
| 3148 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3149 | if (!strcmp(sub->name, "type")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3150 | if (llist->type.der || has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3151 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3152 | goto error; |
| 3153 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3154 | if (fill_yin_type(module, parent, sub, &llist->type, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3155 | goto error; |
| 3156 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3157 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3158 | } else if (!strcmp(sub->name, "units")) { |
| 3159 | if (llist->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3160 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3161 | goto error; |
| 3162 | } |
| 3163 | GETVAL(value, sub, "name"); |
| 3164 | llist->units = lydict_insert(module->ctx, value, strlen(value)); |
| 3165 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 3166 | if (f_ordr) { |
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 | /* just checking the flags in llist is not sufficient, we would |
| 3171 | * allow multiple ordered-by statements with the "system" value |
| 3172 | */ |
| 3173 | f_ordr = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3174 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3175 | if (llist->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3176 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 3177 | * state data |
| 3178 | */ |
| 3179 | lyxml_free_elem(module->ctx, sub); |
| 3180 | continue; |
| 3181 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3182 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3183 | GETVAL(value, sub, "value"); |
| 3184 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3185 | llist->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3186 | } else if (strcmp(value, "system")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3187 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3188 | goto error; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3189 | } /* else system is the default value, so we can ignore it */ |
| 3190 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3191 | } else if (!strcmp(sub->name, "must")) { |
| 3192 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3193 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3194 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3195 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3196 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3197 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3198 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3199 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3200 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3201 | goto error; |
| 3202 | } |
| 3203 | f_min = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3204 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3205 | GETVAL(value, sub, "value"); |
| 3206 | while (isspace(value[0])) { |
| 3207 | value++; |
| 3208 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3209 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3210 | /* convert it to uint32_t */ |
| 3211 | errno = 0; |
| 3212 | endptr = NULL; |
| 3213 | val = strtoul(value, &endptr, 10); |
| 3214 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3215 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3216 | goto error; |
| 3217 | } |
| 3218 | llist->min = (uint32_t) val; |
| 3219 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3220 | if (f_max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3221 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3222 | goto error; |
| 3223 | } |
| 3224 | f_max = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3225 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3226 | GETVAL(value, sub, "value"); |
| 3227 | while (isspace(value[0])) { |
| 3228 | value++; |
| 3229 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3230 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3231 | /* convert it to uint32_t */ |
| 3232 | errno = 0; |
| 3233 | endptr = NULL; |
| 3234 | val = strtoul(value, &endptr, 10); |
| 3235 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3236 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3237 | goto error; |
| 3238 | } |
| 3239 | llist->max = (uint32_t) val; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3240 | } else if (!strcmp(sub->name, "when")) { |
| 3241 | if (llist->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3242 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3243 | goto error; |
| 3244 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3245 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3246 | llist->when = read_yin_when(module, sub); |
| 3247 | if (!llist->when) { |
| 3248 | goto error; |
| 3249 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3250 | if (unres_schema_add_node(module, unres, llist->when, UNRES_WHEN, retval, LOGLINE(sub)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3251 | goto error; |
| 3252 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3253 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3254 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3255 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3256 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3257 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3258 | lyxml_free_elem(module->ctx, sub); |
| 3259 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3260 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3261 | /* check constraints */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3262 | if (!has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3263 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3264 | goto error; |
| 3265 | } |
| 3266 | if (llist->max && llist->min > llist->max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3267 | LOGVAL(LYE_SPEC, LOGLINE(yin), "\"min-elements\" is bigger than \"max-elements\"."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3268 | goto error; |
| 3269 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3270 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3271 | /* middle part - process nodes with cardinality of 0..n */ |
| 3272 | if (c_must) { |
| 3273 | llist->must = calloc(c_must, sizeof *llist->must); |
| 3274 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3275 | if (c_ftrs) { |
| 3276 | llist->features = calloc(c_ftrs, sizeof *llist->features); |
| 3277 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3278 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3279 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3280 | if (!strcmp(sub->name, "must")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3281 | r = fill_yin_must(module, sub, &llist->must[llist->must_size++]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3282 | if (r) { |
| 3283 | goto error; |
| 3284 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3285 | if (unres_schema_add_node(module, unres, &llist->must[llist->must_size-1], UNRES_MUST, retval, LOGLINE(sub)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3286 | goto error; |
| 3287 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3288 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3289 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3290 | 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] | 3291 | LOGLINE(sub)) == -1) { |
| 3292 | goto error; |
| 3293 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3294 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3295 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3296 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3297 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3298 | |
| 3299 | error: |
| 3300 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3301 | lys_node_free(retval); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3302 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3303 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3304 | } |
| 3305 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3306 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3307 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3308 | read_yin_list(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 3309 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3310 | { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3311 | struct lys_node *retval, *node; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3312 | struct lys_node_list *list; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3313 | struct lyxml_elem *sub, *next, root, uniq; |
Michal Vasko | e38af6e | 2015-08-03 14:39:27 +0200 | [diff] [blame] | 3314 | int r, key_line; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3315 | 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] | 3316 | int f_ordr = 0, f_max = 0, f_min = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3317 | const char *key_str = NULL, *value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3318 | char *auxs; |
| 3319 | unsigned long val; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3320 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3321 | /* init */ |
| 3322 | memset(&root, 0, sizeof root); |
| 3323 | memset(&uniq, 0, sizeof uniq); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3324 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3325 | list = calloc(1, sizeof *list); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3326 | list->nodetype = LYS_LIST; |
| 3327 | list->prev = (struct lys_node *)list; |
| 3328 | retval = (struct lys_node *)list; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3329 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3330 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG | OPT_NACMEXT |
| 3331 | | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3332 | goto error; |
| 3333 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3334 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3335 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3336 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3337 | /* process list's specific children */ |
| 3338 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3339 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3340 | /* garbage */ |
| 3341 | lyxml_free_elem(module->ctx, sub); |
| 3342 | continue; |
| 3343 | } |
| 3344 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3345 | /* data statements */ |
| 3346 | if (!strcmp(sub->name, "container") || |
| 3347 | !strcmp(sub->name, "leaf-list") || |
| 3348 | !strcmp(sub->name, "leaf") || |
| 3349 | !strcmp(sub->name, "list") || |
| 3350 | !strcmp(sub->name, "choice") || |
| 3351 | !strcmp(sub->name, "uses") || |
| 3352 | !strcmp(sub->name, "grouping") || |
| 3353 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3354 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 3355 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3356 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3357 | /* array counters */ |
| 3358 | } else if (!strcmp(sub->name, "key")) { |
| 3359 | /* check cardinality 0..1 */ |
| 3360 | if (list->keys_size) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3361 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, list->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3362 | goto error; |
| 3363 | } |
Radek Krejci | d7f0d01 | 2015-05-25 15:04:52 +0200 | [diff] [blame] | 3364 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3365 | /* count the number of keys */ |
| 3366 | GETVAL(value, sub, "value"); |
| 3367 | key_str = value; |
Michal Vasko | e38af6e | 2015-08-03 14:39:27 +0200 | [diff] [blame] | 3368 | key_line = LOGLINE(sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3369 | while ((value = strpbrk(value, " \t\n"))) { |
| 3370 | list->keys_size++; |
| 3371 | while (isspace(*value)) { |
| 3372 | value++; |
| 3373 | } |
| 3374 | } |
| 3375 | list->keys_size++; |
| 3376 | list->keys = calloc(list->keys_size, sizeof *list->keys); |
| 3377 | } else if (!strcmp(sub->name, "unique")) { |
| 3378 | c_uniq++; |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3379 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 3380 | lyxml_add_child(module->ctx, &uniq, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3381 | } else if (!strcmp(sub->name, "typedef")) { |
| 3382 | c_tpdf++; |
| 3383 | } else if (!strcmp(sub->name, "must")) { |
| 3384 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3385 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3386 | c_ftrs++; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3387 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3388 | /* optional stetments */ |
| 3389 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 3390 | if (f_ordr) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3391 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3392 | goto error; |
| 3393 | } |
| 3394 | /* just checking the flags in llist is not sufficient, we would |
| 3395 | * allow multiple ordered-by statements with the "system" value |
| 3396 | */ |
| 3397 | f_ordr = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3398 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3399 | if (list->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3400 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 3401 | * state data |
| 3402 | */ |
| 3403 | lyxml_free_elem(module->ctx, sub); |
| 3404 | continue; |
| 3405 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3406 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3407 | GETVAL(value, sub, "value"); |
| 3408 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3409 | list->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3410 | } else if (strcmp(value, "system")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3411 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3412 | goto error; |
| 3413 | } |
| 3414 | /* else system is the default value, so we can ignore it */ |
| 3415 | lyxml_free_elem(module->ctx, sub); |
| 3416 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3417 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3418 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3419 | goto error; |
| 3420 | } |
| 3421 | f_min = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3422 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3423 | GETVAL(value, sub, "value"); |
| 3424 | while (isspace(value[0])) { |
| 3425 | value++; |
| 3426 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3427 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3428 | /* convert it to uint32_t */ |
| 3429 | errno = 0; |
| 3430 | auxs = NULL; |
| 3431 | val = strtoul(value, &auxs, 10); |
| 3432 | if (*auxs || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3433 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3434 | goto error; |
| 3435 | } |
| 3436 | list->min = (uint32_t) val; |
| 3437 | lyxml_free_elem(module->ctx, sub); |
| 3438 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3439 | if (f_max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3440 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3441 | goto error; |
| 3442 | } |
| 3443 | f_max = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3444 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3445 | GETVAL(value, sub, "value"); |
| 3446 | while (isspace(value[0])) { |
| 3447 | value++; |
| 3448 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3449 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3450 | /* convert it to uint32_t */ |
| 3451 | errno = 0; |
| 3452 | auxs = NULL; |
| 3453 | val = strtoul(value, &auxs, 10); |
| 3454 | if (*auxs || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3455 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3456 | goto error; |
| 3457 | } |
| 3458 | list->max = (uint32_t) val; |
| 3459 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3460 | } else if (!strcmp(sub->name, "when")) { |
| 3461 | if (list->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3462 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3463 | goto error; |
| 3464 | } |
| 3465 | |
| 3466 | list->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3467 | if (!list->when) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3468 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3469 | goto error; |
| 3470 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3471 | if (unres_schema_add_node(module, unres, list->when, UNRES_WHEN, NULL, LOGLINE(sub)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3472 | goto error; |
| 3473 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3474 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3475 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3476 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3477 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3478 | } |
| 3479 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3480 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3481 | /* check - if list is configuration, key statement is mandatory */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3482 | if ((list->flags & LYS_CONFIG_W) && !key_str) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3483 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "key", "list"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3484 | goto error; |
| 3485 | } |
| 3486 | if (list->max && list->min > list->max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3487 | LOGVAL(LYE_SPEC, LOGLINE(yin), "\"min-elements\" is bigger than \"max-elements\"."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3488 | goto error; |
| 3489 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3490 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3491 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3492 | if (c_tpdf) { |
| 3493 | list->tpdf = calloc(c_tpdf, sizeof *list->tpdf); |
| 3494 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3495 | if (c_must) { |
| 3496 | list->must = calloc(c_must, sizeof *list->must); |
| 3497 | } |
| 3498 | if (c_ftrs) { |
| 3499 | list->features = calloc(c_ftrs, sizeof *list->features); |
| 3500 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3501 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3502 | if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3503 | 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] | 3504 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3505 | if (r) { |
| 3506 | goto error; |
| 3507 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3508 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3509 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3510 | 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] | 3511 | goto error; |
| 3512 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3513 | } else if (!strcmp(sub->name, "must")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3514 | r = fill_yin_must(module, sub, &list->must[list->must_size++]); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3515 | if (r) { |
| 3516 | goto error; |
| 3517 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3518 | if (unres_schema_add_node(module, unres, &list->must[list->must_size-1], UNRES_MUST, retval, LOGLINE(sub)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3519 | goto error; |
| 3520 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3521 | } |
| 3522 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 3523 | |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3524 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3525 | goto error; |
| 3526 | } |
| 3527 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3528 | /* last part - process data nodes */ |
| 3529 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3530 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3531 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3532 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3533 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3534 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3535 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3536 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3537 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3538 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3539 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3540 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3541 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3542 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3543 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3544 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3545 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Michal Vasko | c07187d | 2015-08-13 15:20:57 +0200 | [diff] [blame] | 3546 | } else { |
| 3547 | LOGINT; |
| 3548 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3549 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3550 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3551 | goto error; |
| 3552 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3553 | |
| 3554 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3555 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3556 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3557 | if (!key_str) { |
| 3558 | /* config false list without a key */ |
| 3559 | return retval; |
| 3560 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3561 | 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] | 3562 | goto error; |
| 3563 | } |
Radek Krejci | 812b10a | 2015-05-28 16:48:25 +0200 | [diff] [blame] | 3564 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3565 | /* process unique statements */ |
| 3566 | if (c_uniq) { |
| 3567 | list->unique = calloc(c_uniq, sizeof *list->unique); |
| 3568 | } |
| 3569 | LY_TREE_FOR_SAFE(uniq.child, next, sub) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3570 | /* HACK for unres */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3571 | list->unique[list->unique_size++].leafs = (struct lys_node_leaf **)list; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3572 | GETVAL(value, sub, "tag"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3573 | 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] | 3574 | LOGLINE(sub)) == -1) { |
| 3575 | goto error; |
| 3576 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 3577 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3578 | lyxml_free_elem(module->ctx, sub); |
| 3579 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 3580 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3581 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3582 | |
| 3583 | error: |
| 3584 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3585 | lys_node_free(retval); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3586 | while (root.child) { |
| 3587 | lyxml_free_elem(module->ctx, root.child); |
| 3588 | } |
| 3589 | while (uniq.child) { |
| 3590 | lyxml_free_elem(module->ctx, uniq.child); |
| 3591 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3592 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3593 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3594 | } |
| 3595 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3596 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3597 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3598 | read_yin_container(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 3599 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3600 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3601 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3602 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3603 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3604 | struct lys_node_container *cont; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3605 | const char *value; |
| 3606 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3607 | int c_tpdf = 0, c_must = 0, c_ftrs = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3608 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3609 | /* init */ |
| 3610 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3611 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3612 | cont = calloc(1, sizeof *cont); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3613 | cont->nodetype = LYS_CONTAINER; |
| 3614 | cont->prev = (struct lys_node *)cont; |
| 3615 | retval = (struct lys_node *)cont; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3616 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3617 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG | OPT_NACMEXT |
| 3618 | | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3619 | goto error; |
| 3620 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3621 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3622 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3623 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3624 | /* process container's specific children */ |
| 3625 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3626 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3627 | /* garbage */ |
| 3628 | lyxml_free_elem(module->ctx, sub); |
| 3629 | continue; |
| 3630 | } |
| 3631 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3632 | if (!strcmp(sub->name, "presence")) { |
| 3633 | if (cont->presence) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3634 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3635 | goto error; |
| 3636 | } |
| 3637 | GETVAL(value, sub, "value"); |
| 3638 | cont->presence = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 3639 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3640 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3641 | } else if (!strcmp(sub->name, "when")) { |
| 3642 | if (cont->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3643 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3644 | goto error; |
| 3645 | } |
| 3646 | |
| 3647 | cont->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3648 | if (!cont->when) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3649 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3650 | goto error; |
| 3651 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3652 | if (unres_schema_add_node(module, unres, cont->when, UNRES_WHEN, retval, LOGLINE(sub)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3653 | goto error; |
| 3654 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3655 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3656 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3657 | /* data statements */ |
| 3658 | } else if (!strcmp(sub->name, "container") || |
| 3659 | !strcmp(sub->name, "leaf-list") || |
| 3660 | !strcmp(sub->name, "leaf") || |
| 3661 | !strcmp(sub->name, "list") || |
| 3662 | !strcmp(sub->name, "choice") || |
| 3663 | !strcmp(sub->name, "uses") || |
| 3664 | !strcmp(sub->name, "grouping") || |
| 3665 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3666 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 3667 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3668 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3669 | /* array counters */ |
| 3670 | } else if (!strcmp(sub->name, "typedef")) { |
| 3671 | c_tpdf++; |
| 3672 | } else if (!strcmp(sub->name, "must")) { |
| 3673 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3674 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3675 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3676 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3677 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3678 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3679 | } |
| 3680 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3681 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3682 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3683 | if (c_tpdf) { |
| 3684 | cont->tpdf = calloc(c_tpdf, sizeof *cont->tpdf); |
| 3685 | } |
| 3686 | if (c_must) { |
| 3687 | cont->must = calloc(c_must, sizeof *cont->must); |
| 3688 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3689 | if (c_ftrs) { |
| 3690 | cont->features = calloc(c_ftrs, sizeof *cont->features); |
| 3691 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 3692 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3693 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3694 | if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3695 | 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] | 3696 | if (r) { |
| 3697 | goto error; |
| 3698 | } |
| 3699 | } else if (!strcmp(sub->name, "must")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3700 | r = fill_yin_must(module, sub, &cont->must[cont->must_size++]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3701 | if (r) { |
| 3702 | goto error; |
| 3703 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3704 | if (unres_schema_add_node(module, unres, &cont->must[cont->must_size-1], UNRES_MUST, retval, |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3705 | LOGLINE(sub)) == -1) { |
| 3706 | goto error; |
| 3707 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3708 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3709 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3710 | 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] | 3711 | LOGLINE(sub)) == -1) { |
| 3712 | goto error; |
| 3713 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3714 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3715 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3716 | |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3717 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3718 | goto error; |
| 3719 | } |
| 3720 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3721 | /* last part - process data nodes */ |
| 3722 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3723 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3724 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3725 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3726 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3727 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3728 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3729 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3730 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3731 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3732 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3733 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3734 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3735 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3736 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3737 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3738 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3739 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3740 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3741 | goto error; |
| 3742 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3743 | |
| 3744 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3745 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3746 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3747 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3748 | |
| 3749 | error: |
| 3750 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3751 | lys_node_free(retval); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3752 | while (root.child) { |
| 3753 | lyxml_free_elem(module->ctx, root.child); |
| 3754 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3755 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3756 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3757 | } |
| 3758 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3759 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3760 | static struct lys_node * |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3761 | 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] | 3762 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3763 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3764 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3765 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3766 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3767 | struct lys_node_grp *grp; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3768 | int r; |
| 3769 | int c_tpdf = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3770 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3771 | /* init */ |
| 3772 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3773 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3774 | grp = calloc(1, sizeof *grp); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3775 | grp->nodetype = LYS_GROUPING; |
| 3776 | grp->prev = (struct lys_node *)grp; |
| 3777 | retval = (struct lys_node *)grp; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3778 | |
Michal Vasko | 71e1aa8 | 2015-08-12 12:17:51 +0200 | [diff] [blame] | 3779 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3780 | goto error; |
| 3781 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3782 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3783 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3784 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3785 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3786 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3787 | /* garbage */ |
| 3788 | lyxml_free_elem(module->ctx, sub); |
| 3789 | continue; |
| 3790 | } |
| 3791 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3792 | /* data statements */ |
| 3793 | if (!strcmp(sub->name, "container") || |
| 3794 | !strcmp(sub->name, "leaf-list") || |
| 3795 | !strcmp(sub->name, "leaf") || |
| 3796 | !strcmp(sub->name, "list") || |
| 3797 | !strcmp(sub->name, "choice") || |
| 3798 | !strcmp(sub->name, "uses") || |
| 3799 | !strcmp(sub->name, "grouping") || |
| 3800 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3801 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 3802 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3803 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3804 | /* array counters */ |
| 3805 | } else if (!strcmp(sub->name, "typedef")) { |
| 3806 | c_tpdf++; |
| 3807 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3808 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3809 | goto error; |
| 3810 | } |
| 3811 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3812 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3813 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3814 | if (c_tpdf) { |
| 3815 | grp->tpdf = calloc(c_tpdf, sizeof *grp->tpdf); |
| 3816 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3817 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3818 | 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] | 3819 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3820 | if (r) { |
| 3821 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3822 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3823 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3824 | |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3825 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3826 | goto error; |
| 3827 | } |
| 3828 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3829 | /* last part - process data nodes */ |
| 3830 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3831 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3832 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3833 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3834 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3835 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3836 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3837 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3838 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3839 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3840 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3841 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3842 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3843 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3844 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3845 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3846 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3847 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3848 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3849 | goto error; |
| 3850 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3851 | |
| 3852 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3853 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3854 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3855 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3856 | |
| 3857 | error: |
| 3858 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3859 | lys_node_free(retval); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3860 | while (root.child) { |
| 3861 | lyxml_free_elem(module->ctx, root.child); |
| 3862 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3863 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3864 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3865 | } |
| 3866 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3867 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3868 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3869 | read_yin_input_output(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 3870 | struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3871 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3872 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3873 | struct lys_node *node = NULL; |
Radek Krejci | 31fc30d | 2015-08-13 08:27:38 +0200 | [diff] [blame] | 3874 | struct lys_node *retval = NULL; |
Radek Krejci | 4608ada | 2015-08-05 16:04:37 +0200 | [diff] [blame] | 3875 | struct lys_node_rpc_inout *inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3876 | int r; |
| 3877 | int c_tpdf = 0; |
| 3878 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3879 | /* init */ |
| 3880 | memset(&root, 0, sizeof root); |
| 3881 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3882 | inout = calloc(1, sizeof *inout); |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 3883 | inout->prev = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3884 | |
| 3885 | if (!strcmp(yin->name, "input")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3886 | inout->nodetype = LYS_INPUT; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3887 | } else if (!strcmp(yin->name, "output")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3888 | inout->nodetype = LYS_OUTPUT; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3889 | } else { |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 3890 | LOGINT; |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 3891 | free(inout); |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 3892 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3893 | } |
| 3894 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3895 | retval = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3896 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 3897 | if (read_yin_common(module, parent, retval, yin, OPT_MODULE | OPT_NACMEXT)) { |
Michal Vasko | ebeac94 | 2015-06-15 12:11:50 +0200 | [diff] [blame] | 3898 | goto error; |
| 3899 | } |
| 3900 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3901 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3902 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3903 | /* data statements */ |
| 3904 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3905 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3906 | /* garbage */ |
| 3907 | lyxml_free_elem(module->ctx, sub); |
| 3908 | continue; |
| 3909 | } |
| 3910 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3911 | if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3912 | !strcmp(sub->name, "leaf-list") || |
| 3913 | !strcmp(sub->name, "leaf") || |
| 3914 | !strcmp(sub->name, "list") || |
| 3915 | !strcmp(sub->name, "choice") || |
| 3916 | !strcmp(sub->name, "uses") || |
| 3917 | !strcmp(sub->name, "grouping") || |
| 3918 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3919 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 3920 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3921 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3922 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3923 | } else if (!strcmp(sub->name, "typedef")) { |
| 3924 | c_tpdf++; |
Radek Krejci | d2bfa79 | 2015-07-02 16:45:29 +0200 | [diff] [blame] | 3925 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3926 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3927 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3928 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3929 | } |
| 3930 | } |
| 3931 | |
| 3932 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3933 | if (c_tpdf) { |
| 3934 | inout->tpdf = calloc(c_tpdf, sizeof *inout->tpdf); |
| 3935 | } |
| 3936 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3937 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3938 | 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] | 3939 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3940 | if (r) { |
| 3941 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3942 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3943 | } |
| 3944 | |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3945 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3946 | goto error; |
| 3947 | } |
| 3948 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3949 | /* last part - process data nodes */ |
| 3950 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3951 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3952 | node = read_yin_container(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3953 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3954 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3955 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3956 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3957 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3958 | node = read_yin_list(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3959 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3960 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3961 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3962 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3963 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3964 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3965 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3966 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3967 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3968 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3969 | goto error; |
| 3970 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3971 | |
| 3972 | lyxml_free_elem(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3973 | } |
| 3974 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3975 | return retval; |
| 3976 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3977 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3978 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3979 | lys_node_free(retval); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 3980 | while (root.child) { |
| 3981 | lyxml_free_elem(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3982 | } |
| 3983 | |
| 3984 | return NULL; |
| 3985 | } |
| 3986 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3987 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3988 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3989 | read_yin_notif(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 3990 | struct unres_schema *unres) |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 3991 | { |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 3992 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3993 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3994 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3995 | struct lys_node_notif *notif; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3996 | const char *value; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 3997 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3998 | int c_tpdf = 0, c_ftrs = 0; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 3999 | |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 4000 | memset(&root, 0, sizeof root); |
| 4001 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4002 | notif = calloc(1, sizeof *notif); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4003 | notif->nodetype = LYS_NOTIF; |
| 4004 | notif->prev = (struct lys_node *)notif; |
| 4005 | retval = (struct lys_node *)notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4006 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4007 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_NACMEXT)) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4008 | goto error; |
| 4009 | } |
| 4010 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4011 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4012 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4013 | /* process rpc's specific children */ |
| 4014 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4015 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4016 | /* garbage */ |
| 4017 | lyxml_free_elem(module->ctx, sub); |
| 4018 | continue; |
| 4019 | } |
| 4020 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4021 | /* data statements */ |
| 4022 | if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4023 | !strcmp(sub->name, "leaf-list") || |
| 4024 | !strcmp(sub->name, "leaf") || |
| 4025 | !strcmp(sub->name, "list") || |
| 4026 | !strcmp(sub->name, "choice") || |
| 4027 | !strcmp(sub->name, "uses") || |
| 4028 | !strcmp(sub->name, "grouping") || |
| 4029 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4030 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 4031 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4032 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4033 | /* array counters */ |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4034 | } else if (!strcmp(sub->name, "typedef")) { |
| 4035 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4036 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4037 | c_ftrs++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4038 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4039 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4040 | goto error; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4041 | } |
| 4042 | } |
| 4043 | |
| 4044 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4045 | if (c_tpdf) { |
| 4046 | notif->tpdf = calloc(c_tpdf, sizeof *notif->tpdf); |
| 4047 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4048 | if (c_ftrs) { |
| 4049 | notif->features = calloc(c_ftrs, sizeof *notif->features); |
| 4050 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4051 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4052 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4053 | if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4054 | 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] | 4055 | |
| 4056 | if (r) { |
| 4057 | goto error; |
| 4058 | } |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 4059 | } else if (!strcmp(sub->name, "if-features")) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4060 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 4061 | 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] | 4062 | LOGLINE(sub)) == -1) { |
| 4063 | goto error; |
| 4064 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4065 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4066 | } |
| 4067 | |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4068 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4069 | goto error; |
| 4070 | } |
| 4071 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4072 | /* last part - process data nodes */ |
| 4073 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4074 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4075 | node = read_yin_container(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4076 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4077 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4078 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4079 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4080 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4081 | node = read_yin_list(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4082 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4083 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4084 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4085 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4086 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4087 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4088 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4089 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4090 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4091 | if (!node) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4092 | goto error; |
| 4093 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4094 | |
| 4095 | lyxml_free_elem(module->ctx, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4096 | } |
| 4097 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4098 | return retval; |
| 4099 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4100 | error: |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4101 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4102 | lys_node_free(retval); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4103 | while (root.child) { |
| 4104 | lyxml_free_elem(module->ctx, root.child); |
| 4105 | } |
| 4106 | |
| 4107 | return NULL; |
| 4108 | } |
| 4109 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4110 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4111 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4112 | read_yin_rpc(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 4113 | struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4114 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4115 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4116 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4117 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4118 | struct lys_node_rpc *rpc; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4119 | const char *value; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4120 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4121 | int c_tpdf = 0, c_ftrs = 0; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4122 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4123 | /* init */ |
| 4124 | memset(&root, 0, sizeof root); |
| 4125 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4126 | rpc = calloc(1, sizeof *rpc); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4127 | rpc->nodetype = LYS_RPC; |
| 4128 | rpc->prev = (struct lys_node *)rpc; |
| 4129 | retval = (struct lys_node *)rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4130 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4131 | 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] | 4132 | goto error; |
| 4133 | } |
| 4134 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4135 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4136 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4137 | /* process rpc's specific children */ |
| 4138 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4139 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4140 | /* garbage */ |
| 4141 | lyxml_free_elem(module->ctx, sub); |
| 4142 | continue; |
| 4143 | } |
| 4144 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4145 | if (!strcmp(sub->name, "input")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4146 | if (rpc->child |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4147 | && (rpc->child->nodetype == LYS_INPUT |
| 4148 | || (rpc->child->next && rpc->child->next->nodetype == LYS_INPUT))) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4149 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4150 | goto error; |
| 4151 | } |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4152 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 4153 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4154 | } else if (!strcmp(sub->name, "output")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4155 | if (rpc->child |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4156 | && (rpc->child->nodetype == LYS_INPUT |
| 4157 | || (rpc->child->next && rpc->child->next->nodetype == LYS_INPUT))) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4158 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4159 | goto error; |
| 4160 | } |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4161 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 4162 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4163 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4164 | /* data statements */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4165 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4166 | lyxml_unlink_elem(module->ctx, sub, 1); |
| 4167 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4168 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4169 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4170 | } else if (!strcmp(sub->name, "typedef")) { |
| 4171 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4172 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4173 | c_ftrs++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4174 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4175 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4176 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4177 | } |
| 4178 | } |
| 4179 | |
| 4180 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4181 | if (c_tpdf) { |
| 4182 | rpc->tpdf = calloc(c_tpdf, sizeof *rpc->tpdf); |
| 4183 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4184 | if (c_ftrs) { |
| 4185 | rpc->features = calloc(c_ftrs, sizeof *rpc->features); |
| 4186 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4187 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4188 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4189 | if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4190 | 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] | 4191 | |
| 4192 | if (r) { |
| 4193 | goto error; |
| 4194 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4195 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4196 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 4197 | 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] | 4198 | LOGLINE(sub)) == -1) { |
| 4199 | goto error; |
| 4200 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4201 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4202 | } |
| 4203 | |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4204 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4205 | goto error; |
| 4206 | } |
| 4207 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4208 | /* last part - process data nodes */ |
| 4209 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4210 | if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4211 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4212 | } else if (!strcmp(sub->name, "input")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4213 | node = read_yin_input_output(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4214 | } else if (!strcmp(sub->name, "output")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4215 | node = read_yin_input_output(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4216 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4217 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4218 | goto error; |
| 4219 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4220 | |
| 4221 | lyxml_free_elem(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4222 | } |
| 4223 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4224 | return retval; |
| 4225 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4226 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4227 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4228 | lys_node_free(retval); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 4229 | while (root.child) { |
| 4230 | lyxml_free_elem(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4231 | } |
| 4232 | |
| 4233 | return NULL; |
| 4234 | } |
| 4235 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4236 | /* logs directly |
| 4237 | * |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4238 | * resolve - referenced grouping should be bounded to the namespace (resolved) |
| 4239 | * only when uses does not appear in grouping. In a case of grouping's uses, |
| 4240 | * we just get information but we do not apply augment or refine to it. |
| 4241 | */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4242 | static struct lys_node * |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4243 | 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] | 4244 | struct unres_schema *unres) |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4245 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4246 | struct lyxml_elem *sub, *next; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4247 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4248 | struct lys_node_uses *uses; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4249 | const char *value; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4250 | int c_ref = 0, c_aug = 0, c_ftrs = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4251 | int r; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4252 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4253 | uses = calloc(1, sizeof *uses); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4254 | uses->nodetype = LYS_USES; |
| 4255 | uses->prev = (struct lys_node *)uses; |
| 4256 | retval = (struct lys_node *)uses; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4257 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4258 | GETVAL(value, yin, "name"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4259 | uses->name = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 4260 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4261 | if (read_yin_common(module, parent, retval, yin, OPT_MODULE | OPT_NACMEXT | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4262 | goto error; |
| 4263 | } |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4264 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4265 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4266 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4267 | /* get other properties of uses */ |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4268 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4269 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4270 | /* garbage */ |
| 4271 | lyxml_free_elem(module->ctx, sub); |
| 4272 | continue; |
| 4273 | } |
| 4274 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4275 | if (!strcmp(sub->name, "refine")) { |
| 4276 | c_ref++; |
| 4277 | } else if (!strcmp(sub->name, "augment")) { |
| 4278 | c_aug++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4279 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 56e8977 | 2015-06-19 10:00:54 +0200 | [diff] [blame] | 4280 | c_ftrs++; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4281 | } else if (!strcmp(sub->name, "when")) { |
| 4282 | if (uses->when) { |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4283 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4284 | goto error; |
| 4285 | } |
| 4286 | |
| 4287 | uses->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4288 | if (!uses->when) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4289 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4290 | goto error; |
| 4291 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 4292 | if (unres_schema_add_node(module, unres, uses->when, UNRES_WHEN, retval, LOGLINE(sub)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4293 | goto error; |
| 4294 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4295 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4296 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4297 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4298 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4299 | } |
| 4300 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4301 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4302 | /* process properties with cardinality 0..n */ |
| 4303 | if (c_ref) { |
| 4304 | uses->refine = calloc(c_ref, sizeof *uses->refine); |
| 4305 | } |
| 4306 | if (c_aug) { |
| 4307 | uses->augment = calloc(c_aug, sizeof *uses->augment); |
| 4308 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4309 | if (c_ftrs) { |
| 4310 | uses->features = calloc(c_ftrs, sizeof *uses->features); |
| 4311 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4312 | |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 4313 | if (lys_node_addchild(parent, module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4314 | goto error; |
| 4315 | } |
| 4316 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4317 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4318 | if (!strcmp(sub->name, "refine")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4319 | r = fill_yin_refine(module, sub, &uses->refine[uses->refine_size++], uses, unres); |
| 4320 | if (r) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4321 | goto error; |
| 4322 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4323 | } else if (!strcmp(sub->name, "augment")) { |
| 4324 | r = fill_yin_augment(module, retval, sub, &uses->augment[uses->augment_size++], unres); |
| 4325 | if (r) { |
| 4326 | goto error; |
| 4327 | } |
| 4328 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4329 | GETVAL(value, sub, "name"); |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 4330 | 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] | 4331 | LOGLINE(sub)) == -1) { |
| 4332 | goto error; |
| 4333 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4334 | } |
| 4335 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4336 | |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 4337 | 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] | 4338 | goto error; |
| 4339 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4340 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4341 | if (resolve) { |
| 4342 | /* inherit config flag */ |
| 4343 | if (parent) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4344 | retval->flags |= parent->flags & LYS_CONFIG_MASK; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4345 | } else { |
| 4346 | /* default config is true */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4347 | retval->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4348 | } |
| 4349 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 4350 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4351 | return retval; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4352 | |
| 4353 | error: |
| 4354 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4355 | lys_node_free(retval); |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4356 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4357 | return NULL; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4358 | } |
| 4359 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4360 | /* logs directly |
| 4361 | * |
| 4362 | * common code for yin_read_module() and yin_read_submodule() |
| 4363 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4364 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4365 | 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] | 4366 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4367 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4368 | struct lys_submodule *submodule = (struct lys_submodule *)module; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4369 | struct lyxml_elem *next, *child, *child2, root, grps, rpcs, notifs; |
| 4370 | struct lys_node *node = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4371 | const char *value; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4372 | int i, r; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4373 | int belongsto_flag = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4374 | /* counters */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4375 | 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] | 4376 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4377 | /* init */ |
| 4378 | memset(&root, 0, sizeof root); |
| 4379 | memset(&grps, 0, sizeof grps); |
| 4380 | memset(&rpcs, 0, sizeof rpcs); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4381 | memset(¬ifs, 0, sizeof notifs); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4382 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4383 | /* |
| 4384 | * in the first run, we process elements with cardinality of 1 or 0..1 and |
| 4385 | * count elements with cardinality 0..n. Data elements (choices, containers, |
| 4386 | * leafs, lists, leaf-lists) are moved aside to be processed last, since we |
| 4387 | * need have all top-level and groupings already prepared at that time. In |
| 4388 | * the middle loop, we process other elements with carinality of 0..n since |
| 4389 | * we need to allocate arrays to store them. |
| 4390 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4391 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 4392 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4393 | /* garbage */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4394 | lyxml_free_elem(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4395 | continue; |
| 4396 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4397 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4398 | if (!module->type && !strcmp(child->name, "namespace")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4399 | if (module->ns) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4400 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4401 | goto error; |
| 4402 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4403 | GETVAL(value, child, "uri"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4404 | module->ns = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4405 | lyxml_free_elem(ctx, child); |
| 4406 | } else if (!module->type && !strcmp(child->name, "prefix")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4407 | if (module->prefix) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4408 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4409 | goto error; |
| 4410 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4411 | GETVAL(value, child, "value"); |
| 4412 | if (check_identifier(value, LY_IDENT_PREFIX, LOGLINE(child), module, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4413 | goto error; |
| 4414 | } |
| 4415 | module->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4416 | lyxml_free_elem(ctx, child); |
| 4417 | } else if (module->type && !strcmp(child->name, "belongs-to")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4418 | if (belongsto_flag) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4419 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4420 | goto error; |
| 4421 | } |
| 4422 | belongsto_flag = 1; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4423 | GETVAL(value, child, "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4424 | while (submodule->belongsto->type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4425 | submodule->belongsto = ((struct lys_submodule *)submodule->belongsto)->belongsto; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4426 | } |
| 4427 | if (value != submodule->belongsto->name) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4428 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4429 | goto error; |
| 4430 | } |
Radek Krejci | f388693 | 2015-06-04 17:36:06 +0200 | [diff] [blame] | 4431 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4432 | /* get the prefix substatement, start with checks */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4433 | if (!child->child) { |
| 4434 | LOGVAL(LYE_MISSSTMT2, LOGLINE(child), "prefix", child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4435 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4436 | } else if (strcmp(child->child->name, "prefix")) { |
| 4437 | LOGVAL(LYE_INSTMT, LOGLINE(child->child), child->child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4438 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4439 | } else if (child->child->next) { |
| 4440 | LOGVAL(LYE_INSTMT, LOGLINE(child->child->next), child->child->next->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4441 | goto error; |
| 4442 | } |
| 4443 | /* and now finally get the value */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4444 | GETVAL(value, child->child, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4445 | /* check here differs from a generic prefix check, since this prefix |
| 4446 | * don't have to be unique |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4447 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4448 | if (check_identifier(value, LY_IDENT_NAME, LOGLINE(child->child), NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4449 | goto error; |
| 4450 | } |
| 4451 | module->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 0af1387 | 2015-05-30 11:50:52 +0200 | [diff] [blame] | 4452 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4453 | /* we are done with belongs-to */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4454 | lyxml_free_elem(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4455 | |
| 4456 | /* counters (statements with n..1 cardinality) */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4457 | } else if (!strcmp(child->name, "import")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4458 | c_imp++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4459 | } else if (!strcmp(child->name, "revision")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4460 | c_rev++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4461 | } else if (!strcmp(child->name, "typedef")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4462 | c_tpdf++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4463 | } else if (!strcmp(child->name, "identity")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4464 | c_ident++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4465 | } else if (!strcmp(child->name, "include")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4466 | c_inc++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4467 | } else if (!strcmp(child->name, "augment")) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4468 | c_aug++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4469 | } else if (!strcmp(child->name, "feature")) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4470 | c_ftrs++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4471 | } else if (!strcmp(child->name, "deviation")) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4472 | c_dev++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4473 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4474 | /* data statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4475 | } else if (!strcmp(child->name, "container") || |
| 4476 | !strcmp(child->name, "leaf-list") || |
| 4477 | !strcmp(child->name, "leaf") || |
| 4478 | !strcmp(child->name, "list") || |
| 4479 | !strcmp(child->name, "choice") || |
| 4480 | !strcmp(child->name, "uses") || |
| 4481 | !strcmp(child->name, "anyxml")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4482 | lyxml_unlink_elem(module->ctx, child, 1); |
| 4483 | lyxml_add_child(module->ctx, &root, child); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4484 | } else if (!strcmp(child->name, "grouping")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4485 | /* keep groupings separated and process them before other data statements */ |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4486 | lyxml_unlink_elem(module->ctx, child, 1); |
| 4487 | lyxml_add_child(module->ctx, &grps, child); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4488 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4489 | /* optional statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4490 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4491 | if (module->dsc) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4492 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4493 | goto error; |
| 4494 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4495 | module->dsc = read_yin_subnode(ctx, child, "text"); |
| 4496 | lyxml_free_elem(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4497 | if (!module->dsc) { |
| 4498 | goto error; |
| 4499 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4500 | } else if (!strcmp(child->name, "reference")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4501 | if (module->ref) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4502 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4503 | goto error; |
| 4504 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4505 | module->ref = read_yin_subnode(ctx, child, "text"); |
| 4506 | lyxml_free_elem(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4507 | if (!module->ref) { |
| 4508 | goto error; |
| 4509 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4510 | } else if (!strcmp(child->name, "organization")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4511 | if (module->org) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4512 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4513 | goto error; |
| 4514 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4515 | module->org = read_yin_subnode(ctx, child, "text"); |
| 4516 | lyxml_free_elem(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4517 | if (!module->org) { |
| 4518 | goto error; |
| 4519 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4520 | } else if (!strcmp(child->name, "contact")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4521 | if (module->contact) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4522 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4523 | goto error; |
| 4524 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4525 | module->contact = read_yin_subnode(ctx, child, "text"); |
| 4526 | lyxml_free_elem(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4527 | if (!module->contact) { |
| 4528 | goto error; |
| 4529 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4530 | } else if (!strcmp(child->name, "yang-version")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4531 | /* TODO: support YANG 1.1 ? */ |
| 4532 | if (module->version) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4533 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4534 | goto error; |
| 4535 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4536 | GETVAL(value, child, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4537 | if (strcmp(value, "1")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4538 | LOGVAL(LYE_INARG, LOGLINE(child), value, "yang-version"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4539 | goto error; |
| 4540 | } |
| 4541 | module->version = 1; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4542 | lyxml_free_elem(ctx, child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4543 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4544 | /* rpcs & notifications */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4545 | } else if (!strcmp(child->name, "rpc")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4546 | lyxml_unlink_elem(module->ctx, child, 1); |
| 4547 | lyxml_add_child(module->ctx, &rpcs, child); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4548 | } else if (!strcmp(child->name, "notification")) { |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4549 | lyxml_unlink_elem(module->ctx, child, 1); |
| 4550 | lyxml_add_child(module->ctx, ¬ifs, child); |
Radek Krejci | 5166a89 | 2015-07-02 16:44:24 +0200 | [diff] [blame] | 4551 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4552 | } else if (!strcmp(child->name, "extension")) { |
| 4553 | GETVAL(value, child, "name"); |
Radek Krejci | 5166a89 | 2015-07-02 16:44:24 +0200 | [diff] [blame] | 4554 | |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 4555 | /* we have 2 supported (hardcoded) extensions: |
| 4556 | * NACM's default-deny-write and default-deny-all |
| 4557 | */ |
| 4558 | if (strcmp(module->ns, LY_NSNACM) || |
| 4559 | (strcmp(value, "default-deny-write") && strcmp(value, "default-deny-all"))) { |
| 4560 | LOGWRN("Not supported \"%s\" extension statement found, ignoring.", value); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4561 | lyxml_free_elem(ctx, child); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 4562 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4563 | } else { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4564 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4565 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4566 | } |
| 4567 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4568 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4569 | if (!submodule) { |
| 4570 | /* check for mandatory statements */ |
| 4571 | if (!module->ns) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4572 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "namespace", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4573 | goto error; |
| 4574 | } |
| 4575 | if (!module->prefix) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4576 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "prefix", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4577 | goto error; |
| 4578 | } |
| 4579 | } |
Radek Krejci | bb3257d | 2015-05-21 23:03:51 +0200 | [diff] [blame] | 4580 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4581 | /* allocate arrays for elements with cardinality of 0..n */ |
| 4582 | if (c_imp) { |
| 4583 | module->imp = calloc(c_imp, sizeof *module->imp); |
| 4584 | } |
| 4585 | if (c_rev) { |
| 4586 | module->rev = calloc(c_rev, sizeof *module->rev); |
| 4587 | } |
| 4588 | if (c_tpdf) { |
| 4589 | module->tpdf = calloc(c_tpdf, sizeof *module->tpdf); |
| 4590 | } |
| 4591 | if (c_ident) { |
| 4592 | module->ident = calloc(c_ident, sizeof *module->ident); |
| 4593 | } |
| 4594 | if (c_inc) { |
| 4595 | module->inc = calloc(c_inc, sizeof *module->inc); |
| 4596 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4597 | if (c_aug) { |
| 4598 | module->augment = calloc(c_aug, sizeof *module->augment); |
| 4599 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4600 | if (c_ftrs) { |
| 4601 | module->features = calloc(c_ftrs, sizeof *module->features); |
| 4602 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4603 | if (c_dev) { |
| 4604 | module->deviation = calloc(c_dev, sizeof *module->deviation); |
| 4605 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4606 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4607 | /* 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] | 4608 | LY_TREE_FOR(yin->child, child) { |
| 4609 | if (!strcmp(child->name, "import")) { |
| 4610 | r = fill_yin_import(module, child, &module->imp[module->imp_size]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4611 | module->imp_size++; |
| 4612 | if (r) { |
| 4613 | goto error; |
| 4614 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4615 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4616 | /* check duplicities in imported modules */ |
| 4617 | for (i = 0; i < module->imp_size - 1; i++) { |
| 4618 | 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] | 4619 | 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] | 4620 | goto error; |
| 4621 | } |
| 4622 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4623 | } else if (!strcmp(child->name, "include")) { |
| 4624 | r = fill_yin_include(module, child, &module->inc[module->inc_size]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4625 | module->inc_size++; |
| 4626 | if (r) { |
| 4627 | goto error; |
| 4628 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4629 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4630 | /* check duplications in include submodules */ |
| 4631 | for (i = 0; i < module->inc_size - 1; i++) { |
| 4632 | 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] | 4633 | LOGVAL(LYE_SPEC, LOGLINE(child), "Importing module \"%s\" repeatedly.", |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4634 | module->inc[i].submodule->name); |
| 4635 | goto error; |
| 4636 | } |
| 4637 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4638 | } else if (!strcmp(child->name, "revision")) { |
| 4639 | GETVAL(value, child, "date"); |
| 4640 | if (check_date(value, LOGLINE(child))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4641 | goto error; |
| 4642 | } |
| 4643 | memcpy(module->rev[module->rev_size].date, value, LY_REV_SIZE - 1); |
| 4644 | /* check uniqueness of the revision date - not required by RFC */ |
| 4645 | for (i = 0; i < module->rev_size; i++) { |
| 4646 | if (!strcmp(value, module->rev[i].date)) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4647 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4648 | LOGVAL(LYE_SPEC, 0, "Revision is not unique."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4649 | } |
| 4650 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4651 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4652 | LY_TREE_FOR(child->child, child2) { |
| 4653 | if (!strcmp(child2->name, "description")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4654 | if (module->rev[module->rev_size].dsc) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4655 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child2->name, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4656 | goto error; |
| 4657 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4658 | module->rev[module->rev_size].dsc = read_yin_subnode(ctx, child2, "text"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4659 | if (!module->rev[module->rev_size].dsc) { |
| 4660 | goto error; |
| 4661 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4662 | } else if (!strcmp(child2->name, "reference")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4663 | if (module->rev[module->rev_size].ref) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4664 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child2->name, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4665 | goto error; |
| 4666 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4667 | module->rev[module->rev_size].ref = read_yin_subnode(ctx, child2, "text"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4668 | if (!module->rev[module->rev_size].ref) { |
| 4669 | goto error; |
| 4670 | } |
| 4671 | } else { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4672 | LOGVAL(LYE_INSTMT, LOGLINE(child2), child2->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4673 | goto error; |
| 4674 | } |
| 4675 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4676 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4677 | /* keep the latest revision at position 0 */ |
| 4678 | if (module->rev_size && strcmp(module->rev[module->rev_size].date, module->rev[0].date) > 0) { |
| 4679 | /* switch their position */ |
| 4680 | value = strdup(module->rev[0].date); |
| 4681 | memcpy(module->rev[0].date, module->rev[module->rev_size].date, LY_REV_SIZE - 1); |
| 4682 | memcpy(module->rev[module->rev_size].date, value, LY_REV_SIZE - 1); |
| 4683 | free((char *)value); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4684 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4685 | if (module->rev[0].dsc != module->rev[module->rev_size].dsc) { |
| 4686 | value = module->rev[0].dsc; |
| 4687 | module->rev[0].dsc = module->rev[module->rev_size].dsc; |
| 4688 | module->rev[module->rev_size].dsc = value; |
| 4689 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4690 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4691 | if (module->rev[0].ref != module->rev[module->rev_size].ref) { |
| 4692 | value = module->rev[0].ref; |
| 4693 | module->rev[0].ref = module->rev[module->rev_size].ref; |
| 4694 | module->rev[module->rev_size].ref = value; |
| 4695 | } |
| 4696 | } |
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 | module->rev_size++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4699 | } else if (!strcmp(child->name, "typedef")) { |
| 4700 | 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] | 4701 | module->tpdf_size++; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 4702 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4703 | if (r) { |
| 4704 | goto error; |
| 4705 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4706 | } else if (!strcmp(child->name, "identity")) { |
| 4707 | r = fill_yin_identity(module, child, &module->ident[module->ident_size], unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4708 | module->ident_size++; |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 4709 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4710 | if (r) { |
| 4711 | goto error; |
| 4712 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4713 | } else if (!strcmp(child->name, "feature")) { |
| 4714 | r = fill_yin_feature(module, child, &module->features[module->features_size], unres); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4715 | module->features_size++; |
| 4716 | |
| 4717 | if (r) { |
| 4718 | goto error; |
| 4719 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4720 | } else if (!strcmp(child->name, "augment")) { |
| 4721 | 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] | 4722 | module->augment_size++; |
| 4723 | |
| 4724 | if (r) { |
| 4725 | goto error; |
| 4726 | } |
| 4727 | |
| 4728 | /* node is reconnected into the augment, so we have to skip its free at the end of the loop */ |
| 4729 | continue; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4730 | } else if (!strcmp(child->name, "deviation")) { |
| 4731 | r = fill_yin_deviation(module, child, &module->deviation[module->deviation_size]); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4732 | module->deviation_size++; |
| 4733 | |
| 4734 | if (r) { |
| 4735 | goto error; |
| 4736 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4737 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4738 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4739 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4740 | /* process data nodes. Start with groupings to allow uses |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4741 | * refer to them |
| 4742 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4743 | LY_TREE_FOR_SAFE(grps.child, next, child) { |
| 4744 | node = read_yin_grouping(module, NULL, child, 0, unres); |
| 4745 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4746 | goto error; |
| 4747 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4748 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4749 | lyxml_free_elem(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4750 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4751 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4752 | /* parse data nodes, ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4753 | LY_TREE_FOR_SAFE(root.child, next, child) { |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4754 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4755 | if (!strcmp(child->name, "container")) { |
| 4756 | node = read_yin_container(module, NULL, child, 1, unres); |
| 4757 | } else if (!strcmp(child->name, "leaf-list")) { |
| 4758 | node = read_yin_leaflist(module, NULL, child, 1, unres); |
| 4759 | } else if (!strcmp(child->name, "leaf")) { |
| 4760 | node = read_yin_leaf(module, NULL, child, 1, unres); |
| 4761 | } else if (!strcmp(child->name, "list")) { |
| 4762 | node = read_yin_list(module, NULL, child, 1, unres); |
| 4763 | } else if (!strcmp(child->name, "choice")) { |
| 4764 | node = read_yin_choice(module, NULL, child, 1, unres); |
| 4765 | } else if (!strcmp(child->name, "uses")) { |
| 4766 | node = read_yin_uses(module, NULL, child, 1, unres); |
| 4767 | } else if (!strcmp(child->name, "anyxml")) { |
| 4768 | node = read_yin_anyxml(module, NULL, child, 1, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4769 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4770 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4771 | goto error; |
| 4772 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 4773 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4774 | lyxml_free_elem(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4775 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4776 | |
| 4777 | /* ... rpcs ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4778 | LY_TREE_FOR_SAFE(rpcs.child, next, child) { |
| 4779 | node = read_yin_rpc(module, NULL, child, 0, unres); |
| 4780 | if (!node) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4781 | goto error; |
| 4782 | } |
| 4783 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4784 | lyxml_free_elem(ctx, child); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4785 | } |
| 4786 | |
| 4787 | /* ... and notifications */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4788 | LY_TREE_FOR_SAFE(notifs.child, next, child) { |
| 4789 | node = read_yin_notif(module, NULL, child, 0, unres); |
| 4790 | if (!node) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4791 | goto error; |
| 4792 | } |
| 4793 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4794 | lyxml_free_elem(ctx, child); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4795 | } |
| 4796 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4797 | return EXIT_SUCCESS; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4798 | |
| 4799 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4800 | /* cleanup */ |
| 4801 | while (root.child) { |
| 4802 | lyxml_free_elem(module->ctx, root.child); |
| 4803 | } |
| 4804 | while (grps.child) { |
| 4805 | lyxml_free_elem(module->ctx, grps.child); |
| 4806 | } |
| 4807 | while (rpcs.child) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4808 | lyxml_free_elem(module->ctx, rpcs.child); |
| 4809 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4810 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4811 | free(unres->item); |
| 4812 | unres->item = NULL; |
| 4813 | free(unres->type); |
| 4814 | unres->type = NULL; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4815 | free(unres->str_snode); |
| 4816 | unres->str_snode = NULL; |
Michal Vasko | c07187d | 2015-08-13 15:20:57 +0200 | [diff] [blame] | 4817 | #ifndef NDEBUG |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4818 | free(unres->line); |
| 4819 | unres->line = NULL; |
Michal Vasko | c07187d | 2015-08-13 15:20:57 +0200 | [diff] [blame] | 4820 | #endif |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4821 | unres->count = 0; |
Radek Krejci | 8de7b0f | 2015-07-02 11:43:42 +0200 | [diff] [blame] | 4822 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4823 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4824 | } |
| 4825 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4826 | /* logs directly */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4827 | struct lys_submodule * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4828 | 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] | 4829 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4830 | struct lyxml_elem *yin; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4831 | struct lys_submodule *submodule = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4832 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4833 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4834 | assert(module->ctx); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4835 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4836 | yin = lyxml_read(module->ctx, data, 0); |
| 4837 | if (!yin) { |
| 4838 | return NULL; |
| 4839 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4840 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4841 | /* check root element */ |
| 4842 | if (!yin->name || strcmp(yin->name, "submodule")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4843 | LOGVAL(LYE_INSTMT, LOGLINE(yin), yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4844 | goto error; |
| 4845 | } |
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 | GETVAL(value, yin, "name"); |
| 4848 | if (check_identifier(value, LY_IDENT_NAME, LOGLINE(yin), NULL, NULL)) { |
| 4849 | goto error; |
| 4850 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4851 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4852 | submodule = calloc(1, sizeof *submodule); |
| 4853 | if (!submodule) { |
| 4854 | LOGMEM; |
| 4855 | goto error; |
| 4856 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4857 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4858 | submodule->ctx = module->ctx; |
| 4859 | submodule->name = lydict_insert(submodule->ctx, value, strlen(value)); |
| 4860 | submodule->type = 1; |
| 4861 | submodule->belongsto = module; |
Michal Vasko | d8aa32d | 2015-07-24 11:50:01 +0200 | [diff] [blame] | 4862 | submodule->implemented = (implement ? 1 : 0); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4863 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4864 | LOGVRB("reading submodule %s", submodule->name); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4865 | if (read_sub_module((struct lys_module *)submodule, yin, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4866 | goto error; |
| 4867 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4868 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4869 | /* cleanup */ |
| 4870 | lyxml_free_elem(module->ctx, yin); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4871 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4872 | LOGVRB("submodule %s successfully parsed", submodule->name); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4873 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4874 | return submodule; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4875 | |
| 4876 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4877 | /* cleanup */ |
| 4878 | lyxml_free_elem(module->ctx, yin); |
Michal Vasko | 13b1583 | 2015-08-19 11:04:48 +0200 | [diff] [blame] | 4879 | lys_submodule_free(submodule, 0); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4880 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4881 | return NULL; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4882 | } |
| 4883 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4884 | /* logs directly */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4885 | struct lys_module * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4886 | 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] | 4887 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4888 | struct lyxml_elem *yin; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4889 | struct lys_module *module = NULL, **newlist = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4890 | const char *value; |
| 4891 | int i; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4892 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4893 | yin = lyxml_read(ctx, data, 0); |
| 4894 | if (!yin) { |
| 4895 | return NULL; |
| 4896 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4897 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4898 | /* check root element */ |
| 4899 | if (!yin->name || strcmp(yin->name, "module")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4900 | LOGVAL(LYE_INSTMT, LOGLINE(yin), yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4901 | goto error; |
| 4902 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4903 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4904 | GETVAL(value, yin, "name"); |
| 4905 | if (check_identifier(value, LY_IDENT_NAME, LOGLINE(yin), NULL, NULL)) { |
| 4906 | goto error; |
| 4907 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4908 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4909 | module = calloc(1, sizeof *module); |
| 4910 | if (!module) { |
| 4911 | LOGMEM; |
| 4912 | goto error; |
| 4913 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4914 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4915 | module->ctx = ctx; |
| 4916 | module->name = lydict_insert(ctx, value, strlen(value)); |
| 4917 | module->type = 0; |
Michal Vasko | d8aa32d | 2015-07-24 11:50:01 +0200 | [diff] [blame] | 4918 | module->implemented = (implement ? 1 : 0); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4919 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4920 | LOGVRB("reading module %s", module->name); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4921 | if (read_sub_module(module, yin, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4922 | goto error; |
| 4923 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4924 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4925 | /* add to the context's list of modules */ |
| 4926 | if (ctx->models.used == ctx->models.size) { |
| 4927 | newlist = realloc(ctx->models.list, ctx->models.size * 2); |
| 4928 | if (!newlist) { |
| 4929 | LOGMEM; |
| 4930 | goto error; |
| 4931 | } |
| 4932 | for (i = ctx->models.size; i < ctx->models.size * 2; i++) { |
| 4933 | newlist[i] = NULL; |
| 4934 | } |
| 4935 | ctx->models.size *= 2; |
| 4936 | ctx->models.list = newlist; |
| 4937 | } |
| 4938 | for (i = 0; ctx->models.list[i]; i++) { |
| 4939 | /* check name (name/revision) and namespace uniqueness */ |
| 4940 | if (!strcmp(ctx->models.list[i]->name, module->name)) { |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 4941 | if (ctx->models.list[i]->rev_size == module->rev_size) { |
| 4942 | /* both have the same number of revisions */ |
| 4943 | if (!module->rev_size || !strcmp(ctx->models.list[i]->rev[0].date, module->rev[0].date)) { |
| 4944 | /* both have the same revision -> we already have the same module */ |
| 4945 | /* so free the new one and update the old one's implement flag if needed */ |
| 4946 | lyxml_free_elem(ctx, yin); |
Michal Vasko | 13b1583 | 2015-08-19 11:04:48 +0200 | [diff] [blame] | 4947 | lys_free(module, 0); |
Michal Vasko | aa21157 | 2015-08-13 13:55:39 +0200 | [diff] [blame] | 4948 | unres->count = 0; |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 4949 | |
| 4950 | LOGVRB("module %s already in context", ctx->models.list[i]->name); |
| 4951 | |
| 4952 | if (implement && !ctx->models.list[i]->implemented) { |
| 4953 | lyp_set_implemented(ctx->models.list[i]); |
| 4954 | } |
| 4955 | return ctx->models.list[i]; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4956 | } |
| 4957 | } |
Radek Krejci | f647e61 | 2015-07-30 11:36:07 +0200 | [diff] [blame] | 4958 | /* else (both elses) keep searching, for now the caller is just adding |
| 4959 | * another revision of an already present schema |
| 4960 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4961 | } else if (!strcmp(ctx->models.list[i]->ns, module->ns)) { |
| 4962 | LOGERR(LY_EINVAL, "Two different modules (\"%s\" and \"%s\") have the same namespace \"%s\"", |
| 4963 | ctx->models.list[i]->name, module->name, module->ns); |
| 4964 | goto error; |
| 4965 | } |
| 4966 | } |
| 4967 | ctx->models.list[i] = module; |
| 4968 | ctx->models.used++; |
Michal Vasko | 68cffd7 | 2015-08-03 12:50:11 +0200 | [diff] [blame] | 4969 | ctx->models.module_set_id++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4970 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4971 | /* cleanup */ |
| 4972 | lyxml_free_elem(ctx, yin); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4973 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4974 | LOGVRB("module %s successfully parsed", module->name); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4975 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4976 | return module; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4977 | |
| 4978 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4979 | /* cleanup */ |
| 4980 | lyxml_free_elem(ctx, yin); |
Michal Vasko | 13b1583 | 2015-08-19 11:04:48 +0200 | [diff] [blame] | 4981 | lys_free(module, 0); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4982 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4983 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4984 | } |