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> |
| 31 | #include <regex.h> |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 32 | |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 33 | #include "../libyang.h" |
| 34 | #include "../common.h" |
| 35 | #include "../context.h" |
| 36 | #include "../dict.h" |
| 37 | #include "../parser.h" |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 38 | #include "../parse.h" |
| 39 | #include "../resolve.h" |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 40 | #include "../tree_internal.h" |
| 41 | #include "../xml.h" |
| 42 | |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 43 | enum LY_IDENT { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 44 | LY_IDENT_SIMPLE, /* only syntax rules */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 45 | LY_IDENT_FEATURE, |
| 46 | LY_IDENT_IDENTITY, |
| 47 | LY_IDENT_TYPE, |
| 48 | LY_IDENT_NODE, |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 49 | LY_IDENT_NAME, /* uniqueness across the siblings */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 50 | LY_IDENT_PREFIX |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 51 | }; |
| 52 | |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 53 | #define LY_NSYIN "urn:ietf:params:xml:ns:yang:yin:1" |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 54 | #define LY_NSNACM "urn:ietf:params:xml:ns:yang:ietf-netconf-acm" |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 55 | |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 56 | #define GETVAL(value, node, arg) \ |
| 57 | value = lyxml_get_attr(node, arg, NULL); \ |
| 58 | if (!value) { \ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 59 | LOGVAL(LYE_MISSARG, LOGLINE(node), arg, node->name); \ |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 60 | goto error; \ |
| 61 | } |
| 62 | |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 63 | #define OPT_IDENT 0x01 |
| 64 | #define OPT_CONFIG 0x02 |
| 65 | #define OPT_MODULE 0x04 |
| 66 | #define OPT_INHERIT 0x08 |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 67 | #define OPT_NACMEXT 0x10 |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 68 | 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] | 69 | |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 70 | static struct lys_node *read_yin_choice(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 71 | int resolve, struct unres_item *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 72 | static struct lys_node *read_yin_case(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 73 | int resolve, struct unres_item *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 74 | static struct lys_node *read_yin_anyxml(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 75 | int resolve, struct unres_item *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 76 | static struct lys_node *read_yin_container(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 77 | int resolve, struct unres_item *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 78 | static struct lys_node *read_yin_leaf(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 79 | int resolve, struct unres_item *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 80 | static struct lys_node *read_yin_leaflist(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 81 | int resolve, struct unres_item *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 82 | static struct lys_node *read_yin_list(struct lys_module *module,struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 83 | int resolve, struct unres_item *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 84 | static struct lys_node *read_yin_uses(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *node, |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 85 | int resolve, struct unres_item *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 86 | static struct lys_node *read_yin_grouping(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *node, |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 87 | int resolve, struct unres_item *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 88 | 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] | 89 | |
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 | |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 105 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 106 | dup_feature_check(const char *id, struct lys_module *module) |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 107 | { |
| 108 | int i; |
| 109 | |
| 110 | for (i = 0; i < module->features_size; i++) { |
| 111 | if (!strcmp(id, module->features[i].name)) { |
| 112 | return EXIT_FAILURE; |
| 113 | } |
| 114 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 115 | |
| 116 | return EXIT_SUCCESS; |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 117 | } |
| 118 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 119 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 120 | dup_prefix_check(const char *prefix, struct lys_module *module) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 121 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 122 | int i; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 123 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 124 | if (!module->type && module->prefix && !strcmp(module->prefix, prefix)) { |
| 125 | return EXIT_FAILURE; |
| 126 | } |
| 127 | for (i = 0; i < module->imp_size; i++) { |
| 128 | if (!strcmp(module->imp[i].prefix, prefix)) { |
| 129 | return EXIT_FAILURE; |
| 130 | } |
| 131 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 132 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 133 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 134 | } |
| 135 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 136 | static int |
| 137 | check_identifier(const char *id, enum LY_IDENT type, unsigned int line, |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 138 | struct lys_module *module, struct lys_node *parent) |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 139 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 140 | int i; |
| 141 | int size; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 142 | struct lys_tpdf *tpdf; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 143 | struct lys_node *mnode; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 144 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 145 | assert(id); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 146 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 147 | /* check id syntax */ |
| 148 | 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^] | 149 | LOGVAL(LYE_INID, line, id, "invalid start character"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 150 | return EXIT_FAILURE; |
| 151 | } |
| 152 | for (i = 1; id[i]; i++) { |
| 153 | if (!(id[i] >= 'A' && id[i] <= 'Z') && !(id[i] >= 'a' && id[i] <= 'z') |
| 154 | && !(id[i] >= '0' && id[i] <= '9') && id[i] != '_' && id[i] != '-' && id[i] != '.') { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 155 | LOGVAL(LYE_INID, line, id, "invalid character"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 156 | return EXIT_FAILURE; |
| 157 | } |
| 158 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 159 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 160 | if (i > 64) { |
| 161 | LOGWRN("Identifier \"%s\" is long, you should use something shorter.", id); |
| 162 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 163 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 164 | switch (type) { |
| 165 | case LY_IDENT_NAME: |
| 166 | /* check uniqueness of the node within its siblings */ |
| 167 | if (!parent) { |
| 168 | break; |
| 169 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 170 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 171 | LY_TREE_FOR(parent->child, mnode) { |
| 172 | if (mnode->name == id) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 173 | LOGVAL(LYE_INID, line, id, "name duplication"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 174 | return EXIT_FAILURE; |
| 175 | } |
| 176 | } |
| 177 | break; |
| 178 | case LY_IDENT_TYPE: |
| 179 | assert(module); |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 180 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 181 | /* check collision with the built-in types */ |
| 182 | if (!strcmp(id, "binary") || !strcmp(id, "bits") || |
| 183 | !strcmp(id, "boolean") || !strcmp(id, "decimal64") || |
| 184 | !strcmp(id, "empty") || !strcmp(id, "enumeration") || |
| 185 | !strcmp(id, "identityref") || !strcmp(id, "instance-identifier") || |
| 186 | !strcmp(id, "int8") || !strcmp(id, "int16") || |
| 187 | !strcmp(id, "int32") || !strcmp(id, "int64") || |
| 188 | !strcmp(id, "leafref") || !strcmp(id, "string") || |
| 189 | !strcmp(id, "uint8") || !strcmp(id, "uint16") || |
| 190 | !strcmp(id, "uint32") || !strcmp(id, "uint64") || !strcmp(id, "union")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 191 | LOGVAL(LYE_SPEC, line, "Typedef name duplicates built-in type."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 192 | return EXIT_FAILURE; |
| 193 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 194 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 195 | /* check locally scoped typedefs (avoid name shadowing) */ |
| 196 | for (; parent; parent = parent->parent) { |
| 197 | switch (parent->nodetype) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 198 | case LYS_CONTAINER: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 199 | size = ((struct lys_node_container *)parent)->tpdf_size; |
| 200 | tpdf = ((struct lys_node_container *)parent)->tpdf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 201 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 202 | case LYS_LIST: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 203 | size = ((struct lys_node_list *)parent)->tpdf_size; |
| 204 | tpdf = ((struct lys_node_list *)parent)->tpdf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 205 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 206 | case LYS_GROUPING: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 207 | size = ((struct lys_node_grp *)parent)->tpdf_size; |
| 208 | tpdf = ((struct lys_node_grp *)parent)->tpdf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 209 | break; |
| 210 | default: |
| 211 | continue; |
| 212 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 213 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 214 | if (dup_typedef_check(id, tpdf, size)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 215 | LOGVAL(LYE_DUPID, line, "typedef", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 216 | return EXIT_FAILURE; |
| 217 | } |
| 218 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 219 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 220 | /* check top-level names */ |
| 221 | if (dup_typedef_check(id, module->tpdf, module->tpdf_size)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 222 | LOGVAL(LYE_DUPID, line, "typedef", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 223 | return EXIT_FAILURE; |
| 224 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 225 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 226 | /* check submodule's top-level names */ |
| 227 | for (i = 0; i < module->inc_size; i++) { |
| 228 | 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^] | 229 | LOGVAL(LYE_DUPID, line, "typedef", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 230 | return EXIT_FAILURE; |
| 231 | } |
| 232 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 233 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 234 | /* check top-level names in the main module */ |
| 235 | if (module->type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 236 | if (dup_typedef_check(id, ((struct lys_submodule *)module)->belongsto->tpdf, |
| 237 | ((struct lys_submodule *)module)->belongsto->tpdf_size)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 238 | LOGVAL(LYE_DUPID, line, "typedef", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 239 | return EXIT_FAILURE; |
| 240 | } |
| 241 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 242 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 243 | break; |
| 244 | case LY_IDENT_PREFIX: |
| 245 | assert(module); |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 246 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 247 | if (module->type) { |
| 248 | /* go to the main module */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 249 | module = ((struct lys_submodule *)module)->belongsto; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 250 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 251 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 252 | /* check the main module itself */ |
| 253 | if (dup_prefix_check(id, module)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 254 | LOGVAL(LYE_DUPID, line, "prefix", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 255 | return EXIT_FAILURE; |
| 256 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 257 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 258 | /* and all its submodules */ |
| 259 | for (i = 0; i < module->inc_size; i++) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 260 | if (dup_prefix_check(id, (struct lys_module *)module->inc[i].submodule)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 261 | LOGVAL(LYE_DUPID, line, "prefix", id); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 262 | return EXIT_FAILURE; |
| 263 | } |
| 264 | } |
| 265 | break; |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 266 | case LY_IDENT_FEATURE: |
| 267 | assert(module); |
| 268 | |
| 269 | /* check feature name uniqness*/ |
Radek Krejci | 49babf3 | 2015-06-18 13:56:17 +0200 | [diff] [blame] | 270 | /* check features in the current module */ |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 271 | if (dup_feature_check(id, module)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 272 | LOGVAL(LYE_DUPID, line, "feature", id); |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 273 | return EXIT_FAILURE; |
| 274 | } |
| 275 | |
| 276 | /* and all its submodules */ |
| 277 | for (i = 0; i < module->inc_size; i++) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 278 | if (dup_feature_check(id, (struct lys_module *)module->inc[i].submodule)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 279 | LOGVAL(LYE_DUPID, line, "feature", id); |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 280 | return EXIT_FAILURE; |
| 281 | } |
| 282 | } |
| 283 | break; |
| 284 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 285 | default: |
| 286 | /* no check required */ |
| 287 | break; |
| 288 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 289 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 290 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 291 | } |
| 292 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 293 | static int |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 294 | check_mandatory(struct lys_node *mnode) |
Radek Krejci | 3de29a7 | 2015-06-16 15:23:03 +0200 | [diff] [blame] | 295 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 296 | struct lys_node *child; |
Radek Krejci | 3de29a7 | 2015-06-16 15:23:03 +0200 | [diff] [blame] | 297 | |
| 298 | assert(mnode); |
| 299 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 300 | if (mnode->flags & LYS_MAND_TRUE) { |
Radek Krejci | 3de29a7 | 2015-06-16 15:23:03 +0200 | [diff] [blame] | 301 | return EXIT_FAILURE; |
| 302 | } |
| 303 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 304 | if (mnode->nodetype == LYS_CASE || mnode->nodetype == LYS_CHOICE) { |
Radek Krejci | fd0bb0a | 2015-06-18 13:18:24 +0200 | [diff] [blame] | 305 | LY_TREE_FOR(mnode->child, child) { |
| 306 | if (check_mandatory(child)) { |
| 307 | return EXIT_FAILURE; |
| 308 | } |
Radek Krejci | 3de29a7 | 2015-06-16 15:23:03 +0200 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
| 312 | return EXIT_SUCCESS; |
| 313 | } |
| 314 | |
| 315 | static int |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 316 | check_date(const char *date, unsigned int line) |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 317 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 318 | int i; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 319 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 320 | assert(date); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 321 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 322 | if (strlen(date) != LY_REV_SIZE - 1) { |
| 323 | goto error; |
| 324 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 325 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 326 | for (i = 0; i < LY_REV_SIZE - 1; i++) { |
| 327 | if (i == 4 || i == 7) { |
| 328 | if (date[i] != '-') { |
| 329 | goto error; |
| 330 | } |
| 331 | } else if (!isdigit(date[i])) { |
| 332 | goto error; |
| 333 | } |
| 334 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 335 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 336 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 337 | |
| 338 | error: |
| 339 | |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 340 | LOGVAL(LYE_INDATE, line, date); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 341 | return EXIT_FAILURE; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 342 | } |
| 343 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 344 | static int |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 345 | check_length_range(const char *expr, struct lys_type *type, unsigned int line) |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 346 | { |
Michal Vasko | 9286afd | 2015-07-14 15:27:59 +0200 | [diff] [blame] | 347 | struct len_ran_intv *intv = NULL, *tmp_intv; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 348 | const char *c = expr; |
| 349 | char *tail; |
Michal Vasko | 9286afd | 2015-07-14 15:27:59 +0200 | [diff] [blame] | 350 | int ret = EXIT_FAILURE, flg = 1; /* first run flag */ |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 351 | |
| 352 | assert(expr); |
| 353 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 354 | lengthpart: |
| 355 | |
| 356 | while (isspace(*c)) { |
| 357 | c++; |
| 358 | } |
| 359 | |
| 360 | /* lower boundary or explicit number */ |
| 361 | if (!strncmp(c, "max", 3)) { |
| 362 | max: |
| 363 | c += 3; |
| 364 | while (isspace(*c)) { |
| 365 | c++; |
| 366 | } |
| 367 | if (*c != '\0') { |
| 368 | goto error; |
| 369 | } |
| 370 | |
Michal Vasko | 9286afd | 2015-07-14 15:27:59 +0200 | [diff] [blame] | 371 | goto syntax_ok; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 372 | |
| 373 | } else if (!strncmp(c, "min", 3)) { |
| 374 | if (!flg) { |
| 375 | /* min cannot be used elsewhere than in the first length-part */ |
| 376 | goto error; |
| 377 | } else { |
| 378 | flg = 0; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 379 | } |
| 380 | c += 3; |
| 381 | while (isspace(*c)) { |
| 382 | c++; |
| 383 | } |
| 384 | |
| 385 | if (*c == '|') { |
| 386 | c++; |
| 387 | /* process next length-parth */ |
| 388 | goto lengthpart; |
| 389 | } else if (*c == '\0') { |
Michal Vasko | 9286afd | 2015-07-14 15:27:59 +0200 | [diff] [blame] | 390 | goto syntax_ok; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 391 | } else if (!strncmp(c, "..", 2)) { |
| 392 | upper: |
| 393 | c += 2; |
| 394 | while (isspace(*c)) { |
| 395 | c++; |
| 396 | } |
| 397 | if (*c == '\0') { |
| 398 | goto error; |
| 399 | } |
| 400 | |
| 401 | /* upper boundary */ |
| 402 | if (!strncmp(c, "max", 3)) { |
| 403 | goto max; |
| 404 | } |
| 405 | |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 406 | if (!isdigit(*c) && (*c != '+') && (*c != '-')) { |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 407 | goto error; |
| 408 | } |
| 409 | |
Radek Krejci | b8ca108 | 2015-07-10 11:24:11 +0200 | [diff] [blame] | 410 | errno = 0; |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 411 | strtoll(c, &tail, 10); |
Radek Krejci | b8ca108 | 2015-07-10 11:24:11 +0200 | [diff] [blame] | 412 | if (errno) { |
| 413 | goto error; |
| 414 | } |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 415 | c = tail; |
| 416 | while (isspace(*c)) { |
| 417 | c++; |
| 418 | } |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 419 | if (*c == '\0') { |
Michal Vasko | 9286afd | 2015-07-14 15:27:59 +0200 | [diff] [blame] | 420 | goto syntax_ok; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 421 | } else if (*c == '|') { |
| 422 | c++; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 423 | /* process next length-parth */ |
| 424 | goto lengthpart; |
| 425 | } else { |
| 426 | goto error; |
| 427 | } |
| 428 | } else { |
| 429 | goto error; |
| 430 | } |
| 431 | |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 432 | } else if (isdigit(*c) || (*c == '-') || (*c == '+')) { |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 433 | /* number */ |
Radek Krejci | b8ca108 | 2015-07-10 11:24:11 +0200 | [diff] [blame] | 434 | errno = 0; |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 435 | strtoll(c, &tail, 10); |
Radek Krejci | b8ca108 | 2015-07-10 11:24:11 +0200 | [diff] [blame] | 436 | if (errno) { |
| 437 | /* out of range value */ |
| 438 | goto error; |
| 439 | } |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 440 | c = tail; |
| 441 | while (isspace(*c)) { |
| 442 | c++; |
| 443 | } |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 444 | |
| 445 | if (*c == '|') { |
| 446 | c++; |
| 447 | /* process next length-parth */ |
| 448 | goto lengthpart; |
| 449 | } else if (*c == '\0') { |
Michal Vasko | 9286afd | 2015-07-14 15:27:59 +0200 | [diff] [blame] | 450 | goto syntax_ok; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 451 | } else if (!strncmp(c, "..", 2)) { |
| 452 | goto upper; |
| 453 | } |
Michal Vasko | 9286afd | 2015-07-14 15:27:59 +0200 | [diff] [blame] | 454 | |
| 455 | } else { |
| 456 | goto error; |
| 457 | } |
| 458 | |
| 459 | syntax_ok: |
| 460 | |
Michal Vasko | 020404f | 2015-07-15 15:45:42 +0200 | [diff] [blame] | 461 | if (get_len_ran_interval(expr, type, 1, &intv)) { |
Michal Vasko | 9286afd | 2015-07-14 15:27:59 +0200 | [diff] [blame] | 462 | goto error; |
| 463 | } |
| 464 | |
| 465 | ret = EXIT_SUCCESS; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 466 | |
| 467 | error: |
| 468 | |
Michal Vasko | 9286afd | 2015-07-14 15:27:59 +0200 | [diff] [blame] | 469 | while (intv) { |
| 470 | tmp_intv = intv->next; |
| 471 | free(intv); |
| 472 | intv = tmp_intv; |
| 473 | } |
| 474 | |
| 475 | if (ret) { |
| 476 | LOGVAL(VE_INARG, line, expr, "length"); |
| 477 | } |
| 478 | |
| 479 | return ret; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 480 | } |
| 481 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 482 | static const char * |
| 483 | 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] | 484 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 485 | int len; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 486 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 487 | /* there should be <text> child */ |
| 488 | if (!node->child || !node->child->name || strcmp(node->child->name, name)) { |
| 489 | LOGWRN("Expected \"%s\" element in \"%s\" element.", name, node->name); |
| 490 | } else if (node->child->content) { |
| 491 | len = strlen(node->child->content); |
| 492 | return lydict_insert(ctx, node->child->content, len); |
| 493 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 494 | |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 495 | LOGVAL(LYE_INARG, LOGLINE(node), name, node->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 496 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 497 | } |
| 498 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 499 | static int |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 500 | fill_yin_identity(struct lys_module *module, struct lyxml_elem *yin, struct lys_ident *ident, struct unres_item *unres) |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 501 | { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 502 | struct lyxml_elem *node; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 503 | const char *value; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 504 | |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 505 | GETVAL(value, yin, "name"); |
| 506 | ident->name = lydict_insert(module->ctx, value, 0); |
| 507 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 508 | 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] | 509 | return EXIT_FAILURE; |
| 510 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 511 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 512 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 513 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 514 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 515 | continue; |
| 516 | } |
| 517 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 518 | if (!strcmp(node->name, "base")) { |
| 519 | if (ident->base) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 520 | LOGVAL(LYE_TOOMANY, LOGLINE(node), "base", "identity"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 521 | return EXIT_FAILURE; |
| 522 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 523 | GETVAL(value, node, "name"); |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 524 | add_unres_str(module, unres, ident, UNRES_IDENT, value, LOGLINE(node)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 525 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 526 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name, "identity"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 527 | return EXIT_FAILURE; |
| 528 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 529 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 530 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 531 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 532 | return EXIT_SUCCESS; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 533 | } |
| 534 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 535 | static int |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 536 | 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] | 537 | { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 538 | struct lyxml_elem *child; |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 539 | const char *value; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 540 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 541 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 542 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 543 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 544 | continue; |
| 545 | } |
| 546 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 547 | if (!strcmp(child->name, "description")) { |
| 548 | if (restr->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 549 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 550 | return EXIT_FAILURE; |
| 551 | } |
| 552 | restr->dsc = read_yin_subnode(ctx, child, "text"); |
| 553 | if (!restr->dsc) { |
| 554 | return EXIT_FAILURE; |
| 555 | } |
| 556 | } else if (!strcmp(child->name, "reference")) { |
| 557 | if (restr->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 558 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 559 | return EXIT_FAILURE; |
| 560 | } |
| 561 | restr->ref = read_yin_subnode(ctx, child, "text"); |
| 562 | if (!restr->ref) { |
| 563 | return EXIT_FAILURE; |
| 564 | } |
| 565 | } else if (!strcmp(child->name, "error-app-tag")) { |
| 566 | if (restr->eapptag) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 567 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 568 | return EXIT_FAILURE; |
| 569 | } |
Michal Vasko | 54e426f | 2015-07-07 15:38:02 +0200 | [diff] [blame] | 570 | GETVAL(value, child, "value"); |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 571 | restr->eapptag = lydict_insert(ctx, value, 0); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 572 | } else if (!strcmp(child->name, "error-message")) { |
| 573 | if (restr->emsg) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 574 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 575 | return EXIT_FAILURE; |
| 576 | } |
| 577 | restr->emsg = read_yin_subnode(ctx, child, "value"); |
| 578 | if (!restr->emsg) { |
| 579 | return EXIT_FAILURE; |
| 580 | } |
| 581 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 582 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 583 | return EXIT_FAILURE; |
| 584 | } |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | return EXIT_SUCCESS; |
Michal Vasko | c8ef47f | 2015-06-29 14:56:19 +0200 | [diff] [blame] | 588 | |
| 589 | error: |
| 590 | return EXIT_FAILURE; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 594 | fill_yin_type(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_type *type, |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 595 | struct unres_item *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 596 | { |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 597 | #define REGEX_ERR_LEN 128 |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 598 | const char *value, *delim, *name; |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 599 | char regex_err[REGEX_ERR_LEN]; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 600 | struct lyxml_elem *next, *node; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 601 | struct lys_restr **restr; |
| 602 | struct lys_type_bit bit; |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 603 | regex_t preq; |
| 604 | int i, j, ret; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 605 | int64_t v, v_; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 606 | int64_t p, p_; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 607 | |
Radek Krejci | 8de7b0f | 2015-07-02 11:43:42 +0200 | [diff] [blame] | 608 | GETVAL(value, yin, "name"); |
| 609 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 610 | delim = strchr(value, ':'); |
| 611 | if (delim) { |
| 612 | type->prefix = lydict_insert(module->ctx, value, delim - value); |
| 613 | delim++; |
| 614 | value += delim-value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 615 | } |
Radek Krejci | 667b97f | 2015-05-25 15:03:30 +0200 | [diff] [blame] | 616 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 617 | type->der = resolve_superior_type(value, type->prefix, module, parent); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 618 | if (!type->der) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 619 | /* HACK for unres */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 620 | type->der = (struct lys_tpdf *)parent; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 621 | add_unres_str(module, unres, type, UNRES_TYPE_DER, value, LOGLINE(yin)); |
| 622 | return EXIT_SUCCESS; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 623 | } |
| 624 | type->base = type->der->type.base; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 625 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 626 | switch (type->base) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 627 | case LY_TYPE_BITS: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 628 | /* RFC 6020 9.7.4 - bit */ |
| 629 | |
| 630 | /* get bit specifications, at least one must be present */ |
| 631 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 632 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 633 | /* garbage */ |
| 634 | lyxml_free_elem(module->ctx, node); |
| 635 | continue; |
| 636 | } |
| 637 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 638 | if (!strcmp(node->name, "bit")) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 639 | type->info.bits.count++; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 640 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 641 | LOGVAL(LYE_INSTMT, LOGLINE(yin->child), yin->child->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 642 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 643 | } |
| 644 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 645 | if (!type->der->type.der && !type->info.bits.count) { |
| 646 | /* 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^] | 647 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "bit", "type"); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 648 | goto error; |
| 649 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 650 | if (type->der->type.der && type->info.bits.count) { |
| 651 | /* 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^] | 652 | LOGVAL(LYE_INSTMT, LOGLINE(yin), "bit"); |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 653 | goto error; |
| 654 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 655 | |
| 656 | 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] | 657 | p = 0; |
| 658 | i = -1; |
| 659 | LY_TREE_FOR(yin->child, next) { |
| 660 | i++; |
| 661 | |
| 662 | GETVAL(value, next, "name"); |
| 663 | if (check_identifier(value, LY_IDENT_SIMPLE, LOGLINE(next), NULL, NULL)) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 664 | goto error; |
| 665 | } |
| 666 | 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] | 667 | 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] | 668 | type->info.bits.count = i + 1; |
| 669 | goto error; |
| 670 | } |
| 671 | |
| 672 | /* check the name uniqueness */ |
| 673 | for (j = 0; j < i; j++) { |
| 674 | 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^] | 675 | LOGVAL(LYE_BITS_DUPNAME, LOGLINE(next), type->info.bits.bit[i].name); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 676 | type->info.bits.count = i + 1; |
| 677 | goto error; |
| 678 | } |
| 679 | } |
| 680 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 681 | p_ = -1; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 682 | LY_TREE_FOR(next->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 683 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 684 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 685 | continue; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 686 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 687 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 688 | if (!strcmp(node->name, "position")) { |
| 689 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 690 | p_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 691 | |
| 692 | /* range check */ |
Radek Krejci | b8ca108 | 2015-07-10 11:24:11 +0200 | [diff] [blame] | 693 | if (p_ < 0 || p_ > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 694 | LOGVAL(LYE_INARG, LOGLINE(node), value, "bit/position"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 695 | type->info.bits.count = i + 1; |
| 696 | goto error; |
| 697 | } |
| 698 | type->info.bits.bit[i].pos = (uint32_t)p_; |
| 699 | |
| 700 | /* keep the highest enum value for automatic increment */ |
Michal Vasko | 9ab0594 | 2015-07-07 15:38:26 +0200 | [diff] [blame] | 701 | if (type->info.bits.bit[i].pos >= p) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 702 | p = type->info.bits.bit[i].pos; |
| 703 | p++; |
| 704 | } else { |
| 705 | /* check that the value is unique */ |
| 706 | for (j = 0; j < i; j++) { |
| 707 | 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^] | 708 | 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] | 709 | type->info.bits.count = i + 1; |
| 710 | goto error; |
| 711 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 712 | } |
| 713 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 714 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 715 | LOGVAL(LYE_INSTMT, LOGLINE(next), next->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 716 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 717 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 718 | } |
| 719 | if (p_ == -1) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 720 | /* assign value automatically */ |
| 721 | if (p > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 722 | LOGVAL(LYE_INARG, LOGLINE(next), "4294967295", "bit/position"); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 723 | type->info.bits.count = i + 1; |
| 724 | goto error; |
| 725 | } |
| 726 | type->info.bits.bit[i].pos = (uint32_t)p; |
| 727 | p++; |
| 728 | } |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 729 | |
| 730 | /* keep them ordered by position */ |
| 731 | j = i; |
| 732 | while (j && type->info.bits.bit[j - 1].pos > type->info.bits.bit[j].pos) { |
| 733 | /* switch them */ |
| 734 | memcpy(&bit, &type->info.bits.bit[j], sizeof bit); |
| 735 | memcpy(&type->info.bits.bit[j], &type->info.bits.bit[j - 1], sizeof bit); |
| 736 | memcpy(&type->info.bits.bit[j - 1], &bit, sizeof bit); |
| 737 | j--; |
| 738 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 739 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 740 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 741 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 742 | case LY_TYPE_DEC64: |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 743 | /* RFC 6020 9.2.4 - range and 9.3.4 - fraction-digits */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 744 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 745 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 746 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 747 | continue; |
| 748 | } |
| 749 | |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 750 | if (!strcmp(node->name, "range")) { |
| 751 | if (type->info.dec64.range) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 752 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 753 | goto error; |
| 754 | } |
| 755 | |
| 756 | GETVAL(value, node, "value"); |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 757 | if (check_length_range(value, type, LOGLINE(node))) { |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 758 | goto error; |
| 759 | } |
| 760 | type->info.dec64.range = calloc(1, sizeof *type->info.dec64.range); |
| 761 | type->info.dec64.range->expr = lydict_insert(module->ctx, value, 0); |
| 762 | |
| 763 | /* get possible substatements */ |
| 764 | if (read_restr_substmt(module->ctx, type->info.dec64.range, node)) { |
| 765 | goto error; |
| 766 | } |
| 767 | } else if (!strcmp(node->name, "fraction-digits")) { |
| 768 | if (type->info.dec64.dig) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 769 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 770 | goto error; |
| 771 | } |
| 772 | GETVAL(value, node, "value"); |
| 773 | v = strtol(value, NULL, 10); |
| 774 | |
| 775 | /* range check */ |
| 776 | if (v < 1 || v > 18) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 777 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 778 | goto error; |
| 779 | } |
| 780 | type->info.dec64.dig = (uint8_t)v; |
| 781 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 782 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 783 | goto error; |
| 784 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | /* mandatory sub-statement(s) check */ |
| 788 | if (!type->info.dec64.dig && !type->der->type.der) { |
| 789 | /* decimal64 type directly derived from built-in type requires fraction-digits */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 790 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "fraction-digits", "type"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 791 | goto error; |
| 792 | } |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 793 | if (type->info.dec64.dig && type->der->type.der) { |
| 794 | /* 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^] | 795 | LOGVAL(LYE_INSTMT, LOGLINE(yin), "fraction-digits"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 796 | goto error; |
| 797 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 798 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 799 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 800 | case LY_TYPE_ENUM: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 801 | /* RFC 6020 9.6 - enum */ |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 802 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 803 | /* get enum specifications, at least one must be present */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 804 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 805 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 806 | /* garbage */ |
| 807 | lyxml_free_elem(module->ctx, node); |
| 808 | continue; |
| 809 | } |
| 810 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 811 | if (!strcmp(node->name, "enum")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 812 | type->info.enums.count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 813 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 814 | LOGVAL(LYE_INSTMT, LOGLINE(yin->child), yin->child->name); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 815 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 816 | } |
| 817 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 818 | if (!type->der->type.der && !type->info.enums.count) { |
| 819 | /* 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^] | 820 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "enum", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 821 | goto error; |
| 822 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 823 | if (type->der->type.der && type->info.enums.count) { |
| 824 | /* 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^] | 825 | LOGVAL(LYE_INSTMT, LOGLINE(yin), "enum"); |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 826 | goto error; |
| 827 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 828 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 829 | 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] | 830 | v = 0; |
| 831 | i = -1; |
| 832 | LY_TREE_FOR(yin->child, next) { |
| 833 | i++; |
| 834 | |
| 835 | GETVAL(value, next, "name"); |
| 836 | if (check_identifier(value, LY_IDENT_SIMPLE, LOGLINE(next), NULL, NULL)) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 837 | goto error; |
| 838 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 839 | 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] | 840 | 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] | 841 | type->info.enums.count = i + 1; |
| 842 | goto error; |
| 843 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 844 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 845 | /* the assigned name MUST NOT have any leading or trailing whitespace characters */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 846 | value = type->info.enums.enm[i].name; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 847 | if (isspace(value[0]) || isspace(value[strlen(value) - 1])) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 848 | LOGVAL(LYE_ENUM_WS, LOGLINE(next), value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 849 | type->info.enums.count = i + 1; |
| 850 | goto error; |
| 851 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 852 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 853 | /* check the name uniqueness */ |
| 854 | for (j = 0; j < i; j++) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 855 | 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^] | 856 | LOGVAL(LYE_ENUM_DUPNAME, LOGLINE(next), type->info.enums.enm[i].name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 857 | type->info.enums.count = i + 1; |
| 858 | goto error; |
| 859 | } |
| 860 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 861 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 862 | v_ = -1; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 863 | LY_TREE_FOR(next->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 864 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 865 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 866 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 867 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 868 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 869 | if (!strcmp(node->name, "value")) { |
| 870 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 871 | v_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 872 | |
| 873 | /* range check */ |
| 874 | if (v_ < INT32_MIN || v_ > INT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 875 | LOGVAL(LYE_INARG, LOGLINE(node), value, "enum/value"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 876 | type->info.enums.count = i + 1; |
| 877 | goto error; |
| 878 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 879 | type->info.enums.enm[i].value = v_; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 880 | |
| 881 | /* keep the highest enum value for automatic increment */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 882 | if (type->info.enums.enm[i].value > v) { |
| 883 | v = type->info.enums.enm[i].value; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 884 | v++; |
| 885 | } else { |
| 886 | /* check that the value is unique */ |
| 887 | for (j = 0; j < i; j++) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 888 | 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^] | 889 | LOGVAL(LYE_ENUM_DUPVAL, LOGLINE(node), type->info.enums.enm[i].value, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 890 | type->info.enums.enm[i].name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 891 | type->info.enums.count = i + 1; |
| 892 | goto error; |
| 893 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 894 | } |
| 895 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 896 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 897 | LOGVAL(LYE_INSTMT, LOGLINE(next), next->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 898 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 899 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 900 | } |
| 901 | if (v_ == -1) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 902 | /* assign value automatically */ |
| 903 | if (v > INT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 904 | LOGVAL(LYE_INARG, LOGLINE(next), "2147483648", "enum/value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 905 | type->info.enums.count = i + 1; |
| 906 | goto error; |
| 907 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 908 | type->info.enums.enm[i].value = v; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 909 | v++; |
| 910 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 911 | } |
| 912 | break; |
| 913 | |
| 914 | case LY_TYPE_IDENT: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 915 | /* RFC 6020 9.10 - base */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 916 | |
| 917 | /* get base specification, exactly one must be present */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 918 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 919 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 920 | /* garbage */ |
| 921 | lyxml_free_elem(module->ctx, node); |
| 922 | continue; |
| 923 | } |
| 924 | |
| 925 | if (strcmp(yin->child->name, "base")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 926 | LOGVAL(LYE_INSTMT, LOGLINE(yin->child), yin->child->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 927 | goto error; |
| 928 | } |
| 929 | } |
| 930 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 931 | if (!yin->child) { |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 932 | if (type->der->type.der) { |
| 933 | /* this is just a derived type with no base specified/required */ |
| 934 | break; |
| 935 | } |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 936 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "base", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 937 | goto error; |
| 938 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 939 | if (yin->child->next) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 940 | 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] | 941 | goto error; |
| 942 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 943 | GETVAL(value, yin->child, "name"); |
| 944 | add_unres_str(module, unres, type, UNRES_TYPE_IDENTREF, value, LOGLINE(yin->child)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 945 | break; |
| 946 | |
| 947 | case LY_TYPE_INST: |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 948 | /* RFC 6020 9.13.2 - require-instance */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 949 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 950 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 951 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 952 | continue; |
| 953 | } |
| 954 | |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 955 | if (!strcmp(node->name, "require-instance")) { |
| 956 | if (type->info.inst.req) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 957 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 958 | goto error; |
| 959 | } |
| 960 | GETVAL(value, node, "value"); |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 961 | if (!strcmp(value, "true")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 962 | type->info.inst.req = 1; |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 963 | } else if (!strcmp(value, "false")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 964 | type->info.inst.req = -1; |
| 965 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 966 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 967 | goto error; |
| 968 | } |
| 969 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 970 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 971 | goto error; |
| 972 | } |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 973 | } |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 974 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 975 | break; |
| 976 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 977 | case LY_TYPE_BINARY: |
| 978 | /* 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] | 979 | case LY_TYPE_INT8: |
| 980 | case LY_TYPE_INT16: |
| 981 | case LY_TYPE_INT32: |
| 982 | case LY_TYPE_INT64: |
| 983 | case LY_TYPE_UINT8: |
| 984 | case LY_TYPE_UINT16: |
| 985 | case LY_TYPE_UINT32: |
| 986 | case LY_TYPE_UINT64: |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 987 | /* RFC 6020 9.2.4 - range */ |
| 988 | |
| 989 | /* length and range are actually the same restriction, so process |
| 990 | * them by this common code, we just need to differ the name and |
| 991 | * structure where the information will be stored |
| 992 | */ |
| 993 | if (type->base == LY_TYPE_BINARY) { |
| 994 | restr = &type->info.binary.length; |
| 995 | name = "length"; |
| 996 | } else { |
| 997 | restr = &type->info.num.range; |
| 998 | name = "range"; |
| 999 | } |
| 1000 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1001 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1002 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 1003 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1004 | continue; |
| 1005 | } |
| 1006 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1007 | if (!strcmp(node->name, name)) { |
| 1008 | if (*restr) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1009 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1010 | goto error; |
| 1011 | } |
| 1012 | |
| 1013 | GETVAL(value, node, "value"); |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 1014 | if (check_length_range(value, type, LOGLINE(node))) { |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1015 | goto error; |
| 1016 | } |
| 1017 | *restr = calloc(1, sizeof **restr); |
| 1018 | (*restr)->expr = lydict_insert(module->ctx, value, 0); |
| 1019 | |
| 1020 | /* get possible substatements */ |
| 1021 | if (read_restr_substmt(module->ctx, *restr, node)) { |
| 1022 | goto error; |
| 1023 | } |
| 1024 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1025 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1026 | goto error; |
| 1027 | } |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 1028 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1029 | break; |
| 1030 | |
| 1031 | case LY_TYPE_LEAFREF: |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1032 | /* RFC 6020 9.9.2 - path */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1033 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1034 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 1035 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1036 | continue; |
| 1037 | } |
| 1038 | |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1039 | if (!strcmp(node->name, "path")) { |
| 1040 | if (type->info.lref.path) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1041 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1042 | goto error; |
| 1043 | } |
| 1044 | |
| 1045 | GETVAL(value, node, "value"); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1046 | type->info.lref.path = lydict_insert(module->ctx, value, 0); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1047 | add_unres_mnode(module, unres, type, UNRES_TYPE_LEAFREF, parent, LOGLINE(yin)); |
| 1048 | |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1049 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1050 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1051 | goto error; |
| 1052 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | if (!type->info.lref.path) { |
| 1056 | if (type->der->type.der) { |
| 1057 | /* this is just a derived type with no path specified/required */ |
| 1058 | break; |
| 1059 | } |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1060 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "path", "type"); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1061 | goto error; |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 1062 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1063 | break; |
| 1064 | |
| 1065 | case LY_TYPE_STRING: |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1066 | /* RFC 6020 9.4.4 - length */ |
| 1067 | /* RFC 6020 9.4.6 - pattern */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1068 | i = 0; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1069 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1070 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 1071 | /* garbage */ |
| 1072 | lyxml_free_elem(module->ctx, node); |
| 1073 | continue; |
| 1074 | } |
| 1075 | |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1076 | if (!strcmp(node->name, "length")) { |
| 1077 | if (type->info.str.length) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1078 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1079 | goto error; |
| 1080 | } |
| 1081 | |
| 1082 | GETVAL(value, node, "value"); |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 1083 | if (check_length_range(value, type, LOGLINE(node))) { |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1084 | goto error; |
| 1085 | } |
| 1086 | type->info.str.length = calloc(1, sizeof *type->info.str.length); |
| 1087 | type->info.str.length->expr = lydict_insert(module->ctx, value, 0); |
| 1088 | |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1089 | /* get possible sub-statements */ |
| 1090 | if (read_restr_substmt(module->ctx, type->info.str.length, node)) { |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1091 | goto error; |
| 1092 | } |
Radek Krejci | 82d971d | 2015-06-19 14:20:50 +0200 | [diff] [blame] | 1093 | lyxml_free_elem(module->ctx, node); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1094 | } else if (!strcmp(node->name, "pattern")) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1095 | i++; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1096 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1097 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 1098 | goto error; |
| 1099 | } |
| 1100 | } |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1101 | /* store patterns in array */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1102 | if (i) { |
| 1103 | type->info.str.patterns = calloc(i, sizeof *type->info.str.patterns); |
| 1104 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1105 | GETVAL(value, yin->child, "value"); |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1106 | |
| 1107 | /* check that the regex is valid */ |
| 1108 | if ((ret = regcomp(&preq, value, REG_EXTENDED | REG_NOSUB)) != 0) { |
| 1109 | regerror(ret, &preq, regex_err, REGEX_ERR_LEN); |
| 1110 | regfree(&preq); |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1111 | LOGVAL(LYE_INREGEX, LOGLINE(node), value, regex_err); |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 1112 | free(type->info.str.patterns); |
| 1113 | goto error; |
| 1114 | } |
| 1115 | regfree(&preq); |
| 1116 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1117 | 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] | 1118 | |
| 1119 | /* get possible sub-statements */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1120 | 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] | 1121 | free(type->info.str.patterns); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1122 | goto error; |
| 1123 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1124 | type->info.str.pat_count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 1125 | } |
| 1126 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1127 | break; |
| 1128 | |
| 1129 | case LY_TYPE_UNION: |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1130 | /* RFC 6020 7.4 - type */ |
| 1131 | /* count number of types in union */ |
| 1132 | i = 0; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1133 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 1134 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 1135 | /* garbage */ |
| 1136 | lyxml_free_elem(module->ctx, node); |
| 1137 | continue; |
| 1138 | } |
| 1139 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1140 | if (!strcmp(node->name, "type")) { |
| 1141 | i++; |
| 1142 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1143 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1144 | goto error; |
| 1145 | } |
| 1146 | } |
| 1147 | |
| 1148 | if (!i) { |
| 1149 | if (type->der->type.der) { |
| 1150 | /* this is just a derived type with no base specified/required */ |
| 1151 | break; |
| 1152 | } |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1153 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", "(union) type"); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1154 | goto error; |
| 1155 | } |
| 1156 | |
| 1157 | /* allocate array for union's types ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1158 | type->info.uni.types = calloc(i, sizeof *type->info.uni.types); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1159 | /* ... and fill the structures */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1160 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1161 | 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] | 1162 | goto error; |
| 1163 | } |
| 1164 | type->info.uni.count++; |
| 1165 | |
| 1166 | /* union's type cannot be empty or leafref */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1167 | 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^] | 1168 | LOGVAL(LYE_INARG, LOGLINE(node), "empty", node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1169 | goto error; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1170 | } 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^] | 1171 | LOGVAL(LYE_INARG, LOGLINE(node), "leafref", node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1172 | goto error; |
| 1173 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1174 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1175 | break; |
| 1176 | |
| 1177 | default: |
Radek Krejci | 6e328cd | 2015-06-26 16:24:11 +0200 | [diff] [blame] | 1178 | /* no sub-statement allowed in: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1179 | * LY_TYPE_BOOL, LY_TYPE_EMPTY |
| 1180 | */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1181 | LY_TREE_FOR(yin->child, node) { |
| 1182 | if (node->ns && !strcmp(node->ns->value, LY_NSYIN)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1183 | LOGVAL(LYE_INSTMT, LOGLINE(yin->child), yin->child->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1184 | goto error; |
| 1185 | } |
Radek Krejci | 6e328cd | 2015-06-26 16:24:11 +0200 | [diff] [blame] | 1186 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1187 | break; |
| 1188 | } |
| 1189 | |
| 1190 | return EXIT_SUCCESS; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 1191 | |
| 1192 | error: |
| 1193 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1194 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1195 | } |
| 1196 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1197 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1198 | fill_yin_typedef(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_tpdf *tpdf, struct unres_item *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1199 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1200 | const char *value; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1201 | struct lyxml_elem *node; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1202 | int has_type = 0, dflt_line; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1203 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1204 | GETVAL(value, yin, "name"); |
| 1205 | if (check_identifier(value, LY_IDENT_TYPE, LOGLINE(yin), module, parent)) { |
| 1206 | goto error; |
| 1207 | } |
| 1208 | tpdf->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1209 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1210 | /* generic part - status, description, reference */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1211 | 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] | 1212 | goto error; |
| 1213 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1214 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1215 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1216 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 1217 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1218 | continue; |
| 1219 | } |
| 1220 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1221 | if (!strcmp(node->name, "type")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1222 | if (tpdf->type.der || has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1223 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1224 | goto error; |
| 1225 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1226 | if (fill_yin_type(module, parent, node, &tpdf->type, unres)) { |
| 1227 | goto error; |
| 1228 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1229 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1230 | } else if (!strcmp(node->name, "default")) { |
| 1231 | if (tpdf->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1232 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1233 | goto error; |
| 1234 | } |
| 1235 | GETVAL(value, node, "value"); |
| 1236 | tpdf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1237 | dflt_line = LOGLINE(node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1238 | } else if (!strcmp(node->name, "units")) { |
| 1239 | if (tpdf->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1240 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1241 | goto error; |
| 1242 | } |
| 1243 | GETVAL(value, node, "name"); |
| 1244 | tpdf->units = lydict_insert(module->ctx, value, strlen(value)); |
| 1245 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1246 | LOGVAL(LYE_INSTMT, LOGLINE(node), value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1247 | goto error; |
| 1248 | } |
| 1249 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 1250 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1251 | /* check mandatory value */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1252 | if (!has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1253 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1254 | goto error; |
| 1255 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1256 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1257 | /* check default value */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1258 | if (tpdf->dflt) { |
| 1259 | add_unres_str(module, unres, &tpdf->type, UNRES_TYPE_DFLT, tpdf->dflt, dflt_line); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1260 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1261 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1262 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 1263 | |
| 1264 | error: |
| 1265 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1266 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1267 | } |
| 1268 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1269 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1270 | fill_yin_feature(struct lys_module *module, struct lyxml_elem *yin, struct lys_feature *f, struct unres_item *unres) |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1271 | { |
| 1272 | const char *value; |
| 1273 | struct lyxml_elem *child, *next; |
| 1274 | int c = 0; |
| 1275 | |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1276 | GETVAL(value, yin, "name"); |
| 1277 | if (check_identifier(value, LY_IDENT_FEATURE, LOGLINE(yin), module, NULL)) { |
| 1278 | goto error; |
| 1279 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1280 | f->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 1281 | f->module = module; |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 1282 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1283 | if (read_yin_common(module, NULL, (struct lys_node *)f, yin, 0)) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1284 | goto error; |
| 1285 | } |
| 1286 | |
| 1287 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1288 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1289 | /* garbage */ |
| 1290 | lyxml_free_elem(module->ctx, child); |
| 1291 | continue; |
| 1292 | } |
| 1293 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1294 | if (!strcmp(child->name, "if-feature")) { |
| 1295 | c++; |
| 1296 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1297 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1298 | goto error; |
| 1299 | } |
| 1300 | } |
| 1301 | |
| 1302 | if (c) { |
| 1303 | f->features = calloc(c, sizeof *f->features); |
| 1304 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1305 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1306 | GETVAL(value, child, "name"); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1307 | add_unres_str(module, unres, &f->features[f->features_size++], UNRES_IFFEAT, value, LOGLINE(child)); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1308 | } |
| 1309 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1310 | return EXIT_SUCCESS; |
| 1311 | |
| 1312 | error: |
| 1313 | |
| 1314 | return EXIT_FAILURE; |
| 1315 | } |
| 1316 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1317 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1318 | 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] | 1319 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1320 | const char *value; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1321 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1322 | GETVAL(value, yin, "condition"); |
Radek Krejci | 0bd5db4 | 2015-06-19 13:30:07 +0200 | [diff] [blame] | 1323 | must->expr = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1324 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 1325 | return read_restr_substmt(module->ctx, must, yin); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1326 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 1327 | error: /* GETVAL requires this label */ |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1328 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1329 | return EXIT_FAILURE; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1330 | } |
| 1331 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1332 | /* |
| 1333 | * type: 0 - min, 1 - max |
| 1334 | */ |
| 1335 | static int |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1336 | 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] | 1337 | { |
| 1338 | const char *value; |
| 1339 | char *endptr; |
| 1340 | unsigned long val; |
| 1341 | uint32_t *ui32val; |
| 1342 | |
| 1343 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1344 | if (target->nodetype == LYS_LEAFLIST) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1345 | if (type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1346 | ui32val = &((struct lys_node_leaflist *)target)->max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1347 | } else { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1348 | ui32val = &((struct lys_node_leaflist *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1349 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1350 | } else if (target->nodetype == LYS_LIST) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1351 | if (type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1352 | ui32val = &((struct lys_node_list *)target)->max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1353 | } else { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1354 | ui32val = &((struct lys_node_list *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1355 | } |
| 1356 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1357 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
| 1358 | 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] | 1359 | goto error; |
| 1360 | } |
| 1361 | |
| 1362 | GETVAL(value, node, "value"); |
| 1363 | while (isspace(value[0])) { |
| 1364 | value++; |
| 1365 | } |
| 1366 | |
| 1367 | /* convert it to uint32_t */ |
| 1368 | errno = 0; |
| 1369 | endptr = NULL; |
| 1370 | val = strtoul(value, &endptr, 10); |
| 1371 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1372 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1373 | goto error; |
| 1374 | } |
| 1375 | if (type) { |
| 1376 | d->max = (uint32_t)val; |
| 1377 | } else { |
| 1378 | d->min = (uint32_t)val; |
| 1379 | } |
| 1380 | |
| 1381 | if (d->mod == LY_DEVIATE_ADD) { |
| 1382 | /* check that there is no current value */ |
| 1383 | if (*ui32val) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1384 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
| 1385 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1386 | goto error; |
| 1387 | } |
| 1388 | } |
| 1389 | |
| 1390 | if (d->mod == LY_DEVIATE_DEL) { |
| 1391 | /* check values */ |
| 1392 | if ((uint32_t)val != *ui32val) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1393 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
| 1394 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1395 | goto error; |
| 1396 | } |
| 1397 | /* remove current min-elements value of the target */ |
| 1398 | *ui32val = 0; |
| 1399 | } else { /* add (already checked) and replace */ |
| 1400 | /* set new value specified in deviation */ |
| 1401 | *ui32val = (uint32_t)val; |
| 1402 | } |
| 1403 | |
| 1404 | return EXIT_SUCCESS; |
| 1405 | |
| 1406 | error: |
| 1407 | |
| 1408 | return EXIT_FAILURE; |
| 1409 | } |
| 1410 | |
| 1411 | static int |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1412 | 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] | 1413 | { |
| 1414 | const char *value, **stritem; |
| 1415 | struct lyxml_elem *next, *child, *develem; |
| 1416 | int c_dev = 0, c_must, c_uniq; |
| 1417 | int f_min = 0; /* flags */ |
| 1418 | int i, j; |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1419 | struct lys_deviate *d = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1420 | struct lys_node *mnode = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1421 | struct lys_node_choice *choice = NULL; |
| 1422 | struct lys_node_leaf *leaf = NULL; |
| 1423 | struct lys_node_list *list = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1424 | struct lys_type *t = NULL; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1425 | uint8_t *trg_must_size = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1426 | struct lys_restr **trg_must = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1427 | |
| 1428 | GETVAL(value, yin, "target-node"); |
| 1429 | dev->target_name = lydict_insert(module->ctx, value, 0); |
| 1430 | |
| 1431 | /* resolve target node */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1432 | dev->target = resolve_schema_nodeid(dev->target_name, NULL, module, LYS_AUGMENT); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1433 | if (!dev->target) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1434 | LOGVAL(LYE_INARG, LOGLINE(yin), dev->target_name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1435 | goto error; |
| 1436 | } |
| 1437 | if (dev->target->module == module) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1438 | LOGVAL(LYE_SPEC, LOGLINE(yin), "Deviating own module is not allowed."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1439 | goto error; |
| 1440 | } |
| 1441 | /* mark the target module as deviated */ |
| 1442 | dev->target->module->deviated = 1; |
| 1443 | |
| 1444 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1445 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1446 | /* garbage */ |
| 1447 | lyxml_free_elem(module->ctx, child); |
| 1448 | continue; |
| 1449 | } |
| 1450 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1451 | if (!strcmp(child->name, "description")) { |
| 1452 | if (dev->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1453 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1454 | goto error; |
| 1455 | } |
| 1456 | dev->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 1457 | if (!dev->dsc) { |
| 1458 | goto error; |
| 1459 | } |
| 1460 | } else if (!strcmp(child->name, "reference")) { |
| 1461 | if (dev->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1462 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1463 | goto error; |
| 1464 | } |
| 1465 | dev->ref = read_yin_subnode(module->ctx, child, "text"); |
| 1466 | if (!dev->ref) { |
| 1467 | goto error; |
| 1468 | } |
| 1469 | } else if (!strcmp(child->name, "deviate")) { |
| 1470 | c_dev++; |
| 1471 | |
| 1472 | /* skip lyxml_free_elem() at the end of the loop, node will be |
| 1473 | * further processed later |
| 1474 | */ |
| 1475 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 1476 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1477 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1478 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1479 | goto error; |
| 1480 | } |
| 1481 | |
| 1482 | lyxml_free_elem(module->ctx, child); |
| 1483 | } |
| 1484 | |
| 1485 | if (c_dev) { |
| 1486 | dev->deviate = calloc(c_dev, sizeof *dev->deviate); |
| 1487 | } |
| 1488 | |
| 1489 | LY_TREE_FOR(yin->child, develem) { |
| 1490 | /* init */ |
| 1491 | f_min = 0; |
| 1492 | c_must = 0; |
| 1493 | c_uniq = 0; |
| 1494 | |
| 1495 | /* get deviation type */ |
| 1496 | GETVAL(value, develem, "value"); |
| 1497 | if (!strcmp(value, "not-supported")) { |
| 1498 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_NO; |
| 1499 | /* no property expected in this case */ |
| 1500 | if (develem->child) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1501 | LOGVAL(LYE_INSTMT, LOGLINE(develem->child), develem->child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1502 | goto error; |
| 1503 | } |
| 1504 | |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1505 | /* and neither any other deviate statement is expected, |
| 1506 | * not-supported deviation must be the only deviation of the target |
| 1507 | */ |
| 1508 | if (dev->deviate_size || develem->next) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1509 | LOGVAL(LYE_INARG, LOGLINE(develem), value, develem->name); |
| 1510 | 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] | 1511 | goto error; |
| 1512 | } |
| 1513 | |
| 1514 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1515 | /* remove target node */ |
| 1516 | ly_mnode_free(dev->target); |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1517 | dev->target = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1518 | |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1519 | dev->deviate_size = 1; |
| 1520 | return EXIT_SUCCESS; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1521 | } else if (!strcmp(value, "add")) { |
| 1522 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_ADD; |
| 1523 | } else if (!strcmp(value, "replace")) { |
| 1524 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_RPL; |
| 1525 | } else if (!strcmp(value, "delete")) { |
| 1526 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_DEL; |
| 1527 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1528 | LOGVAL(LYE_INARG, LOGLINE(develem), value, develem->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1529 | goto error; |
| 1530 | } |
| 1531 | d = &dev->deviate[dev->deviate_size]; |
| 1532 | |
| 1533 | /* process deviation properties */ |
| 1534 | LY_TREE_FOR_SAFE(develem->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1535 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1536 | /* garbage */ |
| 1537 | lyxml_free_elem(module->ctx, child); |
| 1538 | continue; |
| 1539 | } |
| 1540 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1541 | if (!strcmp(child->name, "config")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1542 | if (d->flags & LYS_CONFIG_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1543 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1544 | goto error; |
| 1545 | } |
| 1546 | |
| 1547 | /* for we deviate from RFC 6020 and allow config property even it is/is not |
| 1548 | * specified in the target explicitly since config property inherits. So we expect |
| 1549 | * that config is specified in every node. But for delete, we check that the value |
| 1550 | * is the same as here in deviation |
| 1551 | */ |
| 1552 | GETVAL(value, child, "value"); |
| 1553 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1554 | d->flags |= LYS_CONFIG_R; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1555 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1556 | d->flags |= LYS_CONFIG_W; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1557 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1558 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1559 | goto error; |
| 1560 | } |
| 1561 | |
| 1562 | if (d->mod == LY_DEVIATE_DEL) { |
| 1563 | /* check values */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1564 | if ((d->flags & LYS_CONFIG_MASK) != (dev->target->flags & LYS_CONFIG_MASK)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1565 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1566 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1567 | goto error; |
| 1568 | } |
| 1569 | /* remove current config value of the target ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1570 | dev->target->flags &= ~LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1571 | |
| 1572 | /* ... and inherit config value from the target's parent */ |
| 1573 | if (dev->target->parent) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1574 | dev->target->flags |= dev->target->parent->flags & LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1575 | } else { |
| 1576 | /* default config is true */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1577 | dev->target->flags |= LYS_CONFIG_W; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1578 | } |
| 1579 | } else { /* add and replace are the same in this case */ |
| 1580 | /* remove current config value of the target ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1581 | dev->target->flags &= ~LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1582 | |
| 1583 | /* ... and replace it with the value specified in deviation */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1584 | dev->target->flags |= d->flags & LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1585 | } |
| 1586 | } else if (!strcmp(child->name, "default")) { |
| 1587 | if (d->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1588 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1589 | goto error; |
| 1590 | } |
| 1591 | GETVAL(value, child, "value"); |
| 1592 | d->dflt = lydict_insert(module->ctx, value, 0); |
| 1593 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1594 | if (dev->target->nodetype == LYS_CHOICE) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1595 | choice = (struct lys_node_choice *)dev->target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1596 | |
| 1597 | if (d->mod == LY_DEVIATE_ADD) { |
| 1598 | /* check that there is no current value */ |
| 1599 | if (choice->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1600 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1601 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1602 | goto error; |
| 1603 | } |
| 1604 | } |
| 1605 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1606 | mnode = resolve_schema_nodeid(d->dflt, (struct lys_node *)choice, choice->module, LYS_CHOICE); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1607 | if (d->mod == LY_DEVIATE_DEL) { |
| 1608 | if (!choice->dflt || choice->dflt != mnode) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1609 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1610 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1611 | goto error; |
| 1612 | } |
| 1613 | } else { /* add (already checked) and replace */ |
| 1614 | choice->dflt = mnode; |
| 1615 | if (!choice->dflt) { |
| 1616 | /* default branch not found */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1617 | LOGVAL(LYE_INARG, LOGLINE(yin), value, "default"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1618 | goto error; |
| 1619 | } |
| 1620 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1621 | } else if (dev->target->nodetype == LYS_LEAF) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1622 | leaf = (struct lys_node_leaf *)dev->target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1623 | |
| 1624 | if (d->mod == LY_DEVIATE_ADD) { |
| 1625 | /* check that there is no current value */ |
| 1626 | if (leaf->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1627 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1628 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1629 | goto error; |
| 1630 | } |
| 1631 | } |
| 1632 | |
| 1633 | if (d->mod == LY_DEVIATE_DEL) { |
| 1634 | if (!leaf->dflt || leaf->dflt != d->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1635 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1636 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1637 | goto error; |
| 1638 | } |
| 1639 | /* remove value */ |
| 1640 | lydict_remove(leaf->module->ctx, leaf->dflt); |
| 1641 | leaf->dflt = NULL; |
| 1642 | } else { /* add (already checked) and replace */ |
| 1643 | /* remove value */ |
| 1644 | lydict_remove(leaf->module->ctx, leaf->dflt); |
| 1645 | |
| 1646 | /* set new value */ |
| 1647 | leaf->dflt = lydict_insert(leaf->module->ctx, d->dflt, 0); |
| 1648 | } |
| 1649 | } else { |
| 1650 | /* invalid target for default value */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1651 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1652 | 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] | 1653 | goto error; |
| 1654 | } |
| 1655 | } else if (!strcmp(child->name, "mandatory")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1656 | if (d->flags & LYS_MAND_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1657 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1658 | goto error; |
| 1659 | } |
| 1660 | |
| 1661 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1662 | if (!(dev->target->nodetype &= (LYS_LEAF | LYS_CHOICE | LYS_ANYXML))) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1663 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1664 | 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] | 1665 | goto error; |
| 1666 | } |
| 1667 | |
| 1668 | GETVAL(value, child, "value"); |
| 1669 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1670 | d->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1671 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1672 | d->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1673 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1674 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1675 | goto error; |
| 1676 | } |
| 1677 | |
| 1678 | if (d->mod == LY_DEVIATE_ADD) { |
| 1679 | /* check that there is no current value */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1680 | if (dev->target->flags & LYS_MAND_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1681 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1682 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1683 | goto error; |
| 1684 | } |
| 1685 | } |
| 1686 | |
| 1687 | if (d->mod == LY_DEVIATE_DEL) { |
| 1688 | /* check values */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1689 | if ((d->flags & LYS_MAND_MASK) != (dev->target->flags & LYS_MAND_MASK)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1690 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1691 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1692 | goto error; |
| 1693 | } |
| 1694 | /* remove current mandatory value of the target */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1695 | dev->target->flags &= ~LYS_MAND_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1696 | } else { /* add (already checked) and replace */ |
| 1697 | /* remove current mandatory value of the target ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1698 | dev->target->flags &= ~LYS_MAND_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1699 | |
| 1700 | /* ... and replace it with the value specified in deviation */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1701 | dev->target->flags |= d->flags & LYS_MAND_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1702 | } |
| 1703 | } else if (!strcmp(child->name, "min-elements")) { |
| 1704 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1705 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1706 | goto error; |
| 1707 | } |
| 1708 | f_min = 1; |
| 1709 | |
| 1710 | if (deviate_minmax(dev->target, child, d, 0)) { |
| 1711 | goto error; |
| 1712 | } |
| 1713 | } else if (!strcmp(child->name, "max-elements")) { |
| 1714 | if (d->max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1715 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1716 | goto error; |
| 1717 | } |
| 1718 | |
| 1719 | if (deviate_minmax(dev->target, child, d, 1)) { |
| 1720 | goto error; |
| 1721 | } |
| 1722 | } else if (!strcmp(child->name, "must")) { |
| 1723 | c_must++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1724 | /* skip lyxml_free_elem() at the end of the loop, this node will be processed later */ |
| 1725 | continue; |
| 1726 | } else if (!strcmp(child->name, "type")) { |
| 1727 | if (d->type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1728 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1729 | goto error; |
| 1730 | } |
| 1731 | |
| 1732 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1733 | if (dev->target->nodetype == LYS_LEAF) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1734 | t = &((struct lys_node_leaf *)dev->target)->type; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1735 | } else if (dev->target->nodetype == LYS_LEAFLIST) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1736 | t = &((struct lys_node_leaflist *)dev->target)->type; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1737 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1738 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1739 | 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] | 1740 | goto error; |
| 1741 | } |
| 1742 | |
| 1743 | if (d->mod == LY_DEVIATE_ADD) { |
| 1744 | /* not allowed, type is always present at the target */ |
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, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1747 | goto error; |
| 1748 | } else if (d->mod == LY_DEVIATE_DEL) { |
| 1749 | /* not allowed, type cannot be deleted from the target */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1750 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1751 | LOGVAL(LYE_SPEC, 0, "Deleteing type from the target is not allowed."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1752 | goto error; |
| 1753 | } |
| 1754 | |
| 1755 | /* replace */ |
| 1756 | /* remove current units value of the target ... */ |
| 1757 | ly_type_free(dev->target->module->ctx, t); |
| 1758 | |
| 1759 | /* ... and replace it with the value specified in deviation */ |
Radek Krejci | 8de7b0f | 2015-07-02 11:43:42 +0200 | [diff] [blame] | 1760 | if (fill_yin_type(module, dev->target, child, t, NULL)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1761 | goto error; |
| 1762 | } |
| 1763 | d->type = t; |
| 1764 | } else if (!strcmp(child->name, "unique")) { |
| 1765 | c_uniq++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1766 | /* skip lyxml_free_elem() at the end of the loop, this node will be processed later */ |
| 1767 | continue; |
| 1768 | } else if (!strcmp(child->name, "units")) { |
| 1769 | if (d->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1770 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1771 | goto error; |
| 1772 | } |
| 1773 | |
| 1774 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1775 | if (dev->target->nodetype == LYS_LEAFLIST) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1776 | stritem = &((struct lys_node_leaflist *)dev->target)->units; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1777 | } else if (dev->target->nodetype == LYS_LEAF) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1778 | stritem = &((struct lys_node_leaf *)dev->target)->units; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1779 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1780 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1781 | 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] | 1782 | goto error; |
| 1783 | } |
| 1784 | |
| 1785 | /* get units value */ |
| 1786 | GETVAL(value, child, "name"); |
| 1787 | d->units = lydict_insert(module->ctx, value, 0); |
| 1788 | |
| 1789 | /* apply to target */ |
| 1790 | if (d->mod == LY_DEVIATE_ADD) { |
| 1791 | /* check that there is no current value */ |
| 1792 | if (*stritem) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1793 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1794 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1795 | goto error; |
| 1796 | } |
| 1797 | } |
| 1798 | |
| 1799 | if (d->mod == LY_DEVIATE_DEL) { |
| 1800 | /* check values */ |
| 1801 | if (*stritem != d->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1802 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1803 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1804 | goto error; |
| 1805 | } |
| 1806 | /* remove current units value of the target */ |
| 1807 | lydict_remove(dev->target->module->ctx, *stritem); |
| 1808 | } else { /* add (already checked) and replace */ |
| 1809 | /* remove current units value of the target ... */ |
| 1810 | lydict_remove(dev->target->module->ctx, *stritem); |
| 1811 | |
| 1812 | /* ... and replace it with the value specified in deviation */ |
| 1813 | *stritem = lydict_insert(module->ctx, value, 0); |
| 1814 | } |
| 1815 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1816 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1817 | goto error; |
| 1818 | } |
| 1819 | |
| 1820 | lyxml_free_elem(module->ctx, child); |
| 1821 | } |
| 1822 | |
| 1823 | if (c_must) { |
| 1824 | /* check target node type */ |
| 1825 | switch (dev->target->nodetype) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1826 | case LYS_LEAF: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1827 | trg_must = &((struct lys_node_leaf *)dev->target)->must; |
| 1828 | trg_must_size = &((struct lys_node_leaf *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1829 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1830 | case LYS_CONTAINER: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1831 | trg_must = &((struct lys_node_container *)dev->target)->must; |
| 1832 | trg_must_size = &((struct lys_node_container *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1833 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1834 | case LYS_LEAFLIST: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1835 | trg_must = &((struct lys_node_leaflist *)dev->target)->must; |
| 1836 | trg_must_size = &((struct lys_node_leaflist *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1837 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1838 | case LYS_LIST: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1839 | trg_must = &((struct lys_node_list *)dev->target)->must; |
| 1840 | trg_must_size = &((struct lys_node_list *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1841 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1842 | case LYS_ANYXML: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1843 | trg_must = &((struct lys_node_anyxml *)dev->target)->must; |
| 1844 | trg_must_size = &((struct lys_node_anyxml *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1845 | break; |
| 1846 | default: |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1847 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1848 | 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] | 1849 | goto error; |
| 1850 | } |
| 1851 | |
| 1852 | if (d->mod == LY_DEVIATE_RPL) { |
| 1853 | /* remove target's musts and allocate new array for it */ |
| 1854 | if (!*trg_must) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1855 | LOGVAL(LYE_INARG, LOGLINE(develem), "replace", "deviate"); |
| 1856 | 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] | 1857 | goto error; |
| 1858 | } |
| 1859 | |
| 1860 | for (i = 0; i < list->must_size; i++) { |
| 1861 | ly_restr_free(dev->target->module->ctx, &(*trg_must[i])); |
| 1862 | } |
| 1863 | free(*trg_must); |
| 1864 | *trg_must = d->must = calloc(c_must, sizeof *d->must); |
| 1865 | d->must_size = c_must; |
| 1866 | *trg_must_size = 0; |
| 1867 | } else if (d->mod == LY_DEVIATE_ADD) { |
| 1868 | /* reallocate the must array of the target */ |
| 1869 | d->must = realloc(*trg_must, (c_must + *trg_must_size) * sizeof *d->must); |
| 1870 | *trg_must = d->must; |
| 1871 | d->must = &(*trg_must[*trg_must_size]); |
| 1872 | d->must_size = c_must; |
| 1873 | } else { /* LY_DEVIATE_DEL */ |
| 1874 | d->must = calloc(c_must, sizeof *d->must); |
| 1875 | } |
| 1876 | } |
| 1877 | if (c_uniq) { |
| 1878 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1879 | if (dev->target->nodetype != LYS_LIST) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1880 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1881 | 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] | 1882 | goto error; |
| 1883 | } |
| 1884 | |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1885 | list = (struct lys_node_list *)dev->target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1886 | if (d->mod == LY_DEVIATE_RPL) { |
| 1887 | /* remove target's unique and allocate new array for it */ |
| 1888 | if (!list->unique) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1889 | LOGVAL(LYE_INARG, LOGLINE(develem), "replace", "deviate"); |
| 1890 | 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] | 1891 | goto error; |
| 1892 | } |
| 1893 | |
| 1894 | for (i = 0; i < list->unique_size; i++) { |
| 1895 | free(list->unique[i].leafs); |
| 1896 | } |
| 1897 | free(list->unique); |
| 1898 | list->unique = d->unique = calloc(c_uniq, sizeof *d->unique); |
| 1899 | d->unique_size = c_uniq; |
| 1900 | list->unique_size = 0; |
| 1901 | } else if (d->mod == LY_DEVIATE_ADD) { |
| 1902 | /* reallocate the unique array of the target */ |
| 1903 | d->unique = realloc(list->unique, (c_uniq + list->unique_size) * sizeof *d->unique); |
| 1904 | list->unique = d->unique; |
| 1905 | d->unique = &list->unique[list->unique_size]; |
| 1906 | d->unique_size = c_uniq; |
| 1907 | } else { /* LY_DEVIATE_DEL */ |
| 1908 | d->unique = calloc(c_uniq, sizeof *d->unique); |
| 1909 | } |
| 1910 | } |
| 1911 | |
| 1912 | /* process deviation properties with 0..n cardinality */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1913 | LY_TREE_FOR(develem->child, child) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1914 | if (!strcmp(child->name, "must")) { |
| 1915 | if (d->mod == LY_DEVIATE_DEL) { |
| 1916 | if (fill_yin_must(module, child, &d->must[d->must_size])) { |
| 1917 | goto error; |
| 1918 | } |
| 1919 | |
| 1920 | /* find must to delete, we are ok with just matching conditions */ |
| 1921 | for (i = 0; i < *trg_must_size; i++) { |
| 1922 | if (d->must[d->must_size].expr == (*trg_must)[i].expr) { |
| 1923 | /* we have a match, free the must structure ... */ |
| 1924 | ly_restr_free(dev->target->module->ctx, &(*trg_must[i])); |
| 1925 | /* ... and maintain the array */ |
| 1926 | (*trg_must_size)--; |
| 1927 | if (i != *trg_must_size) { |
| 1928 | (*trg_must)[i].expr = (*trg_must)[*trg_must_size].expr; |
| 1929 | (*trg_must)[i].dsc = (*trg_must)[*trg_must_size].dsc; |
| 1930 | (*trg_must)[i].ref = (*trg_must)[*trg_must_size].ref; |
| 1931 | (*trg_must)[i].eapptag = (*trg_must)[*trg_must_size].eapptag; |
| 1932 | (*trg_must)[i].emsg = (*trg_must)[*trg_must_size].emsg; |
| 1933 | } |
| 1934 | if (!(*trg_must_size)) { |
| 1935 | free(*trg_must); |
| 1936 | *trg_must = NULL; |
| 1937 | } else { |
| 1938 | (*trg_must)[*trg_must_size].expr = NULL; |
| 1939 | (*trg_must)[*trg_must_size].dsc = NULL; |
| 1940 | (*trg_must)[*trg_must_size].ref = NULL; |
| 1941 | (*trg_must)[*trg_must_size].eapptag = NULL; |
| 1942 | (*trg_must)[*trg_must_size].emsg = NULL; |
| 1943 | } |
| 1944 | |
| 1945 | i = -1; /* set match flag */ |
| 1946 | break; |
| 1947 | } |
| 1948 | } |
| 1949 | d->must_size++; |
| 1950 | if (i != -1) { |
| 1951 | /* no match found */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 1952 | LOGVAL(LYE_INARG, LOGLINE(child), d->must[d->must_size - 1].expr, child->name); |
| 1953 | 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] | 1954 | goto error; |
| 1955 | } |
| 1956 | } else { /* replace or add */ |
| 1957 | if (fill_yin_must(dev->target->module, child, &((*trg_must)[*trg_must_size]))) { |
| 1958 | goto error; |
| 1959 | } |
| 1960 | (*trg_must_size)++; |
| 1961 | } |
| 1962 | } else if (!strcmp(child->name, "unique")) { |
| 1963 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1964 | GETVAL(value, child, "tag"); |
| 1965 | 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] | 1966 | goto error; |
| 1967 | } |
| 1968 | |
| 1969 | /* find unique structures to delete */ |
| 1970 | for (i = 0; i < list->unique_size; i++) { |
| 1971 | if (list->unique[i].leafs_size != d->unique[d->unique_size].leafs_size) { |
| 1972 | continue; |
| 1973 | } |
| 1974 | |
| 1975 | for (j = 0; j < d->unique[d->unique_size].leafs_size; j++) { |
| 1976 | if (list->unique[i].leafs[j] != d->unique[d->unique_size].leafs[j]) { |
| 1977 | break; |
| 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | if (j == d->unique[d->unique_size].leafs_size) { |
| 1982 | /* we have a match, free the unique structure ... */ |
| 1983 | free(list->unique[i].leafs); |
| 1984 | /* ... and maintain the array */ |
| 1985 | list->unique_size--; |
| 1986 | if (i != list->unique_size) { |
| 1987 | list->unique[i].leafs_size = list->unique[list->unique_size].leafs_size; |
| 1988 | list->unique[i].leafs = list->unique[list->unique_size].leafs; |
| 1989 | } |
| 1990 | |
| 1991 | if (!list->unique_size) { |
| 1992 | free(list->unique); |
| 1993 | list->unique = NULL; |
| 1994 | } else { |
| 1995 | list->unique[list->unique_size].leafs_size = 0; |
| 1996 | list->unique[list->unique_size].leafs = NULL; |
| 1997 | } |
| 1998 | |
| 1999 | i = -1; /* set match flag */ |
| 2000 | break; |
| 2001 | } |
| 2002 | } |
| 2003 | |
| 2004 | d->unique_size++; |
| 2005 | if (i != -1) { |
| 2006 | /* no match found */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2007 | LOGVAL(LYE_INARG, LOGLINE(child), lyxml_get_attr(child, "tag", NULL), child->name); |
| 2008 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2009 | goto error; |
| 2010 | } |
| 2011 | } else { /* replace or add */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2012 | GETVAL(value, child, "tag"); |
| 2013 | 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] | 2014 | goto error; |
| 2015 | } |
| 2016 | list->unique_size++; |
| 2017 | } |
| 2018 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2019 | } |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 2020 | |
| 2021 | dev->deviate_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2022 | } |
| 2023 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2024 | return EXIT_SUCCESS; |
| 2025 | |
| 2026 | error: |
| 2027 | |
| 2028 | if (dev->deviate) { |
| 2029 | for (i = 0; i < dev->deviate_size; i++) { |
| 2030 | lydict_remove(module->ctx, dev->deviate[i].dflt); |
| 2031 | lydict_remove(module->ctx, dev->deviate[i].units); |
| 2032 | |
| 2033 | if (dev->deviate[i].mod == LY_DEVIATE_DEL) { |
| 2034 | for (j = 0; j < dev->deviate[i].must_size; j++) { |
| 2035 | ly_restr_free(module->ctx, &dev->deviate[i].must[j]); |
| 2036 | } |
| 2037 | free(dev->deviate[i].must); |
| 2038 | |
| 2039 | for (j = 0; j < dev->deviate[i].unique_size; j++) { |
| 2040 | free(dev->deviate[i].unique[j].leafs); |
| 2041 | } |
| 2042 | free(dev->deviate[i].unique); |
| 2043 | } |
| 2044 | } |
| 2045 | free(dev->deviate); |
| 2046 | } |
| 2047 | |
| 2048 | return EXIT_FAILURE; |
| 2049 | } |
| 2050 | |
| 2051 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2052 | fill_yin_augment(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_node_augment *aug, |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2053 | struct unres_item *unres) |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2054 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2055 | const char *value; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2056 | struct lyxml_elem *child, *next; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2057 | struct lys_node *mnode; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2058 | int c = 0; |
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 | GETVAL(value, yin, "target-node"); |
| 2061 | aug->target_name = lydict_insert(module->ctx, value, 0); |
| 2062 | aug->parent = parent; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2063 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2064 | if (read_yin_common(module, NULL, (struct lys_node *)aug, yin, OPT_NACMEXT)) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2065 | goto error; |
| 2066 | } |
| 2067 | |
| 2068 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2069 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2070 | /* garbage */ |
| 2071 | lyxml_free_elem(module->ctx, child); |
| 2072 | continue; |
| 2073 | } |
| 2074 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2075 | if (!strcmp(child->name, "if-feature")) { |
| 2076 | c++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2077 | continue; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2078 | } else if (!strcmp(child->name, "when")) { |
| 2079 | if (aug->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2080 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2081 | goto error; |
| 2082 | } |
| 2083 | |
| 2084 | aug->when = read_yin_when(module, child); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2085 | if (!aug->when) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2086 | lyxml_free_elem(module->ctx, child); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2087 | goto error; |
| 2088 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2089 | add_unres_mnode(module, unres, aug->when, UNRES_WHEN, (struct lys_node *)aug, LOGLINE(child)); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2090 | lyxml_free_elem(module->ctx, child); |
| 2091 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2092 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2093 | /* check allowed data sub-statements */ |
| 2094 | } else if (!strcmp(child->name, "container")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2095 | mnode = read_yin_container(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2096 | } else if (!strcmp(child->name, "leaf-list")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2097 | mnode = read_yin_leaflist(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2098 | } else if (!strcmp(child->name, "leaf")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2099 | mnode = read_yin_leaf(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2100 | } else if (!strcmp(child->name, "list")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2101 | mnode = read_yin_list(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2102 | } else if (!strcmp(child->name, "uses")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2103 | mnode = read_yin_uses(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2104 | } else if (!strcmp(child->name, "choice")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2105 | mnode = read_yin_case(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2106 | } else if (!strcmp(child->name, "case")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2107 | mnode = read_yin_case(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2108 | } else if (!strcmp(child->name, "anyxml")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2109 | mnode = read_yin_anyxml(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2110 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2111 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2112 | goto error; |
| 2113 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2114 | |
| 2115 | if (!mnode) { |
| 2116 | goto error; |
| 2117 | } |
| 2118 | |
| 2119 | /* check for mandatory nodes - if the target node is in another module |
| 2120 | * the added nodes cannot be mandatory |
| 2121 | */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2122 | if ((parent->nodetype != LYS_USES) && check_mandatory(mnode)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2123 | 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] | 2124 | goto error; |
| 2125 | } |
| 2126 | |
| 2127 | mnode = NULL; |
| 2128 | lyxml_free_elem(module->ctx, child); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2129 | } |
| 2130 | |
| 2131 | if (c) { |
| 2132 | aug->features = calloc(c, sizeof *aug->features); |
| 2133 | } |
| 2134 | |
| 2135 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 2136 | if (!strcmp(child->name, "if-feature")) { |
| 2137 | GETVAL(value, child, "name"); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2138 | add_unres_str(module, unres, &aug->features[aug->features_size++], UNRES_IFFEAT, value, LOGLINE(child)); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2139 | lyxml_free_elem(module->ctx, child); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2140 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2141 | } |
| 2142 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2143 | /* aug->child points to the parsed nodes, they must now be |
| 2144 | * connected to the tree and adjusted (if possible right now) */ |
| 2145 | add_unres_mnode(module, unres, aug, UNRES_AUGMENT, NULL, LOGLINE(yin)); |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2146 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2147 | return EXIT_SUCCESS; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2148 | |
| 2149 | error: |
| 2150 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2151 | return EXIT_FAILURE; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2152 | } |
| 2153 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2154 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2155 | fill_yin_refine(struct lys_module *module, struct lyxml_elem *yin, struct lys_refine *rfn, struct lys_node_uses *uses, |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2156 | struct unres_item *unres) |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2157 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2158 | struct lyxml_elem *sub, *next; |
| 2159 | const char *value; |
| 2160 | char *endptr; |
| 2161 | int f_mand = 0, f_min = 0, f_max = 0; |
| 2162 | int c_must = 0; |
| 2163 | int r; |
| 2164 | unsigned long int val; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2165 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2166 | 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] | 2167 | goto error; |
| 2168 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2169 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2170 | GETVAL(value, yin, "target-node"); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2171 | rfn->target_name = lydict_insert(module->ctx, value, 0); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2172 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2173 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2174 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2175 | /* garbage */ |
| 2176 | lyxml_free_elem(module->ctx, sub); |
| 2177 | continue; |
| 2178 | } |
| 2179 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2180 | /* limited applicability */ |
| 2181 | if (!strcmp(sub->name, "default")) { |
| 2182 | /* leaf or choice */ |
| 2183 | if (rfn->mod.dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2184 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2185 | goto error; |
| 2186 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2187 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2188 | /* check possibility of statements combination */ |
| 2189 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2190 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2191 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2192 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2193 | goto error; |
| 2194 | } |
| 2195 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2196 | rfn->target_type = LYS_LEAF | LYS_CHOICE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2197 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2198 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2199 | GETVAL(value, sub, "value"); |
| 2200 | rfn->mod.dflt = lydict_insert(module->ctx, value, strlen(value)); |
| 2201 | } else if (!strcmp(sub->name, "mandatory")) { |
| 2202 | /* leaf, choice or anyxml */ |
| 2203 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2204 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2205 | goto error; |
| 2206 | } |
| 2207 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2208 | * multiple mandatory statements with the "false" value |
| 2209 | */ |
| 2210 | f_mand = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2211 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2212 | /* check possibility of statements combination */ |
| 2213 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2214 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE | LYS_ANYXML); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2215 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2216 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2217 | goto error; |
| 2218 | } |
| 2219 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2220 | rfn->target_type = LYS_LEAF | LYS_CHOICE | LYS_ANYXML; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2221 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2222 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2223 | GETVAL(value, sub, "value"); |
| 2224 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2225 | rfn->flags |= LYS_MAND_TRUE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2226 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2227 | rfn->flags |= LYS_MAND_FALSE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2228 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2229 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2230 | goto error; |
| 2231 | } |
| 2232 | } else if (!strcmp(sub->name, "min-elements")) { |
| 2233 | /* list or leaf-list */ |
| 2234 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2235 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2236 | goto error; |
| 2237 | } |
| 2238 | f_min = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2239 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 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); |
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; |
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 | GETVAL(value, sub, "value"); |
| 2252 | while (isspace(value[0])) { |
| 2253 | value++; |
| 2254 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2255 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2256 | /* convert it to uint32_t */ |
| 2257 | errno = 0; |
| 2258 | endptr = NULL; |
| 2259 | val = strtoul(value, &endptr, 10); |
| 2260 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2261 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2262 | goto error; |
| 2263 | } |
| 2264 | rfn->mod.list.min = (uint32_t) val; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2265 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2266 | /* magic - bit 3 in flags means min set */ |
| 2267 | rfn->flags |= 0x04; |
| 2268 | } else if (!strcmp(sub->name, "max-elements")) { |
| 2269 | /* list or leaf-list */ |
| 2270 | if (f_max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2271 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2272 | goto error; |
| 2273 | } |
| 2274 | f_max = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2275 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2276 | /* check possibility of statements combination */ |
| 2277 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2278 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2279 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2280 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2281 | goto error; |
| 2282 | } |
| 2283 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2284 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2285 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2286 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2287 | GETVAL(value, sub, "value"); |
| 2288 | while (isspace(value[0])) { |
| 2289 | value++; |
| 2290 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2291 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2292 | /* convert it to uint32_t */ |
| 2293 | errno = 0; |
| 2294 | endptr = NULL; |
| 2295 | val = strtoul(value, &endptr, 10); |
| 2296 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2297 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2298 | goto error; |
| 2299 | } |
| 2300 | rfn->mod.list.max = (uint32_t) val; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2301 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2302 | /* magic - bit 4 in flags means min set */ |
| 2303 | rfn->flags |= 0x08; |
| 2304 | } else if (!strcmp(sub->name, "presence")) { |
| 2305 | /* container */ |
| 2306 | if (rfn->mod.presence) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2307 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2308 | goto error; |
| 2309 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2310 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2311 | /* check possibility of statements combination */ |
| 2312 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2313 | rfn->target_type &= LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2314 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2315 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2316 | goto error; |
| 2317 | } |
| 2318 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2319 | rfn->target_type = LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2320 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2321 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2322 | GETVAL(value, sub, "value"); |
| 2323 | rfn->mod.presence = lydict_insert(module->ctx, value, strlen(value)); |
| 2324 | } else if (!strcmp(sub->name, "must")) { |
| 2325 | /* leaf-list, list, container or anyxml */ |
| 2326 | /* check possibility of statements combination */ |
| 2327 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2328 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST | LYS_CONTAINER | LYS_ANYXML); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2329 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2330 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2331 | goto error; |
| 2332 | } |
| 2333 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2334 | rfn->target_type = LYS_LIST | LYS_LEAFLIST | LYS_CONTAINER | LYS_ANYXML; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2335 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2336 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2337 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 2338 | continue; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2339 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2340 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2341 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2342 | goto error; |
| 2343 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2344 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2345 | lyxml_free_elem(module->ctx, sub); |
| 2346 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2347 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2348 | /* process nodes with cardinality of 0..n */ |
| 2349 | if (c_must) { |
| 2350 | rfn->must = calloc(c_must, sizeof *rfn->must); |
| 2351 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2352 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2353 | r = fill_yin_must(module, sub, &rfn->must[rfn->must_size++]); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2354 | if (r) { |
| 2355 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2356 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2357 | add_unres_mnode(module, unres, &rfn->must[rfn->must_size-1], UNRES_MUST, (struct lys_node *)uses, |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2358 | LOGLINE(sub)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2359 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2360 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2361 | return EXIT_SUCCESS; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2362 | |
| 2363 | error: |
| 2364 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2365 | return EXIT_FAILURE; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2366 | } |
| 2367 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2368 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2369 | 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] | 2370 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2371 | struct lyxml_elem *child; |
| 2372 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2373 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2374 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2375 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2376 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2377 | continue; |
| 2378 | } |
| 2379 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2380 | if (!strcmp(child->name, "prefix")) { |
| 2381 | GETVAL(value, child, "value"); |
| 2382 | if (check_identifier(value, LY_IDENT_PREFIX, LOGLINE(child), module, NULL)) { |
| 2383 | goto error; |
| 2384 | } |
| 2385 | imp->prefix = lydict_insert(module->ctx, value, strlen(value)); |
| 2386 | } else if (!strcmp(child->name, "revision-date")) { |
| 2387 | if (imp->rev[0]) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2388 | LOGVAL(LYE_TOOMANY, LOGLINE(child), "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2389 | goto error; |
| 2390 | } |
| 2391 | GETVAL(value, child, "date"); |
| 2392 | if (check_date(value, LOGLINE(child))) { |
| 2393 | goto error; |
| 2394 | } |
| 2395 | memcpy(imp->rev, value, LY_REV_SIZE - 1); |
| 2396 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2397 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2398 | goto error; |
| 2399 | } |
| 2400 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2401 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2402 | /* check mandatory information */ |
| 2403 | if (!imp->prefix) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2404 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "prefix", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2405 | goto error; |
| 2406 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2407 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2408 | GETVAL(value, yin, "module"); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 2409 | 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] | 2410 | if (!imp->module) { |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 2411 | imp->module = lyp_search_file(module->ctx, NULL, value, imp->rev[0] ? imp->rev : NULL); |
| 2412 | if (!imp->module) { |
| 2413 | LOGERR(LY_EVALID, "Data model \"%s\" not found (search path is \"%s\")", value, module->ctx->models.search_path); |
| 2414 | LOGERR(LY_EVALID, "Importing \"%s\" module into \"%s\" failed.", value, module->name); |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2415 | LOGVAL(LYE_INARG, LOGLINE(yin), value, yin->name); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 2416 | goto error; |
| 2417 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2418 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2419 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2420 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2421 | |
| 2422 | error: |
| 2423 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2424 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2425 | } |
| 2426 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2427 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2428 | 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] | 2429 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2430 | struct lyxml_elem *child; |
| 2431 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2432 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2433 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2434 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2435 | /* garbage */ |
| 2436 | continue; |
| 2437 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2438 | if (!strcmp(child->name, "revision-date")) { |
| 2439 | if (inc->rev[0]) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2440 | LOGVAL(LYE_TOOMANY, LOGLINE(child), "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2441 | goto error; |
| 2442 | } |
| 2443 | GETVAL(value, child, "date"); |
| 2444 | if (check_date(value, LOGLINE(child))) { |
| 2445 | goto error; |
| 2446 | } |
| 2447 | memcpy(inc->rev, value, LY_REV_SIZE - 1); |
| 2448 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2449 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2450 | goto error; |
| 2451 | } |
| 2452 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2453 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2454 | GETVAL(value, yin, "module"); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 2455 | 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] | 2456 | if (!inc->submodule) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2457 | 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] | 2458 | if (!inc->submodule) { |
| 2459 | LOGERR(LY_EVALID, "Data model \"%s\" not found (search path is \"%s\")", value, module->ctx->models.search_path); |
| 2460 | LOGERR(LY_EVALID, "Including \"%s\" module into \"%s\" failed.", value, module->name); |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2461 | LOGVAL(LYE_INARG, LOGLINE(yin), value, yin->name); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 2462 | goto error; |
| 2463 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2464 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2465 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2466 | /* check that belongs-to corresponds */ |
| 2467 | if (module->type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2468 | module = ((struct lys_submodule *)module)->belongsto; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2469 | } |
| 2470 | if (inc->submodule->belongsto != module) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2471 | LOGVAL(LYE_INARG, LOGLINE(yin), value, yin->name); |
| 2472 | 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] | 2473 | goto error; |
| 2474 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2475 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2476 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2477 | |
| 2478 | error: |
| 2479 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2480 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2481 | } |
| 2482 | |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2483 | /* |
| 2484 | * Covers: |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 2485 | * description, reference, status, optionaly config |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 2486 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2487 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2488 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2489 | read_yin_common(struct lys_module *module, struct lys_node *parent, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2490 | struct lys_node *mnode, struct lyxml_elem *xmlnode, int opt) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2491 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2492 | const char *value; |
| 2493 | struct lyxml_elem *sub, *next; |
| 2494 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2495 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2496 | if (opt & OPT_MODULE) { |
| 2497 | mnode->module = module; |
| 2498 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2499 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2500 | if (opt & OPT_IDENT) { |
| 2501 | GETVAL(value, xmlnode, "name"); |
| 2502 | if (check_identifier(value, LY_IDENT_NAME, LOGLINE(xmlnode), NULL, NULL)) { |
| 2503 | goto error; |
| 2504 | } |
| 2505 | mnode->name = lydict_insert(ctx, value, strlen(value)); |
| 2506 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2507 | |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2508 | /* inherit NACM flags */ |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2509 | if ((opt & OPT_NACMEXT) && parent) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2510 | mnode->nacm = parent->nacm; |
| 2511 | } |
| 2512 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2513 | /* process local parameters */ |
| 2514 | LY_TREE_FOR_SAFE(xmlnode->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2515 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2516 | /* garbage */ |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2517 | lyxml_free_elem(ctx, sub); |
| 2518 | continue; |
| 2519 | } |
| 2520 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 2521 | /* NACM extensions */ |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2522 | if ((opt & OPT_NACMEXT) && !strcmp(sub->ns->value, LY_NSNACM)) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2523 | if (!strcmp(sub->name, "default-deny-write")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2524 | mnode->nacm |= LYS_NACM_DENYW; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2525 | } else if (!strcmp(sub->name, "default-deny-all")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2526 | mnode->nacm |= LYS_NACM_DENYA; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2527 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2528 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2529 | goto error; |
| 2530 | } |
| 2531 | } |
| 2532 | |
| 2533 | /* else garbage */ |
| 2534 | lyxml_free_elem(ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2535 | continue; |
| 2536 | } |
| 2537 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2538 | if (!strcmp(sub->name, "description")) { |
| 2539 | if (mnode->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2540 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2541 | goto error; |
| 2542 | } |
| 2543 | mnode->dsc = read_yin_subnode(ctx, sub, "text"); |
| 2544 | if (!mnode->dsc) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2545 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2546 | } |
| 2547 | } else if (!strcmp(sub->name, "reference")) { |
| 2548 | if (mnode->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2549 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2550 | goto error; |
| 2551 | } |
| 2552 | mnode->ref = read_yin_subnode(ctx, sub, "text"); |
| 2553 | if (!mnode->ref) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2554 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2555 | } |
| 2556 | } else if (!strcmp(sub->name, "status")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2557 | if (mnode->flags & LYS_STATUS_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2558 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2559 | goto error; |
| 2560 | } |
| 2561 | GETVAL(value, sub, "value"); |
| 2562 | if (!strcmp(value, "current")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2563 | mnode->flags |= LYS_STATUS_CURR; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2564 | } else if (!strcmp(value, "deprecated")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2565 | mnode->flags |= LYS_STATUS_DEPRC; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2566 | } else if (!strcmp(value, "obsolete")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2567 | mnode->flags |= LYS_STATUS_OBSLT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2568 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2569 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2570 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2571 | } |
| 2572 | } else if ((opt & OPT_CONFIG) && !strcmp(sub->name, "config")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2573 | if (mnode->flags & LYS_CONFIG_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2574 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2575 | goto error; |
| 2576 | } |
| 2577 | GETVAL(value, sub, "value"); |
| 2578 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2579 | mnode->flags |= LYS_CONFIG_R; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2580 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2581 | mnode->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2582 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2583 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2584 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2585 | } |
| 2586 | } else { |
| 2587 | /* skip the lyxml_free_elem */ |
| 2588 | continue; |
| 2589 | } |
| 2590 | lyxml_free_elem(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2591 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2592 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2593 | if ((opt & OPT_INHERIT) && !(mnode->flags & LYS_CONFIG_MASK)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2594 | /* get config flag from parent */ |
| 2595 | if (parent) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2596 | mnode->flags |= parent->flags & LYS_CONFIG_MASK; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2597 | } else { |
| 2598 | /* default config is true */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2599 | mnode->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2600 | } |
| 2601 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2602 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2603 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 2604 | |
| 2605 | error: |
| 2606 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2607 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2608 | } |
| 2609 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2610 | static struct lys_when * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2611 | read_yin_when(struct lys_module *module, struct lyxml_elem *yin) |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2612 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2613 | struct lys_when *retval = NULL; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2614 | struct lyxml_elem *child; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2615 | const char *value; |
| 2616 | |
| 2617 | retval = calloc(1, sizeof *retval); |
| 2618 | |
| 2619 | GETVAL(value, yin, "condition"); |
| 2620 | retval->cond = lydict_insert(module->ctx, value, 0); |
| 2621 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2622 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2623 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2624 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2625 | continue; |
| 2626 | } |
| 2627 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2628 | if (!strcmp(child->name, "description")) { |
| 2629 | if (retval->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2630 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2631 | goto error; |
| 2632 | } |
| 2633 | retval->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 2634 | if (!retval->dsc) { |
| 2635 | goto error; |
| 2636 | } |
| 2637 | } else if (!strcmp(child->name, "reference")) { |
| 2638 | if (retval->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2639 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2640 | goto error; |
| 2641 | } |
| 2642 | retval->ref = read_yin_subnode(module->ctx, child, "text"); |
| 2643 | if (!retval->ref) { |
| 2644 | goto error; |
| 2645 | } |
| 2646 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2647 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2648 | goto error; |
| 2649 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2650 | } |
| 2651 | |
| 2652 | return retval; |
| 2653 | |
| 2654 | error: |
| 2655 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2656 | ly_mnode_free((struct lys_node *)retval); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2657 | return NULL; |
| 2658 | } |
| 2659 | |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2660 | /* additional check in case statement - the child must be unique across |
| 2661 | * all other case names and its data children |
| 2662 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2663 | static int |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2664 | check_branch_id(struct lys_node *parent, struct lys_node *new, struct lys_node *excl, int line) |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2665 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2666 | struct lys_node *mnode, *submnode; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2667 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2668 | if (new->nodetype == LYS_CHOICE) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2669 | /* we have nested choice in case, so we need recursion */ |
| 2670 | LY_TREE_FOR(new->child, mnode) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2671 | if (mnode->nodetype == LYS_CASE) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2672 | LY_TREE_FOR(mnode->child, submnode) { |
| 2673 | if (check_branch_id(parent, submnode, new, line)) { |
| 2674 | return EXIT_FAILURE; |
| 2675 | } |
| 2676 | } |
| 2677 | } else if (check_branch_id(parent, mnode, new, line)) { |
| 2678 | return EXIT_FAILURE; |
| 2679 | } |
| 2680 | } |
| 2681 | } else { |
| 2682 | LY_TREE_FOR(parent->child, mnode) { |
| 2683 | if (mnode == excl) { |
| 2684 | continue; |
| 2685 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2686 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2687 | if (!strcmp(new->name, mnode->name)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2688 | LOGVAL(LYE_INID, line, new->name, "duplicated identifier within a choice's cases"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2689 | return EXIT_FAILURE; |
| 2690 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2691 | if (mnode->nodetype == LYS_CASE) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2692 | LY_TREE_FOR(mnode->child, submnode) { |
| 2693 | if (!strcmp(new->name, submnode->name)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2694 | LOGVAL(LYE_INID, line, new->name, "duplicated identifier within a choice's cases"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2695 | return EXIT_FAILURE; |
| 2696 | } |
| 2697 | } |
| 2698 | } |
| 2699 | } |
| 2700 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2701 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2702 | return EXIT_SUCCESS; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2703 | } |
| 2704 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2705 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2706 | read_yin_case(struct lys_module *module, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2707 | struct lys_node *parent, struct lyxml_elem *yin, int resolve, struct unres_item *unres) |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2708 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2709 | struct lyxml_elem *sub, *next; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2710 | struct lys_node_case *mcase; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2711 | struct lys_node *retval, *mnode = NULL; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2712 | int c_ftrs = 0; |
| 2713 | const char *value; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2714 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2715 | mcase = calloc(1, sizeof *mcase); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2716 | mcase->nodetype = LYS_CASE; |
| 2717 | mcase->prev = (struct lys_node *)mcase; |
| 2718 | retval = (struct lys_node *)mcase; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2719 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2720 | 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] | 2721 | goto error; |
| 2722 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 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")) { |
| 2733 | mnode = read_yin_container(module, retval, sub, resolve, unres); |
| 2734 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2735 | mnode = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2736 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2737 | mnode = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2738 | } else if (!strcmp(sub->name, "list")) { |
| 2739 | mnode = read_yin_list(module, retval, sub, resolve, unres); |
| 2740 | } else if (!strcmp(sub->name, "uses")) { |
| 2741 | mnode = read_yin_uses(module, retval, sub, resolve, unres); |
| 2742 | } else if (!strcmp(sub->name, "choice")) { |
| 2743 | mnode = read_yin_choice(module, retval, sub, resolve, unres); |
| 2744 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2745 | mnode = read_yin_anyxml(module, retval, sub, resolve, unres); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2746 | } else if (!strcmp(sub->name, "if-feature")) { |
| 2747 | c_ftrs++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2748 | /* skip lyxml_free_elem() at the end of the loop, sub is processed later */ |
| 2749 | continue; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2750 | } else if (!strcmp(sub->name, "when")) { |
| 2751 | if (mcase->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2752 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2753 | goto error; |
| 2754 | } |
| 2755 | |
| 2756 | mcase->when = read_yin_when(module, sub); |
| 2757 | if (!mcase->when) { |
| 2758 | goto error; |
| 2759 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2760 | add_unres_mnode(module, unres, mcase->when, UNRES_WHEN, retval, LOGLINE(sub)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2761 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2762 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2763 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2764 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2765 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2766 | if (!mnode) { |
| 2767 | goto error; |
| 2768 | } else if (check_branch_id(parent, mnode, mnode, LOGLINE(sub))) { |
| 2769 | goto error; |
| 2770 | } |
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 | mnode = NULL; |
| 2773 | lyxml_free_elem(module->ctx, sub); |
| 2774 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2775 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2776 | if (c_ftrs) { |
| 2777 | mcase->features = calloc(c_ftrs, sizeof *mcase->features); |
| 2778 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2779 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2780 | GETVAL(value, sub, "name"); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2781 | add_unres_str(module, unres, &mcase->features[mcase->features_size++], UNRES_IFFEAT, value, LOGLINE(sub)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2782 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 2783 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2784 | /* insert the node into the schema tree */ |
| 2785 | if (ly_mnode_addchild(parent, retval)) { |
| 2786 | goto error; |
| 2787 | } |
Radek Krejci | b7155b5 | 2015-06-10 17:03:01 +0200 | [diff] [blame] | 2788 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2789 | return retval; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2790 | |
| 2791 | error: |
| 2792 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2793 | ly_mnode_free(retval); |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2794 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2795 | return NULL; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2796 | } |
| 2797 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2798 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2799 | read_yin_choice(struct lys_module *module, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2800 | struct lys_node *parent, struct lyxml_elem *yin, int resolve, struct unres_item *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2801 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2802 | struct lyxml_elem *sub, *next; |
| 2803 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2804 | struct lys_node *retval, *mnode = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2805 | struct lys_node_choice *choice; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2806 | const char *value, *dflt_str = NULL; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2807 | int f_mand = 0, c_ftrs = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2808 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2809 | choice = calloc(1, sizeof *choice); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2810 | choice->nodetype = LYS_CHOICE; |
| 2811 | choice->prev = (struct lys_node *)choice; |
| 2812 | retval = (struct lys_node *)choice; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2813 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2814 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG | OPT_NACMEXT |
| 2815 | | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2816 | goto error; |
| 2817 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2818 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2819 | /* process choice's specific children */ |
| 2820 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2821 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2822 | /* garbage */ |
| 2823 | lyxml_free_elem(module->ctx, sub); |
| 2824 | continue; |
| 2825 | } |
| 2826 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2827 | if (!strcmp(sub->name, "container")) { |
| 2828 | if (!(mnode = read_yin_container(module, retval, sub, resolve, unres))) { |
| 2829 | goto error; |
| 2830 | } |
| 2831 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2832 | if (!(mnode = read_yin_leaflist(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2833 | goto error; |
| 2834 | } |
| 2835 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2836 | if (!(mnode = read_yin_leaf(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2837 | goto error; |
| 2838 | } |
| 2839 | } else if (!strcmp(sub->name, "list")) { |
| 2840 | if (!(mnode = read_yin_list(module, retval, sub, resolve, unres))) { |
| 2841 | goto error; |
| 2842 | } |
| 2843 | } else if (!strcmp(sub->name, "case")) { |
| 2844 | if (!(mnode = read_yin_case(module, retval, sub, resolve, unres))) { |
| 2845 | goto error; |
| 2846 | } |
| 2847 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2848 | if (!(mnode = read_yin_anyxml(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2849 | goto error; |
| 2850 | } |
| 2851 | } else if (!strcmp(sub->name, "default")) { |
| 2852 | if (dflt_str) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2853 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2854 | goto error; |
| 2855 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2856 | GETVAL(dflt_str, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2857 | } else if (!strcmp(sub->name, "mandatory")) { |
| 2858 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2859 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2860 | goto error; |
| 2861 | } |
| 2862 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2863 | * multiple mandatory statements with the "false" value |
| 2864 | */ |
| 2865 | f_mand = 1; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2866 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2867 | GETVAL(value, sub, "value"); |
| 2868 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2869 | choice->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2870 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2871 | choice->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2872 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2873 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2874 | goto error; |
| 2875 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2876 | } else if (!strcmp(sub->name, "when")) { |
| 2877 | if (choice->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2878 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2879 | goto error; |
| 2880 | } |
| 2881 | |
| 2882 | choice->when = read_yin_when(module, sub); |
| 2883 | if (!choice->when) { |
| 2884 | goto error; |
| 2885 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2886 | add_unres_mnode(module, unres, choice->when, UNRES_WHEN, retval, LOGLINE(sub)); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2887 | } else if (!strcmp(sub->name, "if-feature")) { |
| 2888 | c_ftrs++; |
| 2889 | |
| 2890 | /* skip lyxml_free_elem() at the end of the loop, the sub node is processed later */ |
| 2891 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2892 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2893 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2894 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2895 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2896 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2897 | if (mnode && check_branch_id(retval, mnode, mnode, LOGLINE(sub))) { |
| 2898 | goto error; |
| 2899 | } |
| 2900 | mnode = NULL; |
| 2901 | lyxml_free_elem(ctx, sub); |
| 2902 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2903 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2904 | if (c_ftrs) { |
| 2905 | choice->features = calloc(c_ftrs, sizeof *choice->features); |
| 2906 | } |
| 2907 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2908 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2909 | GETVAL(value, sub, "name"); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2910 | add_unres_str(module, unres, &choice->features[choice->features_size++], UNRES_IFFEAT, value, LOGLINE(sub)); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2911 | } |
| 2912 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2913 | /* check - default is prohibited in combination with mandatory */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2914 | if (dflt_str && (choice->flags & LYS_MAND_TRUE)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2915 | LOGVAL(LYE_SPEC, LOGLINE(yin), |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2916 | "The \"default\" statement MUST NOT be present on choices where \"mandatory\" is true."); |
| 2917 | goto error; |
| 2918 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2919 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2920 | /* link default with the case */ |
| 2921 | if (dflt_str) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2922 | add_unres_str(module, unres, choice, UNRES_CHOICE_DFLT, dflt_str, LOGLINE(yin)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2923 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2924 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2925 | /* insert the node into the schema tree */ |
| 2926 | if (parent && ly_mnode_addchild(parent, retval)) { |
| 2927 | goto error; |
| 2928 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2929 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2930 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2931 | |
| 2932 | error: |
| 2933 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2934 | ly_mnode_free(retval); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2935 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2936 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2937 | } |
| 2938 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2939 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2940 | read_yin_anyxml(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2941 | struct unres_item *unres) |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2942 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2943 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2944 | struct lys_node_leaf *anyxml; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2945 | struct lyxml_elem *sub, *next; |
| 2946 | const char *value; |
| 2947 | int r; |
| 2948 | int f_mand = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2949 | int c_must = 0, c_ftrs = 0; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2950 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2951 | anyxml = calloc(1, sizeof *anyxml); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2952 | anyxml->nodetype = LYS_ANYXML; |
| 2953 | anyxml->prev = (struct lys_node *)anyxml; |
| 2954 | retval = (struct lys_node *)anyxml; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2955 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2956 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG | OPT_NACMEXT |
| 2957 | | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2958 | goto error; |
| 2959 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2960 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2961 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2962 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2963 | /* garbage */ |
| 2964 | lyxml_free_elem(module->ctx, sub); |
| 2965 | continue; |
| 2966 | } |
| 2967 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2968 | if (!strcmp(sub->name, "mandatory")) { |
| 2969 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2970 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2971 | goto error; |
| 2972 | } |
| 2973 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2974 | * multiple mandatory statements with the "false" value |
| 2975 | */ |
| 2976 | f_mand = 1; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2977 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2978 | GETVAL(value, sub, "value"); |
| 2979 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2980 | anyxml->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2981 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2982 | anyxml->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2983 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2984 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2985 | goto error; |
| 2986 | } |
| 2987 | /* else false is the default value, so we can ignore it */ |
| 2988 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2989 | } else if (!strcmp(sub->name, "when")) { |
| 2990 | if (anyxml->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 2991 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2992 | goto error; |
| 2993 | } |
| 2994 | |
| 2995 | anyxml->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2996 | if (!anyxml->when) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2997 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2998 | goto error; |
| 2999 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3000 | add_unres_mnode(module, unres, anyxml->when, UNRES_WHEN, retval, LOGLINE(sub)); |
| 3001 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3002 | } else if (!strcmp(sub->name, "must")) { |
| 3003 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3004 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3005 | c_ftrs++; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3006 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3007 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3008 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3009 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3010 | } |
| 3011 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3012 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3013 | /* middle part - process nodes with cardinality of 0..n */ |
| 3014 | if (c_must) { |
| 3015 | anyxml->must = calloc(c_must, sizeof *anyxml->must); |
| 3016 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3017 | if (c_ftrs) { |
| 3018 | anyxml->features = calloc(c_ftrs, sizeof *anyxml->features); |
| 3019 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3020 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3021 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3022 | if (!strcmp(sub->name, "must")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3023 | r = fill_yin_must(module, sub, &anyxml->must[anyxml->must_size++]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3024 | if (r) { |
| 3025 | goto error; |
| 3026 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3027 | add_unres_mnode(module, unres, &anyxml->must[anyxml->must_size-1], UNRES_MUST, retval, LOGLINE(sub)); |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 3028 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3029 | GETVAL(value, sub, "name"); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3030 | add_unres_str(module, unres, &anyxml->features[anyxml->features_size++], UNRES_IFFEAT, value, LOGLINE(sub)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3031 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3032 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3033 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3034 | if (parent && ly_mnode_addchild(parent, retval)) { |
| 3035 | goto error; |
| 3036 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3037 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3038 | return retval; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3039 | |
| 3040 | error: |
| 3041 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3042 | ly_mnode_free(retval); |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3043 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3044 | return NULL; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3045 | } |
| 3046 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3047 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3048 | read_yin_leaf(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3049 | struct unres_item *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3050 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3051 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3052 | struct lys_node_leaf *leaf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3053 | struct lyxml_elem *sub, *next; |
| 3054 | const char *value; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3055 | int r, has_type = 0, dflt_line; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3056 | int c_must = 0, c_ftrs = 0, f_mand = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3057 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3058 | leaf = calloc(1, sizeof *leaf); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3059 | leaf->nodetype = LYS_LEAF; |
| 3060 | leaf->prev = (struct lys_node *)leaf; |
| 3061 | retval = (struct lys_node *)leaf; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3062 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3063 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG | OPT_NACMEXT |
| 3064 | | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3065 | goto error; |
| 3066 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3067 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3068 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3069 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3070 | /* garbage */ |
| 3071 | lyxml_free_elem(module->ctx, sub); |
| 3072 | continue; |
| 3073 | } |
| 3074 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3075 | if (!strcmp(sub->name, "type")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3076 | if (leaf->type.der || has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3077 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3078 | goto error; |
| 3079 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3080 | if (fill_yin_type(module, parent, sub, &leaf->type, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3081 | goto error; |
| 3082 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3083 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3084 | } else if (!strcmp(sub->name, "default")) { |
| 3085 | if (leaf->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3086 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3087 | goto error; |
| 3088 | } |
| 3089 | GETVAL(value, sub, "value"); |
| 3090 | leaf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3091 | dflt_line = LOGLINE(sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3092 | } else if (!strcmp(sub->name, "units")) { |
| 3093 | if (leaf->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3094 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3095 | goto error; |
| 3096 | } |
| 3097 | GETVAL(value, sub, "name"); |
| 3098 | leaf->units = lydict_insert(module->ctx, value, strlen(value)); |
| 3099 | } else if (!strcmp(sub->name, "mandatory")) { |
| 3100 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3101 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3102 | goto error; |
| 3103 | } |
| 3104 | /* just checking the flags in leaf is not sufficient, we would allow |
| 3105 | * multiple mandatory statements with the "false" value |
| 3106 | */ |
| 3107 | f_mand = 1; |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3108 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3109 | GETVAL(value, sub, "value"); |
| 3110 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3111 | leaf->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3112 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3113 | leaf->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3114 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3115 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3116 | goto error; |
| 3117 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3118 | } else if (!strcmp(sub->name, "when")) { |
| 3119 | if (leaf->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3120 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3121 | goto error; |
| 3122 | } |
| 3123 | |
| 3124 | leaf->when = read_yin_when(module, sub); |
| 3125 | if (!leaf->when) { |
| 3126 | goto error; |
| 3127 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3128 | add_unres_mnode(module, unres, leaf->when, UNRES_WHEN, retval, LOGLINE(sub)); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3129 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3130 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3131 | c_must++; |
| 3132 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3133 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3134 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3135 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3136 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3137 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3138 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3139 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3140 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3141 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3142 | lyxml_free_elem(module->ctx, sub); |
| 3143 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3144 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3145 | /* check mandatory parameters */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3146 | if (!has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3147 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3148 | goto error; |
| 3149 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3150 | if (leaf->dflt) { |
| 3151 | add_unres_str(module, unres, &leaf->type, UNRES_TYPE_DFLT, leaf->dflt, dflt_line); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3152 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3153 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3154 | /* middle part - process nodes with cardinality of 0..n */ |
| 3155 | if (c_must) { |
| 3156 | leaf->must = calloc(c_must, sizeof *leaf->must); |
| 3157 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3158 | if (c_ftrs) { |
| 3159 | leaf->features = calloc(c_ftrs, sizeof *leaf->features); |
| 3160 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3161 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3162 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3163 | if (!strcmp(sub->name, "must")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3164 | r = fill_yin_must(module, sub, &leaf->must[leaf->must_size++]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3165 | if (r) { |
| 3166 | goto error; |
| 3167 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3168 | add_unres_mnode(module, unres, &leaf->must[leaf->must_size-1], UNRES_MUST, retval, LOGLINE(sub)); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3169 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3170 | GETVAL(value, sub, "name"); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3171 | add_unres_str(module, unres, &leaf->features[leaf->features_size++], UNRES_IFFEAT, value, LOGLINE(sub)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3172 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3173 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3174 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3175 | if (parent && ly_mnode_addchild(parent, retval)) { |
| 3176 | goto error; |
| 3177 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3178 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3179 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3180 | |
| 3181 | error: |
| 3182 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3183 | ly_mnode_free(retval); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3184 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3185 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3186 | } |
| 3187 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3188 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3189 | read_yin_leaflist(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3190 | struct unres_item *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3191 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3192 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3193 | struct lys_node_leaflist *llist; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3194 | struct lyxml_elem *sub, *next; |
| 3195 | const char *value; |
| 3196 | char *endptr; |
| 3197 | unsigned long val; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3198 | int r, has_type = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3199 | int c_must = 0, c_ftrs = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3200 | int f_ordr = 0, f_min = 0, f_max = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3201 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3202 | llist = calloc(1, sizeof *llist); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3203 | llist->nodetype = LYS_LEAFLIST; |
| 3204 | llist->prev = (struct lys_node *)llist; |
| 3205 | retval = (struct lys_node *)llist; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3206 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3207 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG | OPT_NACMEXT |
| 3208 | | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3209 | goto error; |
| 3210 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3211 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3212 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3213 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3214 | /* garbage */ |
| 3215 | lyxml_free_elem(module->ctx, sub); |
| 3216 | continue; |
| 3217 | } |
| 3218 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3219 | if (!strcmp(sub->name, "type")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3220 | if (llist->type.der || has_type) { |
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 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3224 | if (fill_yin_type(module, parent, sub, &llist->type, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3225 | goto error; |
| 3226 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3227 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3228 | } else if (!strcmp(sub->name, "units")) { |
| 3229 | if (llist->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3230 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3231 | goto error; |
| 3232 | } |
| 3233 | GETVAL(value, sub, "name"); |
| 3234 | llist->units = lydict_insert(module->ctx, value, strlen(value)); |
| 3235 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 3236 | if (f_ordr) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3237 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3238 | goto error; |
| 3239 | } |
| 3240 | /* just checking the flags in llist is not sufficient, we would |
| 3241 | * allow multiple ordered-by statements with the "system" value |
| 3242 | */ |
| 3243 | f_ordr = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3244 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3245 | if (llist->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3246 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 3247 | * state data |
| 3248 | */ |
| 3249 | lyxml_free_elem(module->ctx, sub); |
| 3250 | continue; |
| 3251 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3252 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3253 | GETVAL(value, sub, "value"); |
| 3254 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3255 | llist->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3256 | } else if (strcmp(value, "system")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3257 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3258 | goto error; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3259 | } /* else system is the default value, so we can ignore it */ |
| 3260 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3261 | } else if (!strcmp(sub->name, "must")) { |
| 3262 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3263 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3264 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3265 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3266 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3267 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3268 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3269 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3270 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3271 | goto error; |
| 3272 | } |
| 3273 | f_min = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3274 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3275 | GETVAL(value, sub, "value"); |
| 3276 | while (isspace(value[0])) { |
| 3277 | value++; |
| 3278 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3279 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3280 | /* convert it to uint32_t */ |
| 3281 | errno = 0; |
| 3282 | endptr = NULL; |
| 3283 | val = strtoul(value, &endptr, 10); |
| 3284 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3285 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3286 | goto error; |
| 3287 | } |
| 3288 | llist->min = (uint32_t) val; |
| 3289 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3290 | if (f_max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3291 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3292 | goto error; |
| 3293 | } |
| 3294 | f_max = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3295 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3296 | GETVAL(value, sub, "value"); |
| 3297 | while (isspace(value[0])) { |
| 3298 | value++; |
| 3299 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3300 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3301 | /* convert it to uint32_t */ |
| 3302 | errno = 0; |
| 3303 | endptr = NULL; |
| 3304 | val = strtoul(value, &endptr, 10); |
| 3305 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3306 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3307 | goto error; |
| 3308 | } |
| 3309 | llist->max = (uint32_t) val; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3310 | } else if (!strcmp(sub->name, "when")) { |
| 3311 | if (llist->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3312 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3313 | goto error; |
| 3314 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3315 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3316 | llist->when = read_yin_when(module, sub); |
| 3317 | if (!llist->when) { |
| 3318 | goto error; |
| 3319 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3320 | add_unres_mnode(module, unres, llist->when, UNRES_WHEN, retval, LOGLINE(sub)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3321 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3322 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3323 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3324 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3325 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3326 | lyxml_free_elem(module->ctx, sub); |
| 3327 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3328 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3329 | /* check constraints */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3330 | if (!has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3331 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3332 | goto error; |
| 3333 | } |
| 3334 | if (llist->max && llist->min > llist->max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3335 | LOGVAL(LYE_SPEC, LOGLINE(yin), "\"min-elements\" is bigger than \"max-elements\"."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3336 | goto error; |
| 3337 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3338 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3339 | /* middle part - process nodes with cardinality of 0..n */ |
| 3340 | if (c_must) { |
| 3341 | llist->must = calloc(c_must, sizeof *llist->must); |
| 3342 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3343 | if (c_ftrs) { |
| 3344 | llist->features = calloc(c_ftrs, sizeof *llist->features); |
| 3345 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3346 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3347 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3348 | if (!strcmp(sub->name, "must")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3349 | r = fill_yin_must(module, sub, &llist->must[llist->must_size++]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3350 | if (r) { |
| 3351 | goto error; |
| 3352 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3353 | add_unres_mnode(module, unres, &llist->must[llist->must_size-1], UNRES_MUST, retval, LOGLINE(sub)); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3354 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3355 | GETVAL(value, sub, "name"); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3356 | add_unres_str(module, unres, &llist->features[llist->features_size++], UNRES_IFFEAT, value, LOGLINE(sub)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3357 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3358 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3359 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3360 | if (parent && ly_mnode_addchild(parent, retval)) { |
| 3361 | goto error; |
| 3362 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3363 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3364 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3365 | |
| 3366 | error: |
| 3367 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3368 | ly_mnode_free(retval); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3369 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3370 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3371 | } |
| 3372 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3373 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3374 | read_yin_list(struct lys_module *module, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3375 | struct lys_node *parent, struct lyxml_elem *yin, int resolve, struct unres_item *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3376 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3377 | struct lys_node *retval, *mnode; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3378 | struct lys_node_list *list; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3379 | struct lyxml_elem *sub, *next, root, uniq; |
Michal Vasko | e38af6e | 2015-08-03 14:39:27 +0200 | [diff] [blame] | 3380 | int r, key_line; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3381 | 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] | 3382 | int f_ordr = 0, f_max = 0, f_min = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3383 | const char *key_str = NULL, *value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3384 | char *auxs; |
| 3385 | unsigned long val; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3386 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3387 | /* init */ |
| 3388 | memset(&root, 0, sizeof root); |
| 3389 | memset(&uniq, 0, sizeof uniq); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3390 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3391 | list = calloc(1, sizeof *list); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3392 | list->nodetype = LYS_LIST; |
| 3393 | list->prev = (struct lys_node *)list; |
| 3394 | retval = (struct lys_node *)list; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3395 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3396 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG | OPT_NACMEXT |
| 3397 | | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3398 | goto error; |
| 3399 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3400 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3401 | /* process list's specific children */ |
| 3402 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3403 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3404 | /* garbage */ |
| 3405 | lyxml_free_elem(module->ctx, sub); |
| 3406 | continue; |
| 3407 | } |
| 3408 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3409 | /* data statements */ |
| 3410 | if (!strcmp(sub->name, "container") || |
| 3411 | !strcmp(sub->name, "leaf-list") || |
| 3412 | !strcmp(sub->name, "leaf") || |
| 3413 | !strcmp(sub->name, "list") || |
| 3414 | !strcmp(sub->name, "choice") || |
| 3415 | !strcmp(sub->name, "uses") || |
| 3416 | !strcmp(sub->name, "grouping") || |
| 3417 | !strcmp(sub->name, "anyxml")) { |
| 3418 | lyxml_unlink_elem(sub); |
| 3419 | lyxml_add_child(&root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3420 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3421 | /* array counters */ |
| 3422 | } else if (!strcmp(sub->name, "key")) { |
| 3423 | /* check cardinality 0..1 */ |
| 3424 | if (list->keys_size) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3425 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, list->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3426 | goto error; |
| 3427 | } |
Radek Krejci | d7f0d01 | 2015-05-25 15:04:52 +0200 | [diff] [blame] | 3428 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3429 | /* count the number of keys */ |
| 3430 | GETVAL(value, sub, "value"); |
| 3431 | key_str = value; |
Michal Vasko | e38af6e | 2015-08-03 14:39:27 +0200 | [diff] [blame] | 3432 | key_line = LOGLINE(sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3433 | while ((value = strpbrk(value, " \t\n"))) { |
| 3434 | list->keys_size++; |
| 3435 | while (isspace(*value)) { |
| 3436 | value++; |
| 3437 | } |
| 3438 | } |
| 3439 | list->keys_size++; |
| 3440 | list->keys = calloc(list->keys_size, sizeof *list->keys); |
| 3441 | } else if (!strcmp(sub->name, "unique")) { |
| 3442 | c_uniq++; |
| 3443 | lyxml_unlink_elem(sub); |
| 3444 | lyxml_add_child(&uniq, sub); |
| 3445 | } else if (!strcmp(sub->name, "typedef")) { |
| 3446 | c_tpdf++; |
| 3447 | } else if (!strcmp(sub->name, "must")) { |
| 3448 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3449 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3450 | c_ftrs++; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3451 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3452 | /* optional stetments */ |
| 3453 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 3454 | if (f_ordr) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3455 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3456 | goto error; |
| 3457 | } |
| 3458 | /* just checking the flags in llist is not sufficient, we would |
| 3459 | * allow multiple ordered-by statements with the "system" value |
| 3460 | */ |
| 3461 | f_ordr = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3462 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3463 | if (list->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3464 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 3465 | * state data |
| 3466 | */ |
| 3467 | lyxml_free_elem(module->ctx, sub); |
| 3468 | continue; |
| 3469 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3470 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3471 | GETVAL(value, sub, "value"); |
| 3472 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3473 | list->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3474 | } else if (strcmp(value, "system")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3475 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3476 | goto error; |
| 3477 | } |
| 3478 | /* else system is the default value, so we can ignore it */ |
| 3479 | lyxml_free_elem(module->ctx, sub); |
| 3480 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3481 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3482 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3483 | goto error; |
| 3484 | } |
| 3485 | f_min = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3486 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3487 | GETVAL(value, sub, "value"); |
| 3488 | while (isspace(value[0])) { |
| 3489 | value++; |
| 3490 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3491 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3492 | /* convert it to uint32_t */ |
| 3493 | errno = 0; |
| 3494 | auxs = NULL; |
| 3495 | val = strtoul(value, &auxs, 10); |
| 3496 | if (*auxs || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3497 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3498 | goto error; |
| 3499 | } |
| 3500 | list->min = (uint32_t) val; |
| 3501 | lyxml_free_elem(module->ctx, sub); |
| 3502 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3503 | if (f_max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3504 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3505 | goto error; |
| 3506 | } |
| 3507 | f_max = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3508 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3509 | GETVAL(value, sub, "value"); |
| 3510 | while (isspace(value[0])) { |
| 3511 | value++; |
| 3512 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3513 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3514 | /* convert it to uint32_t */ |
| 3515 | errno = 0; |
| 3516 | auxs = NULL; |
| 3517 | val = strtoul(value, &auxs, 10); |
| 3518 | if (*auxs || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3519 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3520 | goto error; |
| 3521 | } |
| 3522 | list->max = (uint32_t) val; |
| 3523 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3524 | } else if (!strcmp(sub->name, "when")) { |
| 3525 | if (list->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3526 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3527 | goto error; |
| 3528 | } |
| 3529 | |
| 3530 | list->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3531 | if (!list->when) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3532 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3533 | goto error; |
| 3534 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3535 | add_unres_mnode(module, unres, list->when, UNRES_WHEN, NULL, LOGLINE(sub)); |
| 3536 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3537 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3538 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3539 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3540 | } |
| 3541 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3542 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3543 | /* check - if list is configuration, key statement is mandatory */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3544 | if ((list->flags & LYS_CONFIG_W) && !key_str) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3545 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "key", "list"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3546 | goto error; |
| 3547 | } |
| 3548 | if (list->max && list->min > list->max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3549 | LOGVAL(LYE_SPEC, LOGLINE(yin), "\"min-elements\" is bigger than \"max-elements\"."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3550 | goto error; |
| 3551 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3552 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3553 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3554 | if (c_tpdf) { |
| 3555 | list->tpdf = calloc(c_tpdf, sizeof *list->tpdf); |
| 3556 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3557 | if (c_must) { |
| 3558 | list->must = calloc(c_must, sizeof *list->must); |
| 3559 | } |
| 3560 | if (c_ftrs) { |
| 3561 | list->features = calloc(c_ftrs, sizeof *list->features); |
| 3562 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3563 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3564 | if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3565 | 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] | 3566 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3567 | if (r) { |
| 3568 | goto error; |
| 3569 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3570 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3571 | GETVAL(value, sub, "name"); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3572 | add_unres_str(module, unres, &list->features[list->features_size++], UNRES_IFFEAT, value, LOGLINE(sub)); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3573 | } else if (!strcmp(sub->name, "must")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3574 | r = fill_yin_must(module, sub, &list->must[list->must_size++]); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3575 | if (r) { |
| 3576 | goto error; |
| 3577 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3578 | add_unres_mnode(module, unres, &list->must[list->must_size-1], UNRES_MUST, retval, LOGLINE(sub)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3579 | } |
| 3580 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 3581 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3582 | /* last part - process data nodes */ |
| 3583 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3584 | if (!strcmp(sub->name, "container")) { |
| 3585 | mnode = read_yin_container(module, retval, sub, resolve, unres); |
| 3586 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3587 | mnode = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3588 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3589 | mnode = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3590 | } else if (!strcmp(sub->name, "list")) { |
| 3591 | mnode = read_yin_list(module, retval, sub, resolve, unres); |
| 3592 | } else if (!strcmp(sub->name, "choice")) { |
| 3593 | mnode = read_yin_choice(module, retval, sub, resolve, unres); |
| 3594 | } else if (!strcmp(sub->name, "uses")) { |
| 3595 | mnode = read_yin_uses(module, retval, sub, resolve, unres); |
| 3596 | } else if (!strcmp(sub->name, "grouping")) { |
| 3597 | mnode = read_yin_grouping(module, retval, sub, resolve, unres); |
| 3598 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3599 | mnode = read_yin_anyxml(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3600 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3601 | if (!mnode) { |
| 3602 | goto error; |
| 3603 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3604 | |
| 3605 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3606 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3607 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3608 | if (parent && ly_mnode_addchild(parent, retval)) { |
| 3609 | goto error; |
| 3610 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3611 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3612 | if (!key_str) { |
| 3613 | /* config false list without a key */ |
| 3614 | return retval; |
| 3615 | } |
Michal Vasko | e38af6e | 2015-08-03 14:39:27 +0200 | [diff] [blame] | 3616 | add_unres_str(module, unres, list, UNRES_LIST_KEYS, key_str, key_line); |
Radek Krejci | 812b10a | 2015-05-28 16:48:25 +0200 | [diff] [blame] | 3617 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3618 | /* process unique statements */ |
| 3619 | if (c_uniq) { |
| 3620 | list->unique = calloc(c_uniq, sizeof *list->unique); |
| 3621 | } |
| 3622 | LY_TREE_FOR_SAFE(uniq.child, next, sub) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3623 | /* HACK for unres */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3624 | list->unique[list->unique_size++].leafs = (struct lys_node_leaf **)list; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3625 | GETVAL(value, sub, "tag"); |
| 3626 | add_unres_str(module, unres, &list->unique[list->unique_size-1], UNRES_LIST_UNIQ, value, LOGLINE(sub)); |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 3627 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3628 | lyxml_free_elem(module->ctx, sub); |
| 3629 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 3630 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3631 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3632 | |
| 3633 | error: |
| 3634 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3635 | ly_mnode_free(retval); |
| 3636 | while (root.child) { |
| 3637 | lyxml_free_elem(module->ctx, root.child); |
| 3638 | } |
| 3639 | while (uniq.child) { |
| 3640 | lyxml_free_elem(module->ctx, uniq.child); |
| 3641 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3642 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3643 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3644 | } |
| 3645 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3646 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3647 | read_yin_container(struct lys_module *module, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3648 | struct lys_node *parent, struct lyxml_elem *yin, int resolve, struct unres_item *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3649 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3650 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3651 | struct lys_node *mnode = NULL; |
| 3652 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3653 | struct lys_node_container *cont; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3654 | const char *value; |
| 3655 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3656 | int c_tpdf = 0, c_must = 0, c_ftrs = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3657 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3658 | /* init */ |
| 3659 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3660 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3661 | cont = calloc(1, sizeof *cont); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3662 | cont->nodetype = LYS_CONTAINER; |
| 3663 | cont->prev = (struct lys_node *)cont; |
| 3664 | retval = (struct lys_node *)cont; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3665 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3666 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG | OPT_NACMEXT |
| 3667 | | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3668 | goto error; |
| 3669 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3670 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3671 | /* process container's specific children */ |
| 3672 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3673 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3674 | /* garbage */ |
| 3675 | lyxml_free_elem(module->ctx, sub); |
| 3676 | continue; |
| 3677 | } |
| 3678 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3679 | if (!strcmp(sub->name, "presence")) { |
| 3680 | if (cont->presence) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3681 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3682 | goto error; |
| 3683 | } |
| 3684 | GETVAL(value, sub, "value"); |
| 3685 | cont->presence = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 3686 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3687 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3688 | } else if (!strcmp(sub->name, "when")) { |
| 3689 | if (cont->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3690 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3691 | goto error; |
| 3692 | } |
| 3693 | |
| 3694 | cont->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3695 | if (!cont->when) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3696 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3697 | goto error; |
| 3698 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3699 | add_unres_mnode(module, unres, cont->when, UNRES_WHEN, retval, LOGLINE(sub)); |
| 3700 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3701 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3702 | /* data statements */ |
| 3703 | } else if (!strcmp(sub->name, "container") || |
| 3704 | !strcmp(sub->name, "leaf-list") || |
| 3705 | !strcmp(sub->name, "leaf") || |
| 3706 | !strcmp(sub->name, "list") || |
| 3707 | !strcmp(sub->name, "choice") || |
| 3708 | !strcmp(sub->name, "uses") || |
| 3709 | !strcmp(sub->name, "grouping") || |
| 3710 | !strcmp(sub->name, "anyxml")) { |
| 3711 | lyxml_unlink_elem(sub); |
| 3712 | lyxml_add_child(&root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3713 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3714 | /* array counters */ |
| 3715 | } else if (!strcmp(sub->name, "typedef")) { |
| 3716 | c_tpdf++; |
| 3717 | } else if (!strcmp(sub->name, "must")) { |
| 3718 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3719 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3720 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3721 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3722 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3723 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3724 | } |
| 3725 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3726 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3727 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3728 | if (c_tpdf) { |
| 3729 | cont->tpdf = calloc(c_tpdf, sizeof *cont->tpdf); |
| 3730 | } |
| 3731 | if (c_must) { |
| 3732 | cont->must = calloc(c_must, sizeof *cont->must); |
| 3733 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3734 | if (c_ftrs) { |
| 3735 | cont->features = calloc(c_ftrs, sizeof *cont->features); |
| 3736 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 3737 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3738 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3739 | if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3740 | 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] | 3741 | if (r) { |
| 3742 | goto error; |
| 3743 | } |
| 3744 | } else if (!strcmp(sub->name, "must")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3745 | r = fill_yin_must(module, sub, &cont->must[cont->must_size++]); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3746 | if (r) { |
| 3747 | goto error; |
| 3748 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3749 | add_unres_mnode(module, unres, &cont->must[cont->must_size-1], UNRES_MUST, retval, LOGLINE(sub)); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3750 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3751 | GETVAL(value, sub, "name"); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3752 | add_unres_str(module, unres, &cont->features[cont->features_size++], UNRES_IFFEAT, value, LOGLINE(sub)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3753 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 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 | /* last part - process data nodes */ |
| 3757 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3758 | if (!strcmp(sub->name, "container")) { |
| 3759 | mnode = read_yin_container(module, retval, sub, resolve, unres); |
| 3760 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3761 | mnode = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3762 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3763 | mnode = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3764 | } else if (!strcmp(sub->name, "list")) { |
| 3765 | mnode = read_yin_list(module, retval, sub, resolve, unres); |
| 3766 | } else if (!strcmp(sub->name, "choice")) { |
| 3767 | mnode = read_yin_choice(module, retval, sub, resolve, unres); |
| 3768 | } else if (!strcmp(sub->name, "uses")) { |
| 3769 | mnode = read_yin_uses(module, retval, sub, resolve, unres); |
| 3770 | } else if (!strcmp(sub->name, "grouping")) { |
| 3771 | mnode = read_yin_grouping(module, retval, sub, resolve, unres); |
| 3772 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3773 | mnode = read_yin_anyxml(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3774 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3775 | if (!mnode) { |
| 3776 | goto error; |
| 3777 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3778 | |
| 3779 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3780 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3781 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3782 | if (parent && ly_mnode_addchild(parent, retval)) { |
| 3783 | goto error; |
| 3784 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3785 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3786 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3787 | |
| 3788 | error: |
| 3789 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3790 | ly_mnode_free(retval); |
| 3791 | while (root.child) { |
| 3792 | lyxml_free_elem(module->ctx, root.child); |
| 3793 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3794 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3795 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3796 | } |
| 3797 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3798 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3799 | read_yin_grouping(struct lys_module *module, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3800 | struct lys_node *parent, struct lyxml_elem *node, int resolve, struct unres_item *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3801 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3802 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3803 | struct lys_node *mnode = NULL; |
| 3804 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3805 | struct lys_node_grp *grp; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3806 | int r; |
| 3807 | int c_tpdf = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3808 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3809 | /* init */ |
| 3810 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3811 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3812 | grp = calloc(1, sizeof *grp); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3813 | grp->nodetype = LYS_GROUPING; |
| 3814 | grp->prev = (struct lys_node *)grp; |
| 3815 | retval = (struct lys_node *)grp; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3816 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 3817 | if (read_yin_common(module, parent, retval, node, OPT_IDENT | OPT_MODULE | OPT_NACMEXT)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3818 | goto error; |
| 3819 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3820 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3821 | LY_TREE_FOR_SAFE(node->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3822 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3823 | /* garbage */ |
| 3824 | lyxml_free_elem(module->ctx, sub); |
| 3825 | continue; |
| 3826 | } |
| 3827 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3828 | /* data statements */ |
| 3829 | if (!strcmp(sub->name, "container") || |
| 3830 | !strcmp(sub->name, "leaf-list") || |
| 3831 | !strcmp(sub->name, "leaf") || |
| 3832 | !strcmp(sub->name, "list") || |
| 3833 | !strcmp(sub->name, "choice") || |
| 3834 | !strcmp(sub->name, "uses") || |
| 3835 | !strcmp(sub->name, "grouping") || |
| 3836 | !strcmp(sub->name, "anyxml")) { |
| 3837 | lyxml_unlink_elem(sub); |
| 3838 | lyxml_add_child(&root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3839 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3840 | /* array counters */ |
| 3841 | } else if (!strcmp(sub->name, "typedef")) { |
| 3842 | c_tpdf++; |
| 3843 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3844 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3845 | goto error; |
| 3846 | } |
| 3847 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3848 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3849 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3850 | if (c_tpdf) { |
| 3851 | grp->tpdf = calloc(c_tpdf, sizeof *grp->tpdf); |
| 3852 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3853 | LY_TREE_FOR(node->child, sub) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3854 | 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] | 3855 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3856 | if (r) { |
| 3857 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3858 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3859 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3860 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3861 | /* last part - process data nodes */ |
| 3862 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3863 | if (!strcmp(sub->name, "container")) { |
| 3864 | mnode = read_yin_container(module, retval, sub, resolve, unres); |
| 3865 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3866 | mnode = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3867 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3868 | mnode = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3869 | } else if (!strcmp(sub->name, "list")) { |
| 3870 | mnode = read_yin_list(module, retval, sub, resolve, unres); |
| 3871 | } else if (!strcmp(sub->name, "choice")) { |
| 3872 | mnode = read_yin_choice(module, retval, sub, resolve, unres); |
| 3873 | } else if (!strcmp(sub->name, "uses")) { |
| 3874 | mnode = read_yin_uses(module, retval, sub, resolve, unres); |
| 3875 | } else if (!strcmp(sub->name, "grouping")) { |
| 3876 | mnode = read_yin_grouping(module, retval, sub, resolve, unres); |
| 3877 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3878 | mnode = read_yin_anyxml(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3879 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3880 | if (!mnode) { |
| 3881 | goto error; |
| 3882 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3883 | |
| 3884 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3885 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3886 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3887 | if (parent && ly_mnode_addchild(parent, retval)) { |
| 3888 | goto error; |
| 3889 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3890 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3891 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3892 | |
| 3893 | error: |
| 3894 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3895 | ly_mnode_free(retval); |
| 3896 | while (root.child) { |
| 3897 | lyxml_free_elem(module->ctx, root.child); |
| 3898 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3899 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3900 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3901 | } |
| 3902 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3903 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3904 | read_yin_input_output(struct lys_module *module, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3905 | struct lys_node *parent, struct lyxml_elem *yin, int resolve, struct unres_item *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3906 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3907 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3908 | struct lys_node *mnode = NULL; |
| 3909 | struct lys_node *retval; |
Radek Krejci | 4608ada | 2015-08-05 16:04:37 +0200 | [diff] [blame] | 3910 | struct lys_node_rpc_inout *inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3911 | int r; |
| 3912 | int c_tpdf = 0; |
| 3913 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3914 | /* init */ |
| 3915 | memset(&root, 0, sizeof root); |
| 3916 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3917 | inout = calloc(1, sizeof *inout); |
| 3918 | |
| 3919 | if (!strcmp(yin->name, "input")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3920 | inout->nodetype = LYS_INPUT; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3921 | } else if (!strcmp(yin->name, "output")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3922 | inout->nodetype = LYS_OUTPUT; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3923 | } else { |
| 3924 | assert(0); |
| 3925 | } |
| 3926 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3927 | inout->prev = (struct lys_node *)inout; |
| 3928 | retval = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3929 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 3930 | if (read_yin_common(module, parent, retval, yin, OPT_MODULE | OPT_NACMEXT)) { |
Michal Vasko | ebeac94 | 2015-06-15 12:11:50 +0200 | [diff] [blame] | 3931 | goto error; |
| 3932 | } |
| 3933 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3934 | /* data statements */ |
| 3935 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3936 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3937 | /* garbage */ |
| 3938 | lyxml_free_elem(module->ctx, sub); |
| 3939 | continue; |
| 3940 | } |
| 3941 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3942 | if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3943 | !strcmp(sub->name, "leaf-list") || |
| 3944 | !strcmp(sub->name, "leaf") || |
| 3945 | !strcmp(sub->name, "list") || |
| 3946 | !strcmp(sub->name, "choice") || |
| 3947 | !strcmp(sub->name, "uses") || |
| 3948 | !strcmp(sub->name, "grouping") || |
| 3949 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3950 | lyxml_unlink_elem(sub); |
| 3951 | lyxml_add_child(&root, sub); |
| 3952 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3953 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3954 | } else if (!strcmp(sub->name, "typedef")) { |
| 3955 | c_tpdf++; |
Radek Krejci | d2bfa79 | 2015-07-02 16:45:29 +0200 | [diff] [blame] | 3956 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3957 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 3958 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3959 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3960 | } |
| 3961 | } |
| 3962 | |
| 3963 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3964 | if (c_tpdf) { |
| 3965 | inout->tpdf = calloc(c_tpdf, sizeof *inout->tpdf); |
| 3966 | } |
| 3967 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3968 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3969 | 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] | 3970 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3971 | if (r) { |
| 3972 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3973 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3974 | } |
| 3975 | |
| 3976 | /* last part - process data nodes */ |
| 3977 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3978 | if (!strcmp(sub->name, "container")) { |
| 3979 | mnode = read_yin_container(module, retval, sub, resolve, unres); |
| 3980 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3981 | mnode = read_yin_leaflist(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3982 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3983 | mnode = read_yin_leaf(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3984 | } else if (!strcmp(sub->name, "list")) { |
| 3985 | mnode = read_yin_list(module, retval, sub, resolve, unres); |
| 3986 | } else if (!strcmp(sub->name, "choice")) { |
| 3987 | mnode = read_yin_choice(module, retval, sub, resolve, unres); |
| 3988 | } else if (!strcmp(sub->name, "uses")) { |
| 3989 | mnode = read_yin_uses(module, retval, sub, resolve, unres); |
| 3990 | } else if (!strcmp(sub->name, "grouping")) { |
| 3991 | mnode = read_yin_grouping(module, retval, sub, resolve, unres); |
| 3992 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3993 | mnode = read_yin_anyxml(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3994 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 3995 | if (!mnode) { |
| 3996 | goto error; |
| 3997 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3998 | |
| 3999 | lyxml_free_elem(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4000 | } |
| 4001 | |
| 4002 | if (parent && ly_mnode_addchild(parent, retval)) { |
| 4003 | goto error; |
| 4004 | } |
| 4005 | |
| 4006 | return retval; |
| 4007 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4008 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4009 | |
| 4010 | ly_mnode_free(retval); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 4011 | while (root.child) { |
| 4012 | lyxml_free_elem(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4013 | } |
| 4014 | |
| 4015 | return NULL; |
| 4016 | } |
| 4017 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4018 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4019 | read_yin_notif(struct lys_module *module, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4020 | struct lys_node *parent, struct lyxml_elem *yin, int resolve, struct unres_item *unres) |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4021 | { |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 4022 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4023 | struct lys_node *mnode = NULL; |
| 4024 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4025 | struct lys_node_notif *notif; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4026 | const char *value; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4027 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4028 | int c_tpdf = 0, c_ftrs = 0; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4029 | |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 4030 | memset(&root, 0, sizeof root); |
| 4031 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4032 | notif = calloc(1, sizeof *notif); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4033 | notif->nodetype = LYS_NOTIF; |
| 4034 | notif->prev = (struct lys_node *)notif; |
| 4035 | retval = (struct lys_node *)notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4036 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4037 | 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] | 4038 | goto error; |
| 4039 | } |
| 4040 | |
| 4041 | /* process rpc's specific children */ |
| 4042 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4043 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4044 | /* garbage */ |
| 4045 | lyxml_free_elem(module->ctx, sub); |
| 4046 | continue; |
| 4047 | } |
| 4048 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4049 | /* data statements */ |
| 4050 | if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4051 | !strcmp(sub->name, "leaf-list") || |
| 4052 | !strcmp(sub->name, "leaf") || |
| 4053 | !strcmp(sub->name, "list") || |
| 4054 | !strcmp(sub->name, "choice") || |
| 4055 | !strcmp(sub->name, "uses") || |
| 4056 | !strcmp(sub->name, "grouping") || |
| 4057 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4058 | lyxml_unlink_elem(sub); |
| 4059 | lyxml_add_child(&root, sub); |
| 4060 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4061 | /* array counters */ |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4062 | } else if (!strcmp(sub->name, "typedef")) { |
| 4063 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4064 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4065 | c_ftrs++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4066 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4067 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4068 | goto error; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4069 | } |
| 4070 | } |
| 4071 | |
| 4072 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4073 | if (c_tpdf) { |
| 4074 | notif->tpdf = calloc(c_tpdf, sizeof *notif->tpdf); |
| 4075 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4076 | if (c_ftrs) { |
| 4077 | notif->features = calloc(c_ftrs, sizeof *notif->features); |
| 4078 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4079 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4080 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4081 | if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4082 | 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] | 4083 | |
| 4084 | if (r) { |
| 4085 | goto error; |
| 4086 | } |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 4087 | } else if (!strcmp(sub->name, "if-features")) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4088 | GETVAL(value, sub, "name"); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4089 | add_unres_str(module, unres, ¬if->features[notif->features_size++], UNRES_IFFEAT, value, LOGLINE(sub)); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4090 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4091 | } |
| 4092 | |
| 4093 | /* last part - process data nodes */ |
| 4094 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4095 | if (!strcmp(sub->name, "container")) { |
| 4096 | mnode = read_yin_container(module, retval, sub, resolve, unres); |
| 4097 | } else if (!strcmp(sub->name, "leaf-list")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4098 | mnode = read_yin_leaflist(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4099 | } else if (!strcmp(sub->name, "leaf")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4100 | mnode = read_yin_leaf(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4101 | } else if (!strcmp(sub->name, "list")) { |
| 4102 | mnode = read_yin_list(module, retval, sub, resolve, unres); |
| 4103 | } else if (!strcmp(sub->name, "choice")) { |
| 4104 | mnode = read_yin_choice(module, retval, sub, resolve, unres); |
| 4105 | } else if (!strcmp(sub->name, "uses")) { |
| 4106 | mnode = read_yin_uses(module, retval, sub, resolve, unres); |
| 4107 | } else if (!strcmp(sub->name, "grouping")) { |
| 4108 | mnode = read_yin_grouping(module, retval, sub, resolve, unres); |
| 4109 | } else if (!strcmp(sub->name, "anyxml")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4110 | mnode = read_yin_anyxml(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4111 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4112 | if (!mnode) { |
| 4113 | goto error; |
| 4114 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4115 | |
| 4116 | lyxml_free_elem(module->ctx, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4117 | } |
| 4118 | |
| 4119 | if (parent && ly_mnode_addchild(parent, retval)) { |
| 4120 | goto error; |
| 4121 | } |
| 4122 | |
| 4123 | return retval; |
| 4124 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4125 | error: |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4126 | |
| 4127 | ly_mnode_free(retval); |
| 4128 | while (root.child) { |
| 4129 | lyxml_free_elem(module->ctx, root.child); |
| 4130 | } |
| 4131 | |
| 4132 | return NULL; |
| 4133 | } |
| 4134 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4135 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4136 | read_yin_rpc(struct lys_module *module, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4137 | struct lys_node *parent, struct lyxml_elem *yin, int resolve, struct unres_item *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4138 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4139 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4140 | struct lys_node *mnode = NULL; |
| 4141 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4142 | struct lys_node_rpc *rpc; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4143 | const char *value; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4144 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4145 | int c_tpdf = 0, c_ftrs = 0; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4146 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4147 | /* init */ |
| 4148 | memset(&root, 0, sizeof root); |
| 4149 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4150 | rpc = calloc(1, sizeof *rpc); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4151 | rpc->nodetype = LYS_RPC; |
| 4152 | rpc->prev = (struct lys_node *)rpc; |
| 4153 | retval = (struct lys_node *)rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4154 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4155 | 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] | 4156 | goto error; |
| 4157 | } |
| 4158 | |
| 4159 | /* process rpc's specific children */ |
| 4160 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4161 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4162 | /* garbage */ |
| 4163 | lyxml_free_elem(module->ctx, sub); |
| 4164 | continue; |
| 4165 | } |
| 4166 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4167 | if (!strcmp(sub->name, "input")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4168 | if (rpc->child |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4169 | && (rpc->child->nodetype == LYS_INPUT |
| 4170 | || (rpc->child->next && rpc->child->next->nodetype == LYS_INPUT))) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4171 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4172 | goto error; |
| 4173 | } |
| 4174 | lyxml_unlink_elem(sub); |
| 4175 | lyxml_add_child(&root, sub); |
| 4176 | } else if (!strcmp(sub->name, "output")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4177 | if (rpc->child |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4178 | && (rpc->child->nodetype == LYS_INPUT |
| 4179 | || (rpc->child->next && rpc->child->next->nodetype == LYS_INPUT))) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4180 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4181 | goto error; |
| 4182 | } |
| 4183 | lyxml_unlink_elem(sub); |
| 4184 | lyxml_add_child(&root, sub); |
| 4185 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4186 | /* data statements */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4187 | } else if (!strcmp(sub->name, "grouping")) { |
| 4188 | lyxml_unlink_elem(sub); |
| 4189 | lyxml_add_child(&root, sub); |
| 4190 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4191 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4192 | } else if (!strcmp(sub->name, "typedef")) { |
| 4193 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4194 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4195 | c_ftrs++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4196 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4197 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4198 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4199 | } |
| 4200 | } |
| 4201 | |
| 4202 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4203 | if (c_tpdf) { |
| 4204 | rpc->tpdf = calloc(c_tpdf, sizeof *rpc->tpdf); |
| 4205 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4206 | if (c_ftrs) { |
| 4207 | rpc->features = calloc(c_ftrs, sizeof *rpc->features); |
| 4208 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4209 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4210 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4211 | if (!strcmp(sub->name, "typedef")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4212 | 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] | 4213 | |
| 4214 | if (r) { |
| 4215 | goto error; |
| 4216 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4217 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4218 | GETVAL(value, sub, "name"); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4219 | add_unres_str(module, unres, &rpc->features[rpc->features_size++], UNRES_IFFEAT, value, LOGLINE(sub)); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4220 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4221 | } |
| 4222 | |
| 4223 | /* last part - process data nodes */ |
| 4224 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4225 | if (!strcmp(sub->name, "grouping")) { |
| 4226 | mnode = read_yin_grouping(module, retval, sub, resolve, unres); |
| 4227 | } else if (!strcmp(sub->name, "input")) { |
| 4228 | mnode = read_yin_input_output(module, retval, sub, resolve, unres); |
| 4229 | } else if (!strcmp(sub->name, "output")) { |
| 4230 | mnode = read_yin_input_output(module, retval, sub, resolve, unres); |
| 4231 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4232 | if (!mnode) { |
| 4233 | goto error; |
| 4234 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4235 | |
| 4236 | lyxml_free_elem(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4237 | } |
| 4238 | |
| 4239 | if (parent && ly_mnode_addchild(parent, retval)) { |
| 4240 | goto error; |
| 4241 | } |
| 4242 | |
| 4243 | return retval; |
| 4244 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4245 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4246 | |
| 4247 | ly_mnode_free(retval); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 4248 | while (root.child) { |
| 4249 | lyxml_free_elem(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4250 | } |
| 4251 | |
| 4252 | return NULL; |
| 4253 | } |
| 4254 | |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4255 | /* |
| 4256 | * resolve - referenced grouping should be bounded to the namespace (resolved) |
| 4257 | * only when uses does not appear in grouping. In a case of grouping's uses, |
| 4258 | * we just get information but we do not apply augment or refine to it. |
| 4259 | */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4260 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4261 | read_yin_uses(struct lys_module *module, |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4262 | struct lys_node *parent, struct lyxml_elem *node, int resolve, struct unres_item *unres) |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4263 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4264 | struct lyxml_elem *sub, *next; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4265 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4266 | struct lys_node_uses *uses; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4267 | const char *value; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4268 | int c_ref = 0, c_aug = 0, c_ftrs = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4269 | int r; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4270 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4271 | uses = calloc(1, sizeof *uses); |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4272 | uses->nodetype = LYS_USES; |
| 4273 | uses->prev = (struct lys_node *)uses; |
| 4274 | retval = (struct lys_node *)uses; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4275 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4276 | GETVAL(value, node, "name"); |
| 4277 | uses->name = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 4278 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4279 | if (read_yin_common(module, parent, retval, node, OPT_MODULE | OPT_NACMEXT | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4280 | goto error; |
| 4281 | } |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4282 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4283 | /* get other properties of uses */ |
| 4284 | LY_TREE_FOR_SAFE(node->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4285 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4286 | /* garbage */ |
| 4287 | lyxml_free_elem(module->ctx, sub); |
| 4288 | continue; |
| 4289 | } |
| 4290 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4291 | if (!strcmp(sub->name, "refine")) { |
| 4292 | c_ref++; |
| 4293 | } else if (!strcmp(sub->name, "augment")) { |
| 4294 | c_aug++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4295 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 56e8977 | 2015-06-19 10:00:54 +0200 | [diff] [blame] | 4296 | c_ftrs++; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4297 | } else if (!strcmp(sub->name, "when")) { |
| 4298 | if (uses->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4299 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, node->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4300 | goto error; |
| 4301 | } |
| 4302 | |
| 4303 | uses->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4304 | if (!uses->when) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4305 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4306 | goto error; |
| 4307 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4308 | add_unres_mnode(module, unres, uses->when, UNRES_WHEN, retval, LOGLINE(sub)); |
| 4309 | lyxml_free_elem(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4310 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4311 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4312 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4313 | } |
| 4314 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4315 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4316 | /* process properties with cardinality 0..n */ |
| 4317 | if (c_ref) { |
| 4318 | uses->refine = calloc(c_ref, sizeof *uses->refine); |
| 4319 | } |
| 4320 | if (c_aug) { |
| 4321 | uses->augment = calloc(c_aug, sizeof *uses->augment); |
| 4322 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4323 | if (c_ftrs) { |
| 4324 | uses->features = calloc(c_ftrs, sizeof *uses->features); |
| 4325 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4326 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4327 | LY_TREE_FOR(node->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4328 | if (!strcmp(sub->name, "refine")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4329 | r = fill_yin_refine(module, sub, &uses->refine[uses->refine_size++], uses, unres); |
| 4330 | if (r) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4331 | goto error; |
| 4332 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4333 | } else if (!strcmp(sub->name, "augment")) { |
| 4334 | r = fill_yin_augment(module, retval, sub, &uses->augment[uses->augment_size++], unres); |
| 4335 | if (r) { |
| 4336 | goto error; |
| 4337 | } |
| 4338 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4339 | GETVAL(value, sub, "name"); |
| 4340 | add_unres_str(module, unres, &uses->features[uses->features_size++], UNRES_IFFEAT, value, LOGLINE(sub)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4341 | } |
| 4342 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4343 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4344 | add_unres_mnode(module, unres, uses, UNRES_USES, NULL, LOGLINE(node)); |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4345 | |
Radek Krejci | 368c38f | 2015-06-15 15:09:55 +0200 | [diff] [blame] | 4346 | if (parent && ly_mnode_addchild(parent, retval)) { |
| 4347 | goto error; |
| 4348 | } |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4349 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4350 | if (resolve) { |
| 4351 | /* inherit config flag */ |
| 4352 | if (parent) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4353 | retval->flags |= parent->flags & LYS_CONFIG_MASK; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4354 | } else { |
| 4355 | /* default config is true */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4356 | retval->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4357 | } |
| 4358 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 4359 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4360 | return retval; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4361 | |
| 4362 | error: |
| 4363 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4364 | ly_mnode_free(retval); |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4365 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4366 | return NULL; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4367 | } |
| 4368 | |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4369 | /* common code for yin_read_module() and yin_read_submodule() */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4370 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4371 | read_sub_module(struct lys_module *module, struct lyxml_elem *yin, struct unres_item *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4372 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4373 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4374 | struct lys_submodule *submodule = (struct lys_submodule *)module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4375 | struct lyxml_elem *next, *node, *child, root, grps, rpcs, notifs; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4376 | struct lys_node *mnode = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4377 | const char *value; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4378 | int i, r; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4379 | int belongsto_flag = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4380 | /* counters */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4381 | 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] | 4382 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4383 | /* init */ |
| 4384 | memset(&root, 0, sizeof root); |
| 4385 | memset(&grps, 0, sizeof grps); |
| 4386 | memset(&rpcs, 0, sizeof rpcs); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4387 | memset(¬ifs, 0, sizeof notifs); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4388 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4389 | /* |
| 4390 | * in the first run, we process elements with cardinality of 1 or 0..1 and |
| 4391 | * count elements with cardinality 0..n. Data elements (choices, containers, |
| 4392 | * leafs, lists, leaf-lists) are moved aside to be processed last, since we |
| 4393 | * need have all top-level and groupings already prepared at that time. In |
| 4394 | * the middle loop, we process other elements with carinality of 0..n since |
| 4395 | * we need to allocate arrays to store them. |
| 4396 | */ |
| 4397 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 4398 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4399 | /* garbage */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4400 | lyxml_free_elem(ctx, node); |
| 4401 | continue; |
| 4402 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4403 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4404 | if (!module->type && !strcmp(node->name, "namespace")) { |
| 4405 | if (module->ns) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4406 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4407 | goto error; |
| 4408 | } |
| 4409 | GETVAL(value, node, "uri"); |
| 4410 | module->ns = lydict_insert(ctx, value, strlen(value)); |
| 4411 | lyxml_free_elem(ctx, node); |
| 4412 | } else if (!module->type && !strcmp(node->name, "prefix")) { |
| 4413 | if (module->prefix) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4414 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4415 | goto error; |
| 4416 | } |
| 4417 | GETVAL(value, node, "value"); |
| 4418 | if (check_identifier(value, LY_IDENT_PREFIX, LOGLINE(node), module, NULL)) { |
| 4419 | goto error; |
| 4420 | } |
| 4421 | module->prefix = lydict_insert(ctx, value, strlen(value)); |
| 4422 | lyxml_free_elem(ctx, node); |
| 4423 | } else if (module->type && !strcmp(node->name, "belongs-to")) { |
| 4424 | if (belongsto_flag) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4425 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4426 | goto error; |
| 4427 | } |
| 4428 | belongsto_flag = 1; |
| 4429 | GETVAL(value, node, "module"); |
| 4430 | while (submodule->belongsto->type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4431 | submodule->belongsto = ((struct lys_submodule *)submodule->belongsto)->belongsto; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4432 | } |
| 4433 | if (value != submodule->belongsto->name) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4434 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4435 | goto error; |
| 4436 | } |
Radek Krejci | f388693 | 2015-06-04 17:36:06 +0200 | [diff] [blame] | 4437 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4438 | /* get the prefix substatement, start with checks */ |
| 4439 | if (!node->child) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4440 | LOGVAL(LYE_MISSSTMT2, LOGLINE(node), "prefix", node->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4441 | goto error; |
| 4442 | } else if (strcmp(node->child->name, "prefix")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4443 | LOGVAL(LYE_INSTMT, LOGLINE(node->child), node->child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4444 | goto error; |
| 4445 | } else if (node->child->next) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4446 | LOGVAL(LYE_INSTMT, LOGLINE(node->child->next), node->child->next->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4447 | goto error; |
| 4448 | } |
| 4449 | /* and now finally get the value */ |
| 4450 | GETVAL(value, node->child, "value"); |
| 4451 | /* check here differs from a generic prefix check, since this prefix |
| 4452 | * don't have to be unique |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4453 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4454 | if (check_identifier(value, LY_IDENT_NAME, LOGLINE(node->child), NULL, NULL)) { |
| 4455 | goto error; |
| 4456 | } |
| 4457 | module->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 0af1387 | 2015-05-30 11:50:52 +0200 | [diff] [blame] | 4458 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4459 | /* we are done with belongs-to */ |
| 4460 | lyxml_free_elem(ctx, node); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4461 | |
| 4462 | /* counters (statements with n..1 cardinality) */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4463 | } else if (!strcmp(node->name, "import")) { |
| 4464 | c_imp++; |
| 4465 | } else if (!strcmp(node->name, "revision")) { |
| 4466 | c_rev++; |
| 4467 | } else if (!strcmp(node->name, "typedef")) { |
| 4468 | c_tpdf++; |
| 4469 | } else if (!strcmp(node->name, "identity")) { |
| 4470 | c_ident++; |
| 4471 | } else if (!strcmp(node->name, "include")) { |
| 4472 | c_inc++; |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4473 | } else if (!strcmp(node->name, "augment")) { |
| 4474 | c_aug++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4475 | } else if (!strcmp(node->name, "feature")) { |
| 4476 | c_ftrs++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4477 | } else if (!strcmp(node->name, "deviation")) { |
| 4478 | c_dev++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4479 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4480 | /* data statements */ |
| 4481 | } else if (!strcmp(node->name, "container") || |
| 4482 | !strcmp(node->name, "leaf-list") || |
| 4483 | !strcmp(node->name, "leaf") || |
| 4484 | !strcmp(node->name, "list") || |
| 4485 | !strcmp(node->name, "choice") || |
| 4486 | !strcmp(node->name, "uses") || |
| 4487 | !strcmp(node->name, "anyxml")) { |
| 4488 | lyxml_unlink_elem(node); |
| 4489 | lyxml_add_child(&root, node); |
| 4490 | } else if (!strcmp(node->name, "grouping")) { |
| 4491 | /* keep groupings separated and process them before other data statements */ |
| 4492 | lyxml_unlink_elem(node); |
| 4493 | lyxml_add_child(&grps, node); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4494 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4495 | /* optional statements */ |
| 4496 | } else if (!strcmp(node->name, "description")) { |
| 4497 | if (module->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4498 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4499 | goto error; |
| 4500 | } |
| 4501 | module->dsc = read_yin_subnode(ctx, node, "text"); |
| 4502 | lyxml_free_elem(ctx, node); |
| 4503 | if (!module->dsc) { |
| 4504 | goto error; |
| 4505 | } |
| 4506 | } else if (!strcmp(node->name, "reference")) { |
| 4507 | if (module->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4508 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4509 | goto error; |
| 4510 | } |
| 4511 | module->ref = read_yin_subnode(ctx, node, "text"); |
| 4512 | lyxml_free_elem(ctx, node); |
| 4513 | if (!module->ref) { |
| 4514 | goto error; |
| 4515 | } |
| 4516 | } else if (!strcmp(node->name, "organization")) { |
| 4517 | if (module->org) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4518 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4519 | goto error; |
| 4520 | } |
| 4521 | module->org = read_yin_subnode(ctx, node, "text"); |
| 4522 | lyxml_free_elem(ctx, node); |
| 4523 | if (!module->org) { |
| 4524 | goto error; |
| 4525 | } |
| 4526 | } else if (!strcmp(node->name, "contact")) { |
| 4527 | if (module->contact) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4528 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4529 | goto error; |
| 4530 | } |
| 4531 | module->contact = read_yin_subnode(ctx, node, "text"); |
| 4532 | lyxml_free_elem(ctx, node); |
| 4533 | if (!module->contact) { |
| 4534 | goto error; |
| 4535 | } |
| 4536 | } else if (!strcmp(node->name, "yang-version")) { |
| 4537 | /* TODO: support YANG 1.1 ? */ |
| 4538 | if (module->version) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4539 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4540 | goto error; |
| 4541 | } |
| 4542 | GETVAL(value, node, "value"); |
| 4543 | if (strcmp(value, "1")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4544 | LOGVAL(LYE_INARG, LOGLINE(node), value, "yang-version"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4545 | goto error; |
| 4546 | } |
| 4547 | module->version = 1; |
| 4548 | lyxml_free_elem(ctx, node); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4549 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4550 | /* rpcs & notifications */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4551 | } else if (!strcmp(node->name, "rpc")) { |
| 4552 | lyxml_unlink_elem(node); |
| 4553 | lyxml_add_child(&rpcs, node); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4554 | } else if (!strcmp(node->name, "notification")) { |
| 4555 | lyxml_unlink_elem(node); |
| 4556 | lyxml_add_child(¬ifs, node); |
Radek Krejci | 5166a89 | 2015-07-02 16:44:24 +0200 | [diff] [blame] | 4557 | |
| 4558 | } else if (!strcmp(node->name, "extension")) { |
| 4559 | GETVAL(value, node, "name"); |
Radek Krejci | 5166a89 | 2015-07-02 16:44:24 +0200 | [diff] [blame] | 4560 | |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 4561 | /* we have 2 supported (hardcoded) extensions: |
| 4562 | * NACM's default-deny-write and default-deny-all |
| 4563 | */ |
| 4564 | if (strcmp(module->ns, LY_NSNACM) || |
| 4565 | (strcmp(value, "default-deny-write") && strcmp(value, "default-deny-all"))) { |
| 4566 | LOGWRN("Not supported \"%s\" extension statement found, ignoring.", value); |
| 4567 | lyxml_free_elem(ctx, node); |
| 4568 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4569 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4570 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4571 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4572 | } |
| 4573 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4574 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4575 | if (!submodule) { |
| 4576 | /* check for mandatory statements */ |
| 4577 | if (!module->ns) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4578 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "namespace", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4579 | goto error; |
| 4580 | } |
| 4581 | if (!module->prefix) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4582 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "prefix", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4583 | goto error; |
| 4584 | } |
| 4585 | } |
Radek Krejci | bb3257d | 2015-05-21 23:03:51 +0200 | [diff] [blame] | 4586 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4587 | /* allocate arrays for elements with cardinality of 0..n */ |
| 4588 | if (c_imp) { |
| 4589 | module->imp = calloc(c_imp, sizeof *module->imp); |
| 4590 | } |
| 4591 | if (c_rev) { |
| 4592 | module->rev = calloc(c_rev, sizeof *module->rev); |
| 4593 | } |
| 4594 | if (c_tpdf) { |
| 4595 | module->tpdf = calloc(c_tpdf, sizeof *module->tpdf); |
| 4596 | } |
| 4597 | if (c_ident) { |
| 4598 | module->ident = calloc(c_ident, sizeof *module->ident); |
| 4599 | } |
| 4600 | if (c_inc) { |
| 4601 | module->inc = calloc(c_inc, sizeof *module->inc); |
| 4602 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4603 | if (c_aug) { |
| 4604 | module->augment = calloc(c_aug, sizeof *module->augment); |
| 4605 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4606 | if (c_ftrs) { |
| 4607 | module->features = calloc(c_ftrs, sizeof *module->features); |
| 4608 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4609 | if (c_dev) { |
| 4610 | module->deviation = calloc(c_dev, sizeof *module->deviation); |
| 4611 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4612 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4613 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4614 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4615 | if (!strcmp(node->name, "import")) { |
| 4616 | r = fill_yin_import(module, node, &module->imp[module->imp_size]); |
| 4617 | module->imp_size++; |
| 4618 | if (r) { |
| 4619 | goto error; |
| 4620 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4621 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4622 | /* check duplicities in imported modules */ |
| 4623 | for (i = 0; i < module->imp_size - 1; i++) { |
| 4624 | if (!strcmp(module->imp[i].module->name, module->imp[module->imp_size - 1].module->name)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4625 | LOGVAL(LYE_SPEC, LOGLINE(node), "Importing module \"%s\" repeatedly.", module->imp[i].module->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4626 | goto error; |
| 4627 | } |
| 4628 | } |
| 4629 | } else if (!strcmp(node->name, "include")) { |
| 4630 | r = fill_yin_include(module, node, &module->inc[module->inc_size]); |
| 4631 | module->inc_size++; |
| 4632 | if (r) { |
| 4633 | goto error; |
| 4634 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4635 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4636 | /* check duplications in include submodules */ |
| 4637 | for (i = 0; i < module->inc_size - 1; i++) { |
| 4638 | if (!strcmp(module->inc[i].submodule->name, module->inc[module->inc_size - 1].submodule->name)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4639 | LOGVAL(LYE_SPEC, LOGLINE(node), "Importing module \"%s\" repeatedly.", |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4640 | module->inc[i].submodule->name); |
| 4641 | goto error; |
| 4642 | } |
| 4643 | } |
| 4644 | } else if (!strcmp(node->name, "revision")) { |
| 4645 | GETVAL(value, node, "date"); |
| 4646 | if (check_date(value, LOGLINE(node))) { |
| 4647 | goto error; |
| 4648 | } |
| 4649 | memcpy(module->rev[module->rev_size].date, value, LY_REV_SIZE - 1); |
| 4650 | /* check uniqueness of the revision date - not required by RFC */ |
| 4651 | for (i = 0; i < module->rev_size; i++) { |
| 4652 | if (!strcmp(value, module->rev[i].date)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4653 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
| 4654 | LOGVAL(LYE_SPEC, 0, "Revision is not unique."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4655 | } |
| 4656 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4657 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4658 | LY_TREE_FOR(node->child, child) { |
| 4659 | if (!strcmp(child->name, "description")) { |
| 4660 | if (module->rev[module->rev_size].dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4661 | LOGVAL(LYE_TOOMANY, LOGLINE(node), child->name, node->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4662 | goto error; |
| 4663 | } |
| 4664 | module->rev[module->rev_size].dsc = read_yin_subnode(ctx, child, "text"); |
| 4665 | if (!module->rev[module->rev_size].dsc) { |
| 4666 | goto error; |
| 4667 | } |
| 4668 | } else if (!strcmp(child->name, "reference")) { |
| 4669 | if (module->rev[module->rev_size].ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4670 | LOGVAL(LYE_TOOMANY, LOGLINE(node), child->name, node->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4671 | goto error; |
| 4672 | } |
| 4673 | module->rev[module->rev_size].ref = read_yin_subnode(ctx, child, "text"); |
| 4674 | if (!module->rev[module->rev_size].ref) { |
| 4675 | goto error; |
| 4676 | } |
| 4677 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4678 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4679 | goto error; |
| 4680 | } |
| 4681 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4682 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4683 | /* keep the latest revision at position 0 */ |
| 4684 | if (module->rev_size && strcmp(module->rev[module->rev_size].date, module->rev[0].date) > 0) { |
| 4685 | /* switch their position */ |
| 4686 | value = strdup(module->rev[0].date); |
| 4687 | memcpy(module->rev[0].date, module->rev[module->rev_size].date, LY_REV_SIZE - 1); |
| 4688 | memcpy(module->rev[module->rev_size].date, value, LY_REV_SIZE - 1); |
| 4689 | free((char *)value); |
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].dsc != module->rev[module->rev_size].dsc) { |
| 4692 | value = module->rev[0].dsc; |
| 4693 | module->rev[0].dsc = module->rev[module->rev_size].dsc; |
| 4694 | module->rev[module->rev_size].dsc = value; |
| 4695 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4696 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4697 | if (module->rev[0].ref != module->rev[module->rev_size].ref) { |
| 4698 | value = module->rev[0].ref; |
| 4699 | module->rev[0].ref = module->rev[module->rev_size].ref; |
| 4700 | module->rev[module->rev_size].ref = value; |
| 4701 | } |
| 4702 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4703 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4704 | module->rev_size++; |
| 4705 | } else if (!strcmp(node->name, "typedef")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4706 | r = fill_yin_typedef(module, NULL, node, &module->tpdf[module->tpdf_size], unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4707 | module->tpdf_size++; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 4708 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4709 | if (r) { |
| 4710 | goto error; |
| 4711 | } |
| 4712 | } else if (!strcmp(node->name, "identity")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4713 | r = fill_yin_identity(module, node, &module->ident[module->ident_size], unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4714 | module->ident_size++; |
Radek Krejci | 6793db0 | 2015-05-22 17:49:54 +0200 | [diff] [blame] | 4715 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4716 | if (r) { |
| 4717 | goto error; |
| 4718 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4719 | } else if (!strcmp(node->name, "feature")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4720 | r = fill_yin_feature(module, node, &module->features[module->features_size], unres); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4721 | module->features_size++; |
| 4722 | |
| 4723 | if (r) { |
| 4724 | goto error; |
| 4725 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4726 | } else if (!strcmp(node->name, "augment")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4727 | r = fill_yin_augment(module, NULL, node, &module->augment[module->augment_size], unres); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4728 | module->augment_size++; |
| 4729 | |
| 4730 | if (r) { |
| 4731 | goto error; |
| 4732 | } |
| 4733 | |
| 4734 | /* node is reconnected into the augment, so we have to skip its free at the end of the loop */ |
| 4735 | continue; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4736 | } else if (!strcmp(node->name, "deviation")) { |
| 4737 | r = fill_yin_deviation(module, node, &module->deviation[module->deviation_size]); |
| 4738 | module->deviation_size++; |
| 4739 | |
| 4740 | if (r) { |
| 4741 | goto error; |
| 4742 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4743 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4744 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4745 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4746 | /* process data nodes. Start with groupings to allow uses |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4747 | * refer to them |
| 4748 | */ |
| 4749 | LY_TREE_FOR_SAFE(grps.child, next, node) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4750 | mnode = read_yin_grouping(module, NULL, node, 0, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4751 | if (!mnode) { |
| 4752 | goto error; |
| 4753 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4754 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4755 | lyxml_free_elem(ctx, node); |
| 4756 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4757 | /* include data element */ |
| 4758 | if (module->data) { |
| 4759 | module->data->prev->next = mnode; |
| 4760 | mnode->prev = module->data->prev; |
| 4761 | module->data->prev = mnode; |
| 4762 | } else { |
| 4763 | module->data = mnode; |
| 4764 | } |
| 4765 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4766 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4767 | /* parse data nodes, ... */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4768 | LY_TREE_FOR_SAFE(root.child, next, node) { |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4769 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4770 | if (!strcmp(node->name, "container")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4771 | mnode = read_yin_container(module, NULL, node, 1, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4772 | } else if (!strcmp(node->name, "leaf-list")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4773 | mnode = read_yin_leaflist(module, NULL, node, 1, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4774 | } else if (!strcmp(node->name, "leaf")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4775 | mnode = read_yin_leaf(module, NULL, node, 1, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4776 | } else if (!strcmp(node->name, "list")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4777 | mnode = read_yin_list(module, NULL, node, 1, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4778 | } else if (!strcmp(node->name, "choice")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4779 | mnode = read_yin_choice(module, NULL, node, 1, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4780 | } else if (!strcmp(node->name, "uses")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4781 | mnode = read_yin_uses(module, NULL, node, 1, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4782 | } else if (!strcmp(node->name, "anyxml")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4783 | mnode = read_yin_anyxml(module, NULL, node, 1, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4784 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4785 | if (!mnode) { |
| 4786 | goto error; |
| 4787 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 4788 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4789 | lyxml_free_elem(ctx, node); |
| 4790 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4791 | /* include data element */ |
| 4792 | if (module->data) { |
| 4793 | module->data->prev->next = mnode; |
| 4794 | mnode->prev = module->data->prev; |
| 4795 | module->data->prev = mnode; |
| 4796 | } else { |
| 4797 | module->data = mnode; |
| 4798 | } |
| 4799 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4800 | |
| 4801 | /* ... rpcs ... */ |
| 4802 | LY_TREE_FOR_SAFE(rpcs.child, next, node) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4803 | mnode = read_yin_rpc(module, NULL, node, 0, unres); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4804 | if (!mnode) { |
| 4805 | goto error; |
| 4806 | } |
| 4807 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4808 | lyxml_free_elem(ctx, node); |
| 4809 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4810 | /* include rpc element */ |
| 4811 | if (module->rpc) { |
| 4812 | module->rpc->prev->next = mnode; |
| 4813 | mnode->prev = module->rpc->prev; |
| 4814 | module->rpc->prev = mnode; |
| 4815 | } else { |
| 4816 | module->rpc = mnode; |
| 4817 | } |
| 4818 | } |
| 4819 | |
| 4820 | /* ... and notifications */ |
| 4821 | LY_TREE_FOR_SAFE(notifs.child, next, node) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4822 | mnode = read_yin_notif(module, NULL, node, 0, unres); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4823 | if (!mnode) { |
| 4824 | goto error; |
| 4825 | } |
| 4826 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4827 | lyxml_free_elem(ctx, node); |
| 4828 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4829 | /* include notification element */ |
| 4830 | if (module->notif) { |
| 4831 | module->notif->prev->next = mnode; |
| 4832 | mnode->prev = module->notif->prev; |
| 4833 | module->notif->prev = mnode; |
| 4834 | } else { |
| 4835 | module->notif = mnode; |
| 4836 | } |
| 4837 | } |
| 4838 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4839 | return EXIT_SUCCESS; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4840 | |
| 4841 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4842 | /* cleanup */ |
| 4843 | while (root.child) { |
| 4844 | lyxml_free_elem(module->ctx, root.child); |
| 4845 | } |
| 4846 | while (grps.child) { |
| 4847 | lyxml_free_elem(module->ctx, grps.child); |
| 4848 | } |
| 4849 | while (rpcs.child) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4850 | lyxml_free_elem(module->ctx, rpcs.child); |
| 4851 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4852 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4853 | free(unres->item); |
| 4854 | unres->item = NULL; |
| 4855 | free(unres->type); |
| 4856 | unres->type = NULL; |
| 4857 | free(unres->str_mnode); |
| 4858 | unres->str_mnode = NULL; |
| 4859 | free(unres->line); |
| 4860 | unres->line = NULL; |
| 4861 | unres->count = 0; |
Radek Krejci | 8de7b0f | 2015-07-02 11:43:42 +0200 | [diff] [blame] | 4862 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4863 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4864 | } |
| 4865 | |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4866 | struct lys_submodule * |
| 4867 | yin_read_submodule(struct lys_module *module, const char *data, int implement, struct unres_item *unres) |
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 | struct lyxml_elem *yin; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4870 | struct lys_submodule *submodule = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4871 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4872 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4873 | assert(module->ctx); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4874 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4875 | yin = lyxml_read(module->ctx, data, 0); |
| 4876 | if (!yin) { |
| 4877 | return NULL; |
| 4878 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4879 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4880 | /* check root element */ |
| 4881 | if (!yin->name || strcmp(yin->name, "submodule")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4882 | LOGVAL(LYE_INSTMT, LOGLINE(yin), yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4883 | goto error; |
| 4884 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4885 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4886 | GETVAL(value, yin, "name"); |
| 4887 | if (check_identifier(value, LY_IDENT_NAME, LOGLINE(yin), NULL, NULL)) { |
| 4888 | goto error; |
| 4889 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4890 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4891 | submodule = calloc(1, sizeof *submodule); |
| 4892 | if (!submodule) { |
| 4893 | LOGMEM; |
| 4894 | goto error; |
| 4895 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4896 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4897 | submodule->ctx = module->ctx; |
| 4898 | submodule->name = lydict_insert(submodule->ctx, value, strlen(value)); |
| 4899 | submodule->type = 1; |
| 4900 | submodule->belongsto = module; |
Michal Vasko | d8aa32d | 2015-07-24 11:50:01 +0200 | [diff] [blame] | 4901 | submodule->implemented = (implement ? 1 : 0); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4902 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4903 | LOGVRB("reading submodule %s", submodule->name); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4904 | if (read_sub_module((struct lys_module *)submodule, yin, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4905 | goto error; |
| 4906 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4907 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4908 | /* cleanup */ |
| 4909 | lyxml_free_elem(module->ctx, yin); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4910 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4911 | LOGVRB("submodule %s successfully parsed", submodule->name); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4912 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4913 | return submodule; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4914 | |
| 4915 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4916 | /* cleanup */ |
| 4917 | lyxml_free_elem(module->ctx, yin); |
| 4918 | ly_submodule_free(submodule); |
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 | return NULL; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4921 | } |
| 4922 | |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4923 | struct lys_module * |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4924 | yin_read_module(struct ly_ctx *ctx, const char *data, int implement, struct unres_item *unres) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4925 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4926 | struct lyxml_elem *yin; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4927 | struct lys_module *module = NULL, **newlist = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4928 | const char *value; |
| 4929 | int i; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4930 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4931 | yin = lyxml_read(ctx, data, 0); |
| 4932 | if (!yin) { |
| 4933 | return NULL; |
| 4934 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4935 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4936 | /* check root element */ |
| 4937 | if (!yin->name || strcmp(yin->name, "module")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame^] | 4938 | LOGVAL(LYE_INSTMT, LOGLINE(yin), yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4939 | goto error; |
| 4940 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4941 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4942 | GETVAL(value, yin, "name"); |
| 4943 | if (check_identifier(value, LY_IDENT_NAME, LOGLINE(yin), NULL, NULL)) { |
| 4944 | goto error; |
| 4945 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4946 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4947 | module = calloc(1, sizeof *module); |
| 4948 | if (!module) { |
| 4949 | LOGMEM; |
| 4950 | goto error; |
| 4951 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4952 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4953 | module->ctx = ctx; |
| 4954 | module->name = lydict_insert(ctx, value, strlen(value)); |
| 4955 | module->type = 0; |
Michal Vasko | d8aa32d | 2015-07-24 11:50:01 +0200 | [diff] [blame] | 4956 | module->implemented = (implement ? 1 : 0); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4957 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4958 | LOGVRB("reading module %s", module->name); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4959 | if (read_sub_module(module, yin, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4960 | goto error; |
| 4961 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 4962 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4963 | /* add to the context's list of modules */ |
| 4964 | if (ctx->models.used == ctx->models.size) { |
| 4965 | newlist = realloc(ctx->models.list, ctx->models.size * 2); |
| 4966 | if (!newlist) { |
| 4967 | LOGMEM; |
| 4968 | goto error; |
| 4969 | } |
| 4970 | for (i = ctx->models.size; i < ctx->models.size * 2; i++) { |
| 4971 | newlist[i] = NULL; |
| 4972 | } |
| 4973 | ctx->models.size *= 2; |
| 4974 | ctx->models.list = newlist; |
| 4975 | } |
| 4976 | for (i = 0; ctx->models.list[i]; i++) { |
| 4977 | /* check name (name/revision) and namespace uniqueness */ |
| 4978 | if (!strcmp(ctx->models.list[i]->name, module->name)) { |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 4979 | if (ctx->models.list[i]->rev_size == module->rev_size) { |
| 4980 | /* both have the same number of revisions */ |
| 4981 | if (!module->rev_size || !strcmp(ctx->models.list[i]->rev[0].date, module->rev[0].date)) { |
| 4982 | /* both have the same revision -> we already have the same module */ |
| 4983 | /* so free the new one and update the old one's implement flag if needed */ |
| 4984 | lyxml_free_elem(ctx, yin); |
| 4985 | lys_free(module); |
| 4986 | |
| 4987 | LOGVRB("module %s already in context", ctx->models.list[i]->name); |
| 4988 | |
| 4989 | if (implement && !ctx->models.list[i]->implemented) { |
| 4990 | lyp_set_implemented(ctx->models.list[i]); |
| 4991 | } |
| 4992 | return ctx->models.list[i]; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4993 | } |
| 4994 | } |
Radek Krejci | f647e61 | 2015-07-30 11:36:07 +0200 | [diff] [blame] | 4995 | /* else (both elses) keep searching, for now the caller is just adding |
| 4996 | * another revision of an already present schema |
| 4997 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4998 | } else if (!strcmp(ctx->models.list[i]->ns, module->ns)) { |
| 4999 | LOGERR(LY_EINVAL, "Two different modules (\"%s\" and \"%s\") have the same namespace \"%s\"", |
| 5000 | ctx->models.list[i]->name, module->name, module->ns); |
| 5001 | goto error; |
| 5002 | } |
| 5003 | } |
| 5004 | ctx->models.list[i] = module; |
| 5005 | ctx->models.used++; |
Michal Vasko | 68cffd7 | 2015-08-03 12:50:11 +0200 | [diff] [blame] | 5006 | ctx->models.module_set_id++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5007 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5008 | /* cleanup */ |
| 5009 | lyxml_free_elem(ctx, yin); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5010 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5011 | LOGVRB("module %s successfully parsed", module->name); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5012 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5013 | return module; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5014 | |
| 5015 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5016 | /* cleanup */ |
| 5017 | lyxml_free_elem(ctx, yin); |
Radek Krejci | 912da45 | 2015-07-29 14:10:06 +0200 | [diff] [blame] | 5018 | lys_free(module); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5019 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5020 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5021 | } |