Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file yin.c |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief YIN parser for libyang |
| 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in |
| 15 | * the documentation and/or other materials provided with the |
| 16 | * distribution. |
| 17 | * 3. Neither the name of the Company nor the names of its contributors |
| 18 | * may be used to endorse or promote products derived from this |
| 19 | * software without specific prior written permission. |
| 20 | */ |
| 21 | |
Radek Krejci | 812b10a | 2015-05-28 16:48:25 +0200 | [diff] [blame] | 22 | #include <assert.h> |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 23 | #include <ctype.h> |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 24 | #include <errno.h> |
| 25 | #include <limits.h> |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 26 | #include <stdint.h> |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 27 | #include <stdlib.h> |
| 28 | #include <string.h> |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 29 | #include <stddef.h> |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 30 | #include <sys/types.h> |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 31 | #include <pcre.h> |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 32 | |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 33 | #include "libyang.h" |
| 34 | #include "common.h" |
| 35 | #include "context.h" |
Radek Krejci | 41912fe | 2015-10-22 10:22:12 +0200 | [diff] [blame] | 36 | #include "dict_private.h" |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 37 | #include "xpath.h" |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 38 | #include "parser.h" |
Radek Krejci | 998a0b8 | 2015-08-17 13:14:36 +0200 | [diff] [blame] | 39 | #include "resolve.h" |
| 40 | #include "tree_internal.h" |
Michal Vasko | fc5744d | 2015-10-22 12:09:34 +0200 | [diff] [blame] | 41 | #include "xml_internal.h" |
Radek Krejci | efdd0ce | 2015-05-26 16:48:29 +0200 | [diff] [blame] | 42 | |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 43 | #define GETVAL(value, node, arg) \ |
Michal Vasko | 2d710f3 | 2016-02-05 12:29:21 +0100 | [diff] [blame] | 44 | value = lyxml_get_attr(node, arg, NULL); \ |
| 45 | if (!value) { \ |
| 46 | LOGVAL(LYE_MISSARG, LOGLINE(node), arg, node->name); \ |
| 47 | goto error; \ |
| 48 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 49 | |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 50 | /* parser.c */ |
| 51 | int dup_prefix_check(const char *prefix, struct lys_module *module); |
| 52 | |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 53 | #define OPT_IDENT 0x01 |
| 54 | #define OPT_CONFIG 0x02 |
| 55 | #define OPT_MODULE 0x04 |
| 56 | #define OPT_INHERIT 0x08 |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 57 | #define OPT_NACMEXT 0x10 |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 58 | 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] | 59 | |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 60 | static struct lys_node *read_yin_choice(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 61 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 62 | static struct lys_node *read_yin_case(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 63 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 64 | static struct lys_node *read_yin_anyxml(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 65 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 66 | static struct lys_node *read_yin_container(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 67 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 68 | static struct lys_node *read_yin_leaf(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 69 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 70 | static struct lys_node *read_yin_leaflist(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 71 | int resolve, struct unres_schema *unres); |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 72 | static struct lys_node *read_yin_list(struct lys_module *module,struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 73 | int resolve, struct unres_schema *unres); |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 74 | static struct lys_node *read_yin_uses(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 75 | int resolve, struct unres_schema *unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 76 | static struct lys_node *read_yin_grouping(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 77 | int resolve, struct unres_schema *unres); |
| 78 | 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] | 79 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 80 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 81 | static const char * |
| 82 | 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] | 83 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 84 | int len; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 85 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 86 | /* there should be <text> child */ |
| 87 | if (!node->child || !node->child->name || strcmp(node->child->name, name)) { |
| 88 | LOGWRN("Expected \"%s\" element in \"%s\" element.", name, node->name); |
| 89 | } else if (node->child->content) { |
| 90 | len = strlen(node->child->content); |
| 91 | return lydict_insert(ctx, node->child->content, len); |
| 92 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 93 | |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 94 | LOGVAL(LYE_INARG, LOGLINE(node), name, node->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 95 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 96 | } |
| 97 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 98 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 99 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 100 | fill_yin_identity(struct lys_module *module, struct lyxml_elem *yin, struct lys_ident *ident, struct unres_schema *unres) |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 101 | { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 102 | struct lyxml_elem *node; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 103 | const char *value; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 104 | |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 105 | GETVAL(value, yin, "name"); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 106 | ident->name = value; |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 107 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 108 | 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] | 109 | return EXIT_FAILURE; |
| 110 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 111 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 112 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 113 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 114 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 115 | continue; |
| 116 | } |
| 117 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 118 | if (!strcmp(node->name, "base")) { |
| 119 | if (ident->base) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 120 | LOGVAL(LYE_TOOMANY, LOGLINE(node), "base", "identity"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 121 | return EXIT_FAILURE; |
| 122 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 123 | GETVAL(value, node, "name"); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 124 | value = transform_schema2json(module, value, LOGLINE(node)); |
| 125 | if (!value) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 126 | return EXIT_FAILURE; |
| 127 | } |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 128 | |
| 129 | if (unres_schema_add_str(module, unres, ident, UNRES_IDENT, value, LOGLINE(node)) == -1) { |
| 130 | lydict_remove(module->ctx, value); |
| 131 | return EXIT_FAILURE; |
| 132 | } |
| 133 | lydict_remove(module->ctx, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 134 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 135 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name, "identity"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 136 | return EXIT_FAILURE; |
| 137 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 138 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 139 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 140 | return EXIT_SUCCESS; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 141 | |
| 142 | error: |
| 143 | return EXIT_FAILURE; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 144 | } |
| 145 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 146 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 147 | static int |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 148 | 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] | 149 | { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 150 | struct lyxml_elem *child; |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 151 | const char *value; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 152 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 153 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 154 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 155 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 156 | continue; |
| 157 | } |
| 158 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 159 | if (!strcmp(child->name, "description")) { |
| 160 | if (restr->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 161 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 162 | return EXIT_FAILURE; |
| 163 | } |
| 164 | restr->dsc = read_yin_subnode(ctx, child, "text"); |
| 165 | if (!restr->dsc) { |
| 166 | return EXIT_FAILURE; |
| 167 | } |
| 168 | } else if (!strcmp(child->name, "reference")) { |
| 169 | if (restr->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 170 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 171 | return EXIT_FAILURE; |
| 172 | } |
| 173 | restr->ref = read_yin_subnode(ctx, child, "text"); |
| 174 | if (!restr->ref) { |
| 175 | return EXIT_FAILURE; |
| 176 | } |
| 177 | } else if (!strcmp(child->name, "error-app-tag")) { |
| 178 | if (restr->eapptag) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 179 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 180 | return EXIT_FAILURE; |
| 181 | } |
Michal Vasko | 54e426f | 2015-07-07 15:38:02 +0200 | [diff] [blame] | 182 | GETVAL(value, child, "value"); |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 183 | restr->eapptag = lydict_insert(ctx, value, 0); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 184 | } else if (!strcmp(child->name, "error-message")) { |
| 185 | if (restr->emsg) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 186 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 187 | return EXIT_FAILURE; |
| 188 | } |
| 189 | restr->emsg = read_yin_subnode(ctx, child, "value"); |
| 190 | if (!restr->emsg) { |
| 191 | return EXIT_FAILURE; |
| 192 | } |
| 193 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 194 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 195 | return EXIT_FAILURE; |
| 196 | } |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | return EXIT_SUCCESS; |
Michal Vasko | c8ef47f | 2015-06-29 14:56:19 +0200 | [diff] [blame] | 200 | |
| 201 | error: |
| 202 | return EXIT_FAILURE; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 203 | } |
| 204 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 205 | /* logs directly, returns EXIT_SUCCESS, EXIT_FAILURE, -1 */ |
| 206 | int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 207 | fill_yin_type(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_type *type, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 208 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 209 | { |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 210 | const char *value, *name, *err_ptr; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 211 | struct lyxml_elem *next, *node; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 212 | struct lys_restr **restr; |
| 213 | struct lys_type_bit bit; |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 214 | pcre *precomp; |
| 215 | int i, j, rc, err_offset; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 216 | int64_t v, v_; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 217 | int64_t p, p_; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 218 | |
Radek Krejci | 8de7b0f | 2015-07-02 11:43:42 +0200 | [diff] [blame] | 219 | GETVAL(value, yin, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 220 | value = transform_schema2json(module, value, LOGLINE(yin)); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 221 | if (!value) { |
| 222 | goto error; |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 223 | } |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 224 | |
| 225 | i = parse_identifier(value); |
| 226 | if (i < 1) { |
Michal Vasko | 0160ffe | 2015-10-21 13:25:26 +0200 | [diff] [blame] | 227 | LOGVAL(LYE_INCHAR, LOGLINE(yin), value[-i], &value[-i]); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 228 | lydict_remove(module->ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 229 | goto error; |
| 230 | } |
| 231 | /* module name */ |
| 232 | if (value[i]) { |
| 233 | type->module_name = lydict_insert(module->ctx, value, i); |
| 234 | value += i; |
Michal Vasko | 534f844 | 2015-10-21 13:25:49 +0200 | [diff] [blame] | 235 | if ((value[0] != ':') || (parse_identifier(value + 1) < 1)) { |
Michal Vasko | 0160ffe | 2015-10-21 13:25:26 +0200 | [diff] [blame] | 236 | LOGVAL(LYE_INCHAR, LOGLINE(yin), value[0], value); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 237 | lydict_remove(module->ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 238 | goto error; |
| 239 | } |
Michal Vasko | 534f844 | 2015-10-21 13:25:49 +0200 | [diff] [blame] | 240 | ++value; |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 241 | } |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 242 | |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 243 | rc = resolve_superior_type(value, type->module_name, module, parent, &type->der); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 244 | lydict_remove(module->ctx, value); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 245 | if (rc == -1) { |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 246 | LOGVAL(LYE_INMOD, LOGLINE(yin), type->module_name); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 247 | goto error; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 248 | |
| 249 | /* the type could not be resolved or it was resolved to an unresolved typedef */ |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 250 | } else if (rc == EXIT_FAILURE) { |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 251 | return EXIT_FAILURE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 252 | } |
| 253 | type->base = type->der->type.base; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 254 | |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 255 | /* check status */ |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 256 | if (lyp_check_status(type->parent->flags, type->parent->module, type->parent->name, |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 257 | type->der->flags, type->der->module, type->der->name, LOGLINE(yin))) { |
| 258 | return -1; |
| 259 | } |
| 260 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 261 | switch (type->base) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 262 | case LY_TYPE_BITS: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 263 | /* RFC 6020 9.7.4 - bit */ |
| 264 | |
| 265 | /* get bit specifications, at least one must be present */ |
| 266 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 267 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 268 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 269 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 270 | continue; |
| 271 | } |
| 272 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 273 | if (!strcmp(node->name, "bit")) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 274 | type->info.bits.count++; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 275 | } else { |
Michal Vasko | e29c662 | 2015-11-27 15:02:31 +0100 | [diff] [blame] | 276 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 277 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 278 | } |
| 279 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 280 | if (!type->der->type.der && !type->info.bits.count) { |
| 281 | /* 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] | 282 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "bit", "type"); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 283 | goto error; |
| 284 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 285 | if (type->der->type.der && type->info.bits.count) { |
| 286 | /* 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] | 287 | LOGVAL(LYE_INSTMT, LOGLINE(yin), "bit"); |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 288 | goto error; |
| 289 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 290 | |
| 291 | type->info.bits.bit = calloc(type->info.bits.count, sizeof *type->info.bits.bit); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 292 | if (!type->info.bits.bit) { |
| 293 | LOGMEM; |
| 294 | goto error; |
| 295 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 296 | p = 0; |
| 297 | i = -1; |
| 298 | LY_TREE_FOR(yin->child, next) { |
| 299 | i++; |
| 300 | |
| 301 | GETVAL(value, next, "name"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 302 | if (lyp_check_identifier(value, LY_IDENT_SIMPLE, LOGLINE(next), NULL, NULL)) { |
Michal Vasko | 2d26a02 | 2015-12-07 09:27:21 +0100 | [diff] [blame] | 303 | goto error; |
| 304 | } |
| 305 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 306 | 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] | 307 | 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] | 308 | type->info.bits.count = i + 1; |
| 309 | goto error; |
| 310 | } |
| 311 | |
| 312 | /* check the name uniqueness */ |
| 313 | for (j = 0; j < i; j++) { |
| 314 | 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] | 315 | LOGVAL(LYE_BITS_DUPNAME, LOGLINE(next), type->info.bits.bit[i].name); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 316 | type->info.bits.count = i + 1; |
| 317 | goto error; |
| 318 | } |
| 319 | } |
| 320 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 321 | p_ = -1; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 322 | LY_TREE_FOR(next->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 323 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 324 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 325 | continue; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 326 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 327 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 328 | if (!strcmp(node->name, "position")) { |
| 329 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 330 | p_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 331 | |
| 332 | /* range check */ |
Radek Krejci | b8ca108 | 2015-07-10 11:24:11 +0200 | [diff] [blame] | 333 | if (p_ < 0 || p_ > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 334 | LOGVAL(LYE_INARG, LOGLINE(node), value, "bit/position"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 335 | type->info.bits.count = i + 1; |
| 336 | goto error; |
| 337 | } |
| 338 | type->info.bits.bit[i].pos = (uint32_t)p_; |
| 339 | |
| 340 | /* keep the highest enum value for automatic increment */ |
Michal Vasko | 9ab0594 | 2015-07-07 15:38:26 +0200 | [diff] [blame] | 341 | if (type->info.bits.bit[i].pos >= p) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 342 | p = type->info.bits.bit[i].pos; |
| 343 | p++; |
| 344 | } else { |
| 345 | /* check that the value is unique */ |
| 346 | for (j = 0; j < i; j++) { |
| 347 | 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] | 348 | 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] | 349 | type->info.bits.count = i + 1; |
| 350 | goto error; |
| 351 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 352 | } |
| 353 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 354 | } else { |
Michal Vasko | e29c662 | 2015-11-27 15:02:31 +0100 | [diff] [blame] | 355 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 356 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 357 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 358 | } |
| 359 | if (p_ == -1) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 360 | /* assign value automatically */ |
| 361 | if (p > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 362 | LOGVAL(LYE_INARG, LOGLINE(next), "4294967295", "bit/position"); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 363 | type->info.bits.count = i + 1; |
| 364 | goto error; |
| 365 | } |
| 366 | type->info.bits.bit[i].pos = (uint32_t)p; |
| 367 | p++; |
| 368 | } |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 369 | |
| 370 | /* keep them ordered by position */ |
| 371 | j = i; |
| 372 | while (j && type->info.bits.bit[j - 1].pos > type->info.bits.bit[j].pos) { |
| 373 | /* switch them */ |
| 374 | memcpy(&bit, &type->info.bits.bit[j], sizeof bit); |
| 375 | memcpy(&type->info.bits.bit[j], &type->info.bits.bit[j - 1], sizeof bit); |
| 376 | memcpy(&type->info.bits.bit[j - 1], &bit, sizeof bit); |
| 377 | j--; |
| 378 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 379 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 380 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 381 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 382 | case LY_TYPE_DEC64: |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 383 | /* RFC 6020 9.2.4 - range and 9.3.4 - fraction-digits */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 384 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 385 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 386 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 387 | continue; |
| 388 | } |
| 389 | |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 390 | if (!strcmp(node->name, "range")) { |
| 391 | if (type->info.dec64.range) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 392 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 393 | goto error; |
| 394 | } |
| 395 | |
| 396 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 397 | if (lyp_check_length_range(value, type)) { |
Michal Vasko | 9c1bc64 | 2015-08-05 16:25:53 +0200 | [diff] [blame] | 398 | LOGVAL(LYE_INARG, LOGLINE(node), value, "range"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 399 | goto error; |
| 400 | } |
| 401 | type->info.dec64.range = calloc(1, sizeof *type->info.dec64.range); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 402 | if (!type->info.dec64.range) { |
| 403 | LOGMEM; |
| 404 | goto error; |
| 405 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 406 | type->info.dec64.range->expr = lydict_insert(module->ctx, value, 0); |
| 407 | |
| 408 | /* get possible substatements */ |
| 409 | if (read_restr_substmt(module->ctx, type->info.dec64.range, node)) { |
| 410 | goto error; |
| 411 | } |
| 412 | } else if (!strcmp(node->name, "fraction-digits")) { |
| 413 | if (type->info.dec64.dig) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 414 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 415 | goto error; |
| 416 | } |
| 417 | GETVAL(value, node, "value"); |
| 418 | v = strtol(value, NULL, 10); |
| 419 | |
| 420 | /* range check */ |
| 421 | if (v < 1 || v > 18) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 422 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 423 | goto error; |
| 424 | } |
| 425 | type->info.dec64.dig = (uint8_t)v; |
| 426 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 427 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 428 | goto error; |
| 429 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 430 | } |
| 431 | |
| 432 | /* mandatory sub-statement(s) check */ |
| 433 | if (!type->info.dec64.dig && !type->der->type.der) { |
| 434 | /* decimal64 type directly derived from built-in type requires fraction-digits */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 435 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "fraction-digits", "type"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 436 | goto error; |
| 437 | } |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 438 | if (type->info.dec64.dig && type->der->type.der) { |
| 439 | /* 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] | 440 | LOGVAL(LYE_INSTMT, LOGLINE(yin), "fraction-digits"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 441 | goto error; |
| 442 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 443 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 444 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 445 | case LY_TYPE_ENUM: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 446 | /* RFC 6020 9.6 - enum */ |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 447 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 448 | /* get enum specifications, at least one must be present */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 449 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 450 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 451 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 452 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 453 | continue; |
| 454 | } |
| 455 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 456 | if (!strcmp(node->name, "enum")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 457 | type->info.enums.count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 458 | } else { |
Michal Vasko | e29c662 | 2015-11-27 15:02:31 +0100 | [diff] [blame] | 459 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 460 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 461 | } |
| 462 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 463 | if (!type->der->type.der && !type->info.enums.count) { |
| 464 | /* 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] | 465 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "enum", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 466 | goto error; |
| 467 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 468 | if (type->der->type.der && type->info.enums.count) { |
| 469 | /* 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] | 470 | LOGVAL(LYE_INSTMT, LOGLINE(yin), "enum"); |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 471 | goto error; |
| 472 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 473 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 474 | type->info.enums.enm = calloc(type->info.enums.count, sizeof *type->info.enums.enm); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 475 | if (!type->info.enums.enm) { |
| 476 | LOGMEM; |
| 477 | goto error; |
| 478 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 479 | v = 0; |
| 480 | i = -1; |
| 481 | LY_TREE_FOR(yin->child, next) { |
| 482 | i++; |
| 483 | |
| 484 | GETVAL(value, next, "name"); |
Michal Vasko | 0fb58e9 | 2015-12-07 09:27:44 +0100 | [diff] [blame] | 485 | if (!value[0]) { |
| 486 | LOGVAL(LYE_SPEC, LOGLINE(next), "Enum name must not be empty."); |
| 487 | goto error; |
| 488 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 489 | 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] | 490 | 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] | 491 | type->info.enums.count = i + 1; |
| 492 | goto error; |
| 493 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 494 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 495 | /* the assigned name MUST NOT have any leading or trailing whitespace characters */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 496 | value = type->info.enums.enm[i].name; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 497 | if (isspace(value[0]) || isspace(value[strlen(value) - 1])) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 498 | LOGVAL(LYE_ENUM_WS, LOGLINE(next), value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 499 | type->info.enums.count = i + 1; |
| 500 | goto error; |
| 501 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 502 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 503 | /* check the name uniqueness */ |
| 504 | for (j = 0; j < i; j++) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 505 | 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] | 506 | LOGVAL(LYE_ENUM_DUPNAME, LOGLINE(next), type->info.enums.enm[i].name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 507 | type->info.enums.count = i + 1; |
| 508 | goto error; |
| 509 | } |
| 510 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 511 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 512 | v_ = -1; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 513 | LY_TREE_FOR(next->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 514 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 515 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 516 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 517 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 518 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 519 | if (!strcmp(node->name, "value")) { |
| 520 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 521 | v_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 522 | |
| 523 | /* range check */ |
| 524 | if (v_ < INT32_MIN || v_ > INT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 525 | LOGVAL(LYE_INARG, LOGLINE(node), value, "enum/value"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 526 | type->info.enums.count = i + 1; |
| 527 | goto error; |
| 528 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 529 | type->info.enums.enm[i].value = v_; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 530 | |
| 531 | /* keep the highest enum value for automatic increment */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 532 | if (type->info.enums.enm[i].value > v) { |
| 533 | v = type->info.enums.enm[i].value; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 534 | v++; |
| 535 | } else { |
| 536 | /* check that the value is unique */ |
| 537 | for (j = 0; j < i; j++) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 538 | 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] | 539 | LOGVAL(LYE_ENUM_DUPVAL, LOGLINE(node), type->info.enums.enm[i].value, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 540 | type->info.enums.enm[i].name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 541 | type->info.enums.count = i + 1; |
| 542 | goto error; |
| 543 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 544 | } |
| 545 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 546 | } else { |
Michal Vasko | e29c662 | 2015-11-27 15:02:31 +0100 | [diff] [blame] | 547 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 548 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 549 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 550 | } |
| 551 | if (v_ == -1) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 552 | /* assign value automatically */ |
| 553 | if (v > INT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 554 | LOGVAL(LYE_INARG, LOGLINE(next), "2147483648", "enum/value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 555 | type->info.enums.count = i + 1; |
| 556 | goto error; |
| 557 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 558 | type->info.enums.enm[i].value = v; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 559 | v++; |
| 560 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 561 | } |
| 562 | break; |
| 563 | |
| 564 | case LY_TYPE_IDENT: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 565 | /* RFC 6020 9.10 - base */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 566 | |
| 567 | /* get base specification, exactly one must be present */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 568 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 569 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 570 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 571 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 572 | continue; |
| 573 | } |
| 574 | |
Michal Vasko | e29c662 | 2015-11-27 15:02:31 +0100 | [diff] [blame] | 575 | if (strcmp(node->name, "base")) { |
| 576 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 577 | goto error; |
| 578 | } |
| 579 | } |
| 580 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 581 | if (!yin->child) { |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 582 | if (type->der->type.der) { |
| 583 | /* this is just a derived type with no base specified/required */ |
| 584 | break; |
| 585 | } |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 586 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "base", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 587 | goto error; |
| 588 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 589 | if (yin->child->next) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 590 | 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] | 591 | goto error; |
| 592 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 593 | GETVAL(value, yin->child, "name"); |
Michal Vasko | bdfb1e0 | 2016-02-05 13:15:11 +0100 | [diff] [blame^] | 594 | /* store in the JSON format */ |
| 595 | value = transform_schema2json(module, value, LOGLINE(yin->child)); |
| 596 | if (!value) { |
| 597 | goto error; |
| 598 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 599 | if (unres_schema_add_str(module, unres, type, UNRES_TYPE_IDENTREF, value, LOGLINE(yin->child)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 600 | goto error; |
| 601 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 602 | break; |
| 603 | |
| 604 | case LY_TYPE_INST: |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 605 | /* RFC 6020 9.13.2 - require-instance */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 606 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 607 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 608 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 609 | continue; |
| 610 | } |
| 611 | |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 612 | if (!strcmp(node->name, "require-instance")) { |
| 613 | if (type->info.inst.req) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 614 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 615 | goto error; |
| 616 | } |
| 617 | GETVAL(value, node, "value"); |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 618 | if (!strcmp(value, "true")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 619 | type->info.inst.req = 1; |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 620 | } else if (!strcmp(value, "false")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 621 | type->info.inst.req = -1; |
| 622 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 623 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 624 | goto error; |
| 625 | } |
| 626 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 627 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 628 | goto error; |
| 629 | } |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 630 | } |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 631 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 632 | break; |
| 633 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 634 | case LY_TYPE_BINARY: |
| 635 | /* 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] | 636 | case LY_TYPE_INT8: |
| 637 | case LY_TYPE_INT16: |
| 638 | case LY_TYPE_INT32: |
| 639 | case LY_TYPE_INT64: |
| 640 | case LY_TYPE_UINT8: |
| 641 | case LY_TYPE_UINT16: |
| 642 | case LY_TYPE_UINT32: |
| 643 | case LY_TYPE_UINT64: |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 644 | /* RFC 6020 9.2.4 - range */ |
| 645 | |
| 646 | /* length and range are actually the same restriction, so process |
| 647 | * them by this common code, we just need to differ the name and |
| 648 | * structure where the information will be stored |
| 649 | */ |
| 650 | if (type->base == LY_TYPE_BINARY) { |
| 651 | restr = &type->info.binary.length; |
| 652 | name = "length"; |
| 653 | } else { |
| 654 | restr = &type->info.num.range; |
| 655 | name = "range"; |
| 656 | } |
| 657 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 658 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 659 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 660 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 661 | continue; |
| 662 | } |
| 663 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 664 | if (!strcmp(node->name, name)) { |
| 665 | if (*restr) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 666 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 667 | goto error; |
| 668 | } |
| 669 | |
| 670 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 671 | if (lyp_check_length_range(value, type)) { |
Michal Vasko | 9c1bc64 | 2015-08-05 16:25:53 +0200 | [diff] [blame] | 672 | LOGVAL(LYE_INARG, LOGLINE(node), value, name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 673 | goto error; |
| 674 | } |
| 675 | *restr = calloc(1, sizeof **restr); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 676 | if (!(*restr)) { |
| 677 | LOGMEM; |
| 678 | goto error; |
| 679 | } |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 680 | (*restr)->expr = lydict_insert(module->ctx, value, 0); |
| 681 | |
| 682 | /* get possible substatements */ |
| 683 | if (read_restr_substmt(module->ctx, *restr, node)) { |
| 684 | goto error; |
| 685 | } |
| 686 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 687 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 688 | goto error; |
| 689 | } |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 690 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 691 | break; |
| 692 | |
| 693 | case LY_TYPE_LEAFREF: |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 694 | /* RFC 6020 9.9.2 - path */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 695 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 696 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 697 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 698 | continue; |
| 699 | } |
| 700 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 701 | if (!strcmp(node->name, "path") && !type->der->type.der) { |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 702 | if (type->info.lref.path) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 703 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 704 | goto error; |
| 705 | } |
| 706 | |
| 707 | GETVAL(value, node, "value"); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 708 | /* store in the JSON format */ |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 709 | type->info.lref.path = transform_schema2json(module, value, LOGLINE(node)); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 710 | if (!type->info.lref.path) { |
| 711 | goto error; |
| 712 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 713 | if (unres_schema_add_node(module, unres, type, UNRES_TYPE_LEAFREF, parent, LOGLINE(yin)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 714 | goto error; |
| 715 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 716 | |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 717 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 718 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 719 | goto error; |
| 720 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 721 | } |
| 722 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 723 | if (!type->info.lref.path && !type->der->type.der) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 724 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "path", "type"); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 725 | goto error; |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 726 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 727 | break; |
| 728 | |
| 729 | case LY_TYPE_STRING: |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 730 | /* RFC 6020 9.4.4 - length */ |
| 731 | /* RFC 6020 9.4.6 - pattern */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 732 | i = 0; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 733 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 734 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 735 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 736 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 737 | continue; |
| 738 | } |
| 739 | |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 740 | if (!strcmp(node->name, "length")) { |
| 741 | if (type->info.str.length) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 742 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 743 | goto error; |
| 744 | } |
| 745 | |
| 746 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 747 | if (lyp_check_length_range(value, type)) { |
Michal Vasko | 9c1bc64 | 2015-08-05 16:25:53 +0200 | [diff] [blame] | 748 | LOGVAL(LYE_INARG, LOGLINE(node), value, "length"); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 749 | goto error; |
| 750 | } |
| 751 | type->info.str.length = calloc(1, sizeof *type->info.str.length); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 752 | if (!type->info.str.length) { |
| 753 | LOGMEM; |
| 754 | goto error; |
| 755 | } |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 756 | type->info.str.length->expr = lydict_insert(module->ctx, value, 0); |
| 757 | |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 758 | /* get possible sub-statements */ |
| 759 | if (read_restr_substmt(module->ctx, type->info.str.length, node)) { |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 760 | goto error; |
| 761 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 762 | lyxml_free(module->ctx, node); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 763 | } else if (!strcmp(node->name, "pattern")) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 764 | i++; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 765 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 766 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 767 | goto error; |
| 768 | } |
| 769 | } |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 770 | /* store patterns in array */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 771 | if (i) { |
| 772 | type->info.str.patterns = calloc(i, sizeof *type->info.str.patterns); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 773 | if (!type->info.str.patterns) { |
| 774 | LOGMEM; |
| 775 | goto error; |
| 776 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 777 | LY_TREE_FOR(yin->child, node) { |
Michal Vasko | 5b64da2 | 2015-11-23 15:22:30 +0100 | [diff] [blame] | 778 | GETVAL(value, node, "value"); |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 779 | |
| 780 | /* check that the regex is valid */ |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 781 | precomp = pcre_compile(value, PCRE_NO_AUTO_CAPTURE, &err_ptr, &err_offset, NULL); |
| 782 | if (!precomp) { |
| 783 | LOGVAL(LYE_INREGEX, LOGLINE(node), value, err_ptr); |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 784 | free(type->info.str.patterns); |
| 785 | goto error; |
| 786 | } |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 787 | free(precomp); |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 788 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 789 | 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] | 790 | |
| 791 | /* get possible sub-statements */ |
Michal Vasko | 5b64da2 | 2015-11-23 15:22:30 +0100 | [diff] [blame] | 792 | if (read_restr_substmt(module->ctx, &type->info.str.patterns[type->info.str.pat_count], node)) { |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 793 | free(type->info.str.patterns); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 794 | goto error; |
| 795 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 796 | type->info.str.pat_count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 797 | } |
| 798 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 799 | break; |
| 800 | |
| 801 | case LY_TYPE_UNION: |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 802 | /* RFC 6020 7.4 - type */ |
| 803 | /* count number of types in union */ |
| 804 | i = 0; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 805 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 806 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 807 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 808 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 809 | continue; |
| 810 | } |
| 811 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 812 | if (!strcmp(node->name, "type")) { |
| 813 | i++; |
| 814 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 815 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 816 | goto error; |
| 817 | } |
| 818 | } |
| 819 | |
| 820 | if (!i) { |
| 821 | if (type->der->type.der) { |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 822 | /* this is just a derived type with no additional type specified/required */ |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 823 | break; |
| 824 | } |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 825 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", "(union) type"); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 826 | goto error; |
| 827 | } |
| 828 | |
| 829 | /* allocate array for union's types ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 830 | type->info.uni.types = calloc(i, sizeof *type->info.uni.types); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 831 | if (!type->info.uni.types) { |
| 832 | LOGMEM; |
| 833 | goto error; |
| 834 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 835 | /* ... and fill the structures */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 836 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 837 | type->info.uni.types[type->info.uni.count].parent = type->parent; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 838 | rc = fill_yin_type(module, parent, node, &type->info.uni.types[type->info.uni.count], unres); |
| 839 | if (!rc) { |
| 840 | type->info.uni.count++; |
| 841 | |
| 842 | /* union's type cannot be empty or leafref */ |
| 843 | if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_EMPTY) { |
| 844 | LOGVAL(LYE_INARG, LOGLINE(node), "empty", node->name); |
| 845 | rc = -1; |
| 846 | } else if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_LEAFREF) { |
| 847 | LOGVAL(LYE_INARG, LOGLINE(node), "leafref", node->name); |
| 848 | rc = -1; |
| 849 | } |
| 850 | } |
| 851 | if (rc) { |
| 852 | /* even if we got EXIT_FAILURE, throw it all away, too much trouble doing something else */ |
| 853 | for (i = 0; i < type->info.uni.count; ++i) { |
| 854 | lys_type_free(module->ctx, &type->info.uni.types[i]); |
| 855 | } |
| 856 | free(type->info.uni.types); |
| 857 | type->info.uni.types = NULL; |
| 858 | type->info.uni.count = 0; |
| 859 | |
| 860 | if (rc == EXIT_FAILURE) { |
| 861 | return EXIT_FAILURE; |
| 862 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 863 | goto error; |
| 864 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 865 | } |
| 866 | break; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 867 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 868 | case LY_TYPE_BOOL: |
| 869 | case LY_TYPE_EMPTY: |
| 870 | /* no sub-statement allowed */ |
| 871 | LY_TREE_FOR(yin->child, node) { |
| 872 | if (node->ns && !strcmp(node->ns->value, LY_NSYIN)) { |
| 873 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 874 | goto error; |
| 875 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 876 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 877 | break; |
| 878 | |
| 879 | default: |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 880 | LOGINT; |
| 881 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | return EXIT_SUCCESS; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 885 | |
| 886 | error: |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 887 | return -1; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 888 | } |
| 889 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 890 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 891 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 892 | fill_yin_typedef(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_tpdf *tpdf, struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 893 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 894 | const char *value; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 895 | struct lyxml_elem *node, *next; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 896 | int has_type = 0, dflt_line; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 897 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 898 | GETVAL(value, yin, "name"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 899 | if (lyp_check_identifier(value, LY_IDENT_TYPE, LOGLINE(yin), module, parent)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 900 | goto error; |
| 901 | } |
| 902 | tpdf->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 903 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 904 | /* generic part - status, description, reference */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 905 | 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] | 906 | goto error; |
| 907 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 908 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 909 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 910 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 911 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 912 | continue; |
| 913 | } |
| 914 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 915 | if (!strcmp(node->name, "type")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 916 | if (tpdf->type.der || has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 917 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 918 | goto error; |
| 919 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 920 | /* HACK for unres */ |
| 921 | tpdf->type.der = (struct lys_tpdf *)node; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 922 | tpdf->type.parent = tpdf; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 923 | if (unres_schema_add_node(module, unres, &tpdf->type, UNRES_TYPE_DER, parent, LOGLINE(node))) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 924 | goto error; |
| 925 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 926 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 927 | } else if (!strcmp(node->name, "default")) { |
| 928 | if (tpdf->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 929 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 930 | goto error; |
| 931 | } |
| 932 | GETVAL(value, node, "value"); |
| 933 | tpdf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 934 | dflt_line = LOGLINE(node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 935 | } else if (!strcmp(node->name, "units")) { |
| 936 | if (tpdf->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 937 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 938 | goto error; |
| 939 | } |
| 940 | GETVAL(value, node, "name"); |
| 941 | tpdf->units = lydict_insert(module->ctx, value, strlen(value)); |
| 942 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 943 | LOGVAL(LYE_INSTMT, LOGLINE(node), value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 944 | goto error; |
| 945 | } |
| 946 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 947 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 948 | /* check mandatory value */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 949 | if (!has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 950 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 951 | goto error; |
| 952 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 953 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 954 | /* check default value */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 955 | if (tpdf->dflt) { |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 956 | if (unres_schema_add_str(module, unres, &tpdf->type, UNRES_TYPE_DFLT, tpdf->dflt, dflt_line) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 957 | goto error; |
| 958 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 959 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 960 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 961 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 962 | |
| 963 | error: |
| 964 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 965 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 966 | } |
| 967 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 968 | /* logs directly */ |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 969 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 970 | fill_yin_feature(struct lys_module *module, struct lyxml_elem *yin, struct lys_feature *f, struct unres_schema *unres) |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 971 | { |
| 972 | const char *value; |
| 973 | struct lyxml_elem *child, *next; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 974 | int c = 0, ret; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 975 | |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 976 | GETVAL(value, yin, "name"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 977 | if (lyp_check_identifier(value, LY_IDENT_FEATURE, LOGLINE(yin), module, NULL)) { |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 978 | goto error; |
| 979 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 980 | f->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 981 | f->module = module; |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 982 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 983 | if (read_yin_common(module, NULL, (struct lys_node *)f, yin, 0)) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 984 | goto error; |
| 985 | } |
| 986 | |
| 987 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 988 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 989 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 990 | lyxml_free(module->ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 991 | continue; |
| 992 | } |
| 993 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 994 | if (!strcmp(child->name, "if-feature")) { |
| 995 | c++; |
| 996 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 997 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 998 | goto error; |
| 999 | } |
| 1000 | } |
| 1001 | |
| 1002 | if (c) { |
| 1003 | f->features = calloc(c, sizeof *f->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1004 | if (!f->features) { |
| 1005 | LOGMEM; |
| 1006 | goto error; |
| 1007 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1008 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1009 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1010 | GETVAL(value, child, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 1011 | if (!(value = transform_schema2json(module, value, LOGLINE(child)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 1012 | goto error; |
| 1013 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 1014 | /* hack - store pointer to the parent node for later status check */ |
| 1015 | f->features[f->features_size] = f; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 1016 | ret = unres_schema_add_str(module, unres, &f->features[f->features_size], UNRES_IFFEAT, value, |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 1017 | LOGLINE(child)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 1018 | f->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 1019 | lydict_remove(module->ctx, value); |
| 1020 | if (ret == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1021 | goto error; |
| 1022 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1023 | } |
| 1024 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1025 | return EXIT_SUCCESS; |
| 1026 | |
| 1027 | error: |
| 1028 | |
| 1029 | return EXIT_FAILURE; |
| 1030 | } |
| 1031 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1032 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1033 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1034 | 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] | 1035 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1036 | const char *value; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1037 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1038 | GETVAL(value, yin, "condition"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 1039 | must->expr = transform_schema2json(module, value, LOGLINE(yin)); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 1040 | if (!must->expr) { |
| 1041 | goto error; |
| 1042 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1043 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 1044 | return read_restr_substmt(module->ctx, must, yin); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1045 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 1046 | error: /* GETVAL requires this label */ |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1047 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1048 | return EXIT_FAILURE; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1049 | } |
| 1050 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1051 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1052 | fill_yin_unique(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_unique *unique, |
| 1053 | struct unres_schema *unres) |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1054 | { |
| 1055 | int i, j; |
| 1056 | const char *value, *vaux; |
| 1057 | |
| 1058 | /* get unique value (list of leafs supposed to be unique */ |
| 1059 | GETVAL(value, yin, "tag"); |
| 1060 | |
| 1061 | /* count the number of unique leafs in the value */ |
| 1062 | vaux = value; |
| 1063 | while ((vaux = strpbrk(vaux, " \t\n"))) { |
| 1064 | unique->expr_size++; |
| 1065 | while (isspace(*vaux)) { |
| 1066 | vaux++; |
| 1067 | } |
| 1068 | } |
| 1069 | unique->expr_size++; |
| 1070 | unique->expr = calloc(unique->expr_size, sizeof *unique->expr); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1071 | if (!unique->expr) { |
| 1072 | LOGMEM; |
| 1073 | goto error; |
| 1074 | } |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1075 | |
| 1076 | for (i = 0; i < unique->expr_size; i++) { |
| 1077 | vaux = strpbrk(value, " \t\n"); |
| 1078 | if (!vaux) { |
| 1079 | /* the last token, lydict_insert() will count its size on its own */ |
| 1080 | vaux = value; |
| 1081 | } |
| 1082 | |
| 1083 | /* store token into unique structure */ |
| 1084 | unique->expr[i] = lydict_insert(module->ctx, value, vaux - value); |
| 1085 | |
| 1086 | /* check that the expression does not repeat */ |
| 1087 | for (j = 0; j < i; j++) { |
| 1088 | if (unique->expr[j] == unique->expr[i]) { |
| 1089 | LOGVAL(LYE_INARG, LOGLINE(yin), unique->expr[i], "unique"); |
| 1090 | LOGVAL(LYE_SPEC, 0, "The identifier is not unique"); |
| 1091 | goto error; |
| 1092 | } |
| 1093 | } |
| 1094 | |
| 1095 | /* try to resolve leaf */ |
| 1096 | if (unres) { |
| 1097 | unres_schema_add_str(module, unres, parent, UNRES_LIST_UNIQ, unique->expr[i], LOGLINE(yin)); |
| 1098 | } else { |
| 1099 | if (resolve_unique(parent, value, 0, LOGLINE(yin))) { |
| 1100 | goto error; |
| 1101 | } |
| 1102 | } |
| 1103 | |
| 1104 | /* move to next token */ |
| 1105 | value = vaux; |
| 1106 | while(isspace(*value)) { |
| 1107 | value++; |
| 1108 | } |
| 1109 | } |
| 1110 | |
| 1111 | return EXIT_SUCCESS; |
| 1112 | |
| 1113 | error: |
| 1114 | return EXIT_FAILURE; |
| 1115 | } |
| 1116 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1117 | /* logs directly |
| 1118 | * |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1119 | * type: 0 - min, 1 - max |
| 1120 | */ |
| 1121 | static int |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1122 | 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] | 1123 | { |
| 1124 | const char *value; |
| 1125 | char *endptr; |
| 1126 | unsigned long val; |
| 1127 | uint32_t *ui32val; |
| 1128 | |
| 1129 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1130 | if (target->nodetype == LYS_LEAFLIST) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1131 | if (type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1132 | ui32val = &((struct lys_node_leaflist *)target)->max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1133 | } else { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1134 | ui32val = &((struct lys_node_leaflist *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1135 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1136 | } else if (target->nodetype == LYS_LIST) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1137 | if (type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1138 | ui32val = &((struct lys_node_list *)target)->max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1139 | } else { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1140 | ui32val = &((struct lys_node_list *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1141 | } |
| 1142 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1143 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
| 1144 | 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] | 1145 | goto error; |
| 1146 | } |
| 1147 | |
| 1148 | GETVAL(value, node, "value"); |
| 1149 | while (isspace(value[0])) { |
| 1150 | value++; |
| 1151 | } |
| 1152 | |
| 1153 | /* convert it to uint32_t */ |
| 1154 | errno = 0; |
| 1155 | endptr = NULL; |
| 1156 | val = strtoul(value, &endptr, 10); |
| 1157 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1158 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1159 | goto error; |
| 1160 | } |
| 1161 | if (type) { |
| 1162 | d->max = (uint32_t)val; |
| 1163 | } else { |
| 1164 | d->min = (uint32_t)val; |
| 1165 | } |
| 1166 | |
| 1167 | if (d->mod == LY_DEVIATE_ADD) { |
| 1168 | /* check that there is no current value */ |
| 1169 | if (*ui32val) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1170 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
| 1171 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1172 | goto error; |
| 1173 | } |
| 1174 | } |
| 1175 | |
| 1176 | if (d->mod == LY_DEVIATE_DEL) { |
| 1177 | /* check values */ |
| 1178 | if ((uint32_t)val != *ui32val) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1179 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
| 1180 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1181 | goto error; |
| 1182 | } |
| 1183 | /* remove current min-elements value of the target */ |
| 1184 | *ui32val = 0; |
| 1185 | } else { /* add (already checked) and replace */ |
| 1186 | /* set new value specified in deviation */ |
| 1187 | *ui32val = (uint32_t)val; |
| 1188 | } |
| 1189 | |
| 1190 | return EXIT_SUCCESS; |
| 1191 | |
| 1192 | error: |
| 1193 | |
| 1194 | return EXIT_FAILURE; |
| 1195 | } |
| 1196 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1197 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1198 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1199 | fill_yin_deviation(struct lys_module *module, struct lyxml_elem *yin, struct lys_deviation *dev, |
| 1200 | struct unres_schema *unres) |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1201 | { |
| 1202 | const char *value, **stritem; |
| 1203 | struct lyxml_elem *next, *child, *develem; |
| 1204 | int c_dev = 0, c_must, c_uniq; |
| 1205 | int f_min = 0; /* flags */ |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1206 | int i, j, k, rc; |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1207 | struct lys_deviate *d = NULL; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1208 | struct lys_node *node = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1209 | struct lys_node_choice *choice = NULL; |
| 1210 | struct lys_node_leaf *leaf = NULL; |
| 1211 | struct lys_node_list *list = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1212 | struct lys_type *t = NULL; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1213 | uint8_t *trg_must_size = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1214 | struct lys_restr **trg_must = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1215 | |
| 1216 | GETVAL(value, yin, "target-node"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 1217 | dev->target_name = transform_schema2json(module, value, LOGLINE(yin)); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 1218 | if (!dev->target_name) { |
| 1219 | goto error; |
| 1220 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1221 | |
| 1222 | /* resolve target node */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 1223 | rc = resolve_schema_nodeid(dev->target_name, NULL, module, LYS_AUGMENT, (const struct lys_node **)&dev->target); |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1224 | if (rc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1225 | LOGVAL(LYE_INARG, LOGLINE(yin), dev->target_name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1226 | goto error; |
| 1227 | } |
| 1228 | if (dev->target->module == module) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1229 | LOGVAL(LYE_SPEC, LOGLINE(yin), "Deviating own module is not allowed."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1230 | goto error; |
| 1231 | } |
| 1232 | /* mark the target module as deviated */ |
| 1233 | dev->target->module->deviated = 1; |
| 1234 | |
| 1235 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1236 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1237 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1238 | lyxml_free(module->ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1239 | continue; |
| 1240 | } |
| 1241 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1242 | if (!strcmp(child->name, "description")) { |
| 1243 | if (dev->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1244 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1245 | goto error; |
| 1246 | } |
| 1247 | dev->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 1248 | if (!dev->dsc) { |
| 1249 | goto error; |
| 1250 | } |
| 1251 | } else if (!strcmp(child->name, "reference")) { |
| 1252 | if (dev->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1253 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1254 | goto error; |
| 1255 | } |
| 1256 | dev->ref = read_yin_subnode(module->ctx, child, "text"); |
| 1257 | if (!dev->ref) { |
| 1258 | goto error; |
| 1259 | } |
| 1260 | } else if (!strcmp(child->name, "deviate")) { |
| 1261 | c_dev++; |
| 1262 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1263 | /* skip lyxml_free() at the end of the loop, node will be |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1264 | * further processed later |
| 1265 | */ |
| 1266 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 1267 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1268 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1269 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1270 | goto error; |
| 1271 | } |
| 1272 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1273 | lyxml_free(module->ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1274 | } |
| 1275 | |
| 1276 | if (c_dev) { |
| 1277 | dev->deviate = calloc(c_dev, sizeof *dev->deviate); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1278 | if (!dev->deviate) { |
| 1279 | LOGMEM; |
| 1280 | goto error; |
| 1281 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | LY_TREE_FOR(yin->child, develem) { |
| 1285 | /* init */ |
| 1286 | f_min = 0; |
| 1287 | c_must = 0; |
| 1288 | c_uniq = 0; |
| 1289 | |
| 1290 | /* get deviation type */ |
| 1291 | GETVAL(value, develem, "value"); |
| 1292 | if (!strcmp(value, "not-supported")) { |
| 1293 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_NO; |
| 1294 | /* no property expected in this case */ |
| 1295 | if (develem->child) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1296 | LOGVAL(LYE_INSTMT, LOGLINE(develem->child), develem->child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1297 | goto error; |
| 1298 | } |
| 1299 | |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1300 | /* and neither any other deviate statement is expected, |
| 1301 | * not-supported deviation must be the only deviation of the target |
| 1302 | */ |
| 1303 | if (dev->deviate_size || develem->next) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1304 | LOGVAL(LYE_INARG, LOGLINE(develem), value, develem->name); |
| 1305 | 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] | 1306 | goto error; |
| 1307 | } |
| 1308 | |
| 1309 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1310 | /* remove target node */ |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 1311 | lys_node_free(dev->target, NULL); |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1312 | dev->target = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1313 | |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1314 | dev->deviate_size = 1; |
| 1315 | return EXIT_SUCCESS; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1316 | } else if (!strcmp(value, "add")) { |
| 1317 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_ADD; |
| 1318 | } else if (!strcmp(value, "replace")) { |
| 1319 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_RPL; |
| 1320 | } else if (!strcmp(value, "delete")) { |
| 1321 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_DEL; |
| 1322 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1323 | LOGVAL(LYE_INARG, LOGLINE(develem), value, develem->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1324 | goto error; |
| 1325 | } |
| 1326 | d = &dev->deviate[dev->deviate_size]; |
| 1327 | |
| 1328 | /* process deviation properties */ |
| 1329 | LY_TREE_FOR_SAFE(develem->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1330 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1331 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1332 | lyxml_free(module->ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1333 | continue; |
| 1334 | } |
| 1335 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1336 | if (!strcmp(child->name, "config")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1337 | if (d->flags & LYS_CONFIG_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1338 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1339 | goto error; |
| 1340 | } |
| 1341 | |
| 1342 | /* for we deviate from RFC 6020 and allow config property even it is/is not |
| 1343 | * specified in the target explicitly since config property inherits. So we expect |
| 1344 | * that config is specified in every node. But for delete, we check that the value |
| 1345 | * is the same as here in deviation |
| 1346 | */ |
| 1347 | GETVAL(value, child, "value"); |
| 1348 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1349 | d->flags |= LYS_CONFIG_R; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1350 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1351 | d->flags |= LYS_CONFIG_W; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1352 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1353 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1354 | goto error; |
| 1355 | } |
| 1356 | |
| 1357 | if (d->mod == LY_DEVIATE_DEL) { |
| 1358 | /* check values */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1359 | if ((d->flags & LYS_CONFIG_MASK) != (dev->target->flags & LYS_CONFIG_MASK)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1360 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1361 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1362 | goto error; |
| 1363 | } |
| 1364 | /* remove current config value of the target ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1365 | dev->target->flags &= ~LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1366 | |
| 1367 | /* ... and inherit config value from the target's parent */ |
| 1368 | if (dev->target->parent) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1369 | dev->target->flags |= dev->target->parent->flags & LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1370 | } else { |
| 1371 | /* default config is true */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1372 | dev->target->flags |= LYS_CONFIG_W; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1373 | } |
| 1374 | } else { /* add and replace are the same in this case */ |
| 1375 | /* remove current config value of the target ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1376 | dev->target->flags &= ~LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1377 | |
| 1378 | /* ... and replace it with the value specified in deviation */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1379 | dev->target->flags |= d->flags & LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1380 | } |
| 1381 | } else if (!strcmp(child->name, "default")) { |
| 1382 | if (d->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1383 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1384 | goto error; |
| 1385 | } |
| 1386 | GETVAL(value, child, "value"); |
| 1387 | d->dflt = lydict_insert(module->ctx, value, 0); |
| 1388 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1389 | if (dev->target->nodetype == LYS_CHOICE) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1390 | choice = (struct lys_node_choice *)dev->target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1391 | |
| 1392 | if (d->mod == LY_DEVIATE_ADD) { |
| 1393 | /* check that there is no current value */ |
| 1394 | if (choice->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1395 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1396 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1397 | goto error; |
| 1398 | } |
| 1399 | } |
| 1400 | |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 1401 | rc = resolve_schema_nodeid(d->dflt, choice->child, choice->module, LYS_CHOICE, |
| 1402 | (const struct lys_node **)&node); |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1403 | if (rc) { |
| 1404 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1405 | goto error; |
| 1406 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1407 | if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1408 | if (!choice->dflt || choice->dflt != node) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1409 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1410 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1411 | goto error; |
| 1412 | } |
| 1413 | } else { /* add (already checked) and replace */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1414 | choice->dflt = node; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1415 | if (!choice->dflt) { |
| 1416 | /* default branch not found */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1417 | LOGVAL(LYE_INARG, LOGLINE(yin), value, "default"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1418 | goto error; |
| 1419 | } |
| 1420 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1421 | } else if (dev->target->nodetype == LYS_LEAF) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1422 | leaf = (struct lys_node_leaf *)dev->target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1423 | |
| 1424 | if (d->mod == LY_DEVIATE_ADD) { |
| 1425 | /* check that there is no current value */ |
| 1426 | if (leaf->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1427 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1428 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1429 | goto error; |
| 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | if (d->mod == LY_DEVIATE_DEL) { |
| 1434 | if (!leaf->dflt || leaf->dflt != d->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1435 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1436 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1437 | goto error; |
| 1438 | } |
| 1439 | /* remove value */ |
| 1440 | lydict_remove(leaf->module->ctx, leaf->dflt); |
| 1441 | leaf->dflt = NULL; |
| 1442 | } else { /* add (already checked) and replace */ |
| 1443 | /* remove value */ |
| 1444 | lydict_remove(leaf->module->ctx, leaf->dflt); |
| 1445 | |
| 1446 | /* set new value */ |
| 1447 | leaf->dflt = lydict_insert(leaf->module->ctx, d->dflt, 0); |
| 1448 | } |
| 1449 | } else { |
| 1450 | /* invalid target for default value */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1451 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1452 | 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] | 1453 | goto error; |
| 1454 | } |
| 1455 | } else if (!strcmp(child->name, "mandatory")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1456 | if (d->flags & LYS_MAND_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1457 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1458 | goto error; |
| 1459 | } |
| 1460 | |
| 1461 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1462 | if (!(dev->target->nodetype &= (LYS_LEAF | LYS_CHOICE | LYS_ANYXML))) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1463 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1464 | 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] | 1465 | goto error; |
| 1466 | } |
| 1467 | |
| 1468 | GETVAL(value, child, "value"); |
| 1469 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1470 | d->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1471 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1472 | d->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1473 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1474 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1475 | goto error; |
| 1476 | } |
| 1477 | |
| 1478 | if (d->mod == LY_DEVIATE_ADD) { |
| 1479 | /* check that there is no current value */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1480 | if (dev->target->flags & LYS_MAND_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1481 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1482 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1483 | goto error; |
| 1484 | } |
| 1485 | } |
| 1486 | |
| 1487 | if (d->mod == LY_DEVIATE_DEL) { |
| 1488 | /* check values */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1489 | if ((d->flags & LYS_MAND_MASK) != (dev->target->flags & LYS_MAND_MASK)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1490 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1491 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1492 | goto error; |
| 1493 | } |
| 1494 | /* remove current mandatory value of the target */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1495 | dev->target->flags &= ~LYS_MAND_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1496 | } else { /* add (already checked) and replace */ |
| 1497 | /* remove current mandatory value of the target ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1498 | dev->target->flags &= ~LYS_MAND_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1499 | |
| 1500 | /* ... and replace it with the value specified in deviation */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1501 | dev->target->flags |= d->flags & LYS_MAND_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1502 | } |
| 1503 | } else if (!strcmp(child->name, "min-elements")) { |
| 1504 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1505 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1506 | goto error; |
| 1507 | } |
| 1508 | f_min = 1; |
| 1509 | |
| 1510 | if (deviate_minmax(dev->target, child, d, 0)) { |
| 1511 | goto error; |
| 1512 | } |
| 1513 | } else if (!strcmp(child->name, "max-elements")) { |
| 1514 | if (d->max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1515 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1516 | goto error; |
| 1517 | } |
| 1518 | |
| 1519 | if (deviate_minmax(dev->target, child, d, 1)) { |
| 1520 | goto error; |
| 1521 | } |
| 1522 | } else if (!strcmp(child->name, "must")) { |
| 1523 | c_must++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1524 | /* skip lyxml_free() at the end of the loop, this node will be processed later */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1525 | continue; |
| 1526 | } else if (!strcmp(child->name, "type")) { |
| 1527 | if (d->type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1528 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1529 | goto error; |
| 1530 | } |
| 1531 | |
| 1532 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1533 | if (dev->target->nodetype == LYS_LEAF) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1534 | t = &((struct lys_node_leaf *)dev->target)->type; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1535 | } else if (dev->target->nodetype == LYS_LEAFLIST) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1536 | t = &((struct lys_node_leaflist *)dev->target)->type; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1537 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1538 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1539 | 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] | 1540 | goto error; |
| 1541 | } |
| 1542 | |
| 1543 | if (d->mod == LY_DEVIATE_ADD) { |
| 1544 | /* not allowed, type is always present at the target */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1545 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1546 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1547 | goto error; |
| 1548 | } else if (d->mod == LY_DEVIATE_DEL) { |
| 1549 | /* not allowed, type cannot be deleted from the target */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1550 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1551 | LOGVAL(LYE_SPEC, 0, "Deleteing type from the target is not allowed."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1552 | goto error; |
| 1553 | } |
| 1554 | |
| 1555 | /* replace */ |
| 1556 | /* remove current units value of the target ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1557 | lys_type_free(dev->target->module->ctx, t); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1558 | |
| 1559 | /* ... and replace it with the value specified in deviation */ |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1560 | /* HACK for unres */ |
| 1561 | t->der = (struct lys_tpdf *)child; |
| 1562 | if (unres_schema_add_node(module, unres, t, UNRES_TYPE_DER, dev->target, LOGLINE(child))) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1563 | goto error; |
| 1564 | } |
| 1565 | d->type = t; |
| 1566 | } else if (!strcmp(child->name, "unique")) { |
| 1567 | c_uniq++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1568 | /* skip lyxml_free() at the end of the loop, this node will be processed later */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1569 | continue; |
| 1570 | } else if (!strcmp(child->name, "units")) { |
| 1571 | if (d->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1572 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1573 | goto error; |
| 1574 | } |
| 1575 | |
| 1576 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1577 | if (dev->target->nodetype == LYS_LEAFLIST) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1578 | stritem = &((struct lys_node_leaflist *)dev->target)->units; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1579 | } else if (dev->target->nodetype == LYS_LEAF) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1580 | stritem = &((struct lys_node_leaf *)dev->target)->units; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1581 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1582 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1583 | LOGVAL(LYE_SPEC, 0, "Target node does not allow \"%s\" property.", child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1584 | goto error; |
| 1585 | } |
| 1586 | |
| 1587 | /* get units value */ |
| 1588 | GETVAL(value, child, "name"); |
| 1589 | d->units = lydict_insert(module->ctx, value, 0); |
| 1590 | |
| 1591 | /* apply to target */ |
| 1592 | if (d->mod == LY_DEVIATE_ADD) { |
| 1593 | /* check that there is no current value */ |
| 1594 | if (*stritem) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1595 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1596 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1597 | goto error; |
| 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | if (d->mod == LY_DEVIATE_DEL) { |
| 1602 | /* check values */ |
| 1603 | if (*stritem != d->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1604 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1605 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1606 | goto error; |
| 1607 | } |
| 1608 | /* remove current units value of the target */ |
| 1609 | lydict_remove(dev->target->module->ctx, *stritem); |
| 1610 | } else { /* add (already checked) and replace */ |
| 1611 | /* remove current units value of the target ... */ |
| 1612 | lydict_remove(dev->target->module->ctx, *stritem); |
| 1613 | |
| 1614 | /* ... and replace it with the value specified in deviation */ |
| 1615 | *stritem = lydict_insert(module->ctx, value, 0); |
| 1616 | } |
| 1617 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1618 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1619 | goto error; |
| 1620 | } |
| 1621 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1622 | /* do not free sub, it could have been unlinked and stored in unres */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1623 | } |
| 1624 | |
| 1625 | if (c_must) { |
| 1626 | /* check target node type */ |
| 1627 | switch (dev->target->nodetype) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1628 | case LYS_LEAF: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1629 | trg_must = &((struct lys_node_leaf *)dev->target)->must; |
| 1630 | trg_must_size = &((struct lys_node_leaf *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1631 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1632 | case LYS_CONTAINER: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1633 | trg_must = &((struct lys_node_container *)dev->target)->must; |
| 1634 | trg_must_size = &((struct lys_node_container *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1635 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1636 | case LYS_LEAFLIST: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1637 | trg_must = &((struct lys_node_leaflist *)dev->target)->must; |
| 1638 | trg_must_size = &((struct lys_node_leaflist *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1639 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1640 | case LYS_LIST: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1641 | trg_must = &((struct lys_node_list *)dev->target)->must; |
| 1642 | trg_must_size = &((struct lys_node_list *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1643 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1644 | case LYS_ANYXML: |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1645 | trg_must = &((struct lys_node_anyxml *)dev->target)->must; |
| 1646 | trg_must_size = &((struct lys_node_anyxml *)dev->target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1647 | break; |
| 1648 | default: |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1649 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1650 | 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] | 1651 | goto error; |
| 1652 | } |
| 1653 | |
| 1654 | if (d->mod == LY_DEVIATE_RPL) { |
| 1655 | /* remove target's musts and allocate new array for it */ |
| 1656 | if (!*trg_must) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1657 | LOGVAL(LYE_INARG, LOGLINE(develem), "replace", "deviate"); |
| 1658 | 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] | 1659 | goto error; |
| 1660 | } |
| 1661 | |
| 1662 | for (i = 0; i < list->must_size; i++) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1663 | lys_restr_free(dev->target->module->ctx, &(*trg_must[i])); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1664 | } |
| 1665 | free(*trg_must); |
| 1666 | *trg_must = d->must = calloc(c_must, sizeof *d->must); |
| 1667 | d->must_size = c_must; |
| 1668 | *trg_must_size = 0; |
| 1669 | } else if (d->mod == LY_DEVIATE_ADD) { |
| 1670 | /* reallocate the must array of the target */ |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1671 | d->must = ly_realloc(*trg_must, (c_must + *trg_must_size) * sizeof *d->must); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1672 | *trg_must = d->must; |
Michal Vasko | 979ad5b | 2015-10-23 10:12:55 +0200 | [diff] [blame] | 1673 | d->must = &((*trg_must)[*trg_must_size]); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1674 | d->must_size = c_must; |
| 1675 | } else { /* LY_DEVIATE_DEL */ |
| 1676 | d->must = calloc(c_must, sizeof *d->must); |
| 1677 | } |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1678 | if (!d->must) { |
| 1679 | LOGMEM; |
| 1680 | goto error; |
| 1681 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1682 | } |
| 1683 | if (c_uniq) { |
| 1684 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1685 | if (dev->target->nodetype != LYS_LIST) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1686 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1687 | 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] | 1688 | goto error; |
| 1689 | } |
| 1690 | |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1691 | list = (struct lys_node_list *)dev->target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1692 | if (d->mod == LY_DEVIATE_RPL) { |
| 1693 | /* remove target's unique and allocate new array for it */ |
| 1694 | if (!list->unique) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1695 | LOGVAL(LYE_INARG, LOGLINE(develem), "replace", "deviate"); |
| 1696 | 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] | 1697 | goto error; |
| 1698 | } |
| 1699 | |
| 1700 | for (i = 0; i < list->unique_size; i++) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1701 | for (j = 0; j < list->unique[i].expr_size; j++) { |
| 1702 | lydict_remove(list->module->ctx, list->unique[i].expr[j]); |
| 1703 | } |
| 1704 | free(list->unique[i].expr); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1705 | } |
| 1706 | free(list->unique); |
| 1707 | list->unique = d->unique = calloc(c_uniq, sizeof *d->unique); |
| 1708 | d->unique_size = c_uniq; |
| 1709 | list->unique_size = 0; |
| 1710 | } else if (d->mod == LY_DEVIATE_ADD) { |
| 1711 | /* reallocate the unique array of the target */ |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1712 | d->unique = ly_realloc(list->unique, (c_uniq + list->unique_size) * sizeof *d->unique); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1713 | list->unique = d->unique; |
| 1714 | d->unique = &list->unique[list->unique_size]; |
| 1715 | d->unique_size = c_uniq; |
| 1716 | } else { /* LY_DEVIATE_DEL */ |
| 1717 | d->unique = calloc(c_uniq, sizeof *d->unique); |
| 1718 | } |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1719 | if (!d->unique) { |
| 1720 | LOGMEM; |
| 1721 | goto error; |
| 1722 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1723 | } |
| 1724 | |
| 1725 | /* process deviation properties with 0..n cardinality */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1726 | LY_TREE_FOR(develem->child, child) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1727 | if (!strcmp(child->name, "must")) { |
| 1728 | if (d->mod == LY_DEVIATE_DEL) { |
| 1729 | if (fill_yin_must(module, child, &d->must[d->must_size])) { |
| 1730 | goto error; |
| 1731 | } |
| 1732 | |
| 1733 | /* find must to delete, we are ok with just matching conditions */ |
| 1734 | for (i = 0; i < *trg_must_size; i++) { |
| 1735 | if (d->must[d->must_size].expr == (*trg_must)[i].expr) { |
| 1736 | /* we have a match, free the must structure ... */ |
Michal Vasko | 5e7d9ca | 2015-10-23 10:37:28 +0200 | [diff] [blame] | 1737 | lys_restr_free(dev->target->module->ctx, &((*trg_must)[i])); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1738 | /* ... and maintain the array */ |
| 1739 | (*trg_must_size)--; |
| 1740 | if (i != *trg_must_size) { |
| 1741 | (*trg_must)[i].expr = (*trg_must)[*trg_must_size].expr; |
| 1742 | (*trg_must)[i].dsc = (*trg_must)[*trg_must_size].dsc; |
| 1743 | (*trg_must)[i].ref = (*trg_must)[*trg_must_size].ref; |
| 1744 | (*trg_must)[i].eapptag = (*trg_must)[*trg_must_size].eapptag; |
| 1745 | (*trg_must)[i].emsg = (*trg_must)[*trg_must_size].emsg; |
| 1746 | } |
| 1747 | if (!(*trg_must_size)) { |
| 1748 | free(*trg_must); |
| 1749 | *trg_must = NULL; |
| 1750 | } else { |
| 1751 | (*trg_must)[*trg_must_size].expr = NULL; |
| 1752 | (*trg_must)[*trg_must_size].dsc = NULL; |
| 1753 | (*trg_must)[*trg_must_size].ref = NULL; |
| 1754 | (*trg_must)[*trg_must_size].eapptag = NULL; |
| 1755 | (*trg_must)[*trg_must_size].emsg = NULL; |
| 1756 | } |
| 1757 | |
| 1758 | i = -1; /* set match flag */ |
| 1759 | break; |
| 1760 | } |
| 1761 | } |
| 1762 | d->must_size++; |
| 1763 | if (i != -1) { |
| 1764 | /* no match found */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1765 | LOGVAL(LYE_INARG, LOGLINE(child), d->must[d->must_size - 1].expr, child->name); |
| 1766 | 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] | 1767 | goto error; |
| 1768 | } |
| 1769 | } else { /* replace or add */ |
| 1770 | if (fill_yin_must(dev->target->module, child, &((*trg_must)[*trg_must_size]))) { |
| 1771 | goto error; |
| 1772 | } |
| 1773 | (*trg_must_size)++; |
| 1774 | } |
| 1775 | } else if (!strcmp(child->name, "unique")) { |
| 1776 | if (d->mod == LY_DEVIATE_DEL) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1777 | if (fill_yin_unique(module, dev->target, child, &d->unique[d->unique_size], NULL)) { |
| 1778 | d->unique_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1779 | goto error; |
| 1780 | } |
| 1781 | |
| 1782 | /* find unique structures to delete */ |
| 1783 | for (i = 0; i < list->unique_size; i++) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1784 | if (list->unique[i].expr_size != d->unique[d->unique_size].expr_size) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1785 | continue; |
| 1786 | } |
| 1787 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1788 | for (j = 0; j < d->unique[d->unique_size].expr_size; j++) { |
| 1789 | if (list->unique[i].expr[j] != d->unique[d->unique_size].expr[j]) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1790 | break; |
| 1791 | } |
| 1792 | } |
| 1793 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1794 | if (j == d->unique[d->unique_size].expr_size) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1795 | /* we have a match, free the unique structure ... */ |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1796 | for (j = 0; j < list->unique[i].expr_size; j++) { |
| 1797 | lydict_remove(list->module->ctx, list->unique[i].expr[j]); |
| 1798 | } |
| 1799 | free(list->unique[i].expr); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1800 | /* ... and maintain the array */ |
| 1801 | list->unique_size--; |
| 1802 | if (i != list->unique_size) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1803 | list->unique[i].expr_size = list->unique[list->unique_size].expr_size; |
| 1804 | list->unique[i].expr = list->unique[list->unique_size].expr; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1805 | } |
| 1806 | |
| 1807 | if (!list->unique_size) { |
| 1808 | free(list->unique); |
| 1809 | list->unique = NULL; |
| 1810 | } else { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1811 | list->unique[list->unique_size].expr_size = 0; |
| 1812 | list->unique[list->unique_size].expr = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1813 | } |
| 1814 | |
| 1815 | i = -1; /* set match flag */ |
| 1816 | break; |
| 1817 | } |
| 1818 | } |
| 1819 | |
| 1820 | d->unique_size++; |
| 1821 | if (i != -1) { |
| 1822 | /* no match found */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1823 | LOGVAL(LYE_INARG, LOGLINE(child), lyxml_get_attr(child, "tag", NULL), child->name); |
| 1824 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1825 | goto error; |
| 1826 | } |
| 1827 | } else { /* replace or add */ |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 1828 | i = fill_yin_unique(module, dev->target, child, &list->unique[list->unique_size], NULL); |
| 1829 | list->unique_size++; |
| 1830 | if (i) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1831 | goto error; |
| 1832 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1833 | } |
| 1834 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1835 | } |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1836 | |
| 1837 | dev->deviate_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1838 | } |
| 1839 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1840 | return EXIT_SUCCESS; |
| 1841 | |
| 1842 | error: |
| 1843 | |
| 1844 | if (dev->deviate) { |
| 1845 | for (i = 0; i < dev->deviate_size; i++) { |
| 1846 | lydict_remove(module->ctx, dev->deviate[i].dflt); |
| 1847 | lydict_remove(module->ctx, dev->deviate[i].units); |
| 1848 | |
| 1849 | if (dev->deviate[i].mod == LY_DEVIATE_DEL) { |
| 1850 | for (j = 0; j < dev->deviate[i].must_size; j++) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1851 | lys_restr_free(module->ctx, &dev->deviate[i].must[j]); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1852 | } |
| 1853 | free(dev->deviate[i].must); |
| 1854 | |
| 1855 | for (j = 0; j < dev->deviate[i].unique_size; j++) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1856 | for (k = 0; k < dev->deviate[i].unique[i].expr_size; k++) { |
| 1857 | lydict_remove(module->ctx, dev->deviate[i].unique[j].expr[k]); |
| 1858 | } |
| 1859 | free(dev->deviate[i].unique[j].expr); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1860 | } |
| 1861 | free(dev->deviate[i].unique); |
| 1862 | } |
| 1863 | } |
| 1864 | free(dev->deviate); |
| 1865 | } |
| 1866 | |
| 1867 | return EXIT_FAILURE; |
| 1868 | } |
| 1869 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1870 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1871 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1872 | fill_yin_augment(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_node_augment *aug, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 1873 | struct unres_schema *unres) |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1874 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1875 | const char *value; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1876 | struct lyxml_elem *child, *next; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1877 | struct lys_node *node; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 1878 | int c = 0, ret; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1879 | |
Michal Vasko | 591e0b2 | 2015-08-13 13:53:43 +0200 | [diff] [blame] | 1880 | aug->nodetype = LYS_AUGMENT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1881 | GETVAL(value, yin, "target-node"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 1882 | aug->target_name = transform_schema2json(module, value, LOGLINE(yin)); |
Michal Vasko | 488c19e | 2015-10-20 15:21:00 +0200 | [diff] [blame] | 1883 | if (!aug->target_name) { |
| 1884 | goto error; |
| 1885 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1886 | aug->parent = parent; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1887 | |
Michal Vasko | 1d87a92 | 2015-08-21 12:57:16 +0200 | [diff] [blame] | 1888 | if (read_yin_common(module, NULL, (struct lys_node *)aug, yin, OPT_MODULE | OPT_NACMEXT)) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1889 | goto error; |
| 1890 | } |
| 1891 | |
| 1892 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1893 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1894 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1895 | lyxml_free(module->ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1896 | continue; |
| 1897 | } |
| 1898 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1899 | if (!strcmp(child->name, "if-feature")) { |
| 1900 | c++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1901 | continue; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1902 | } else if (!strcmp(child->name, "when")) { |
| 1903 | if (aug->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1904 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1905 | goto error; |
| 1906 | } |
| 1907 | |
| 1908 | aug->when = read_yin_when(module, child); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1909 | if (!aug->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1910 | lyxml_free(module->ctx, child); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1911 | goto error; |
| 1912 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 1913 | if (lyxp_syntax_check(aug->when->cond, LOGLINE(child))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1914 | goto error; |
| 1915 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1916 | lyxml_free(module->ctx, child); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1917 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1918 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1919 | /* check allowed data sub-statements */ |
| 1920 | } else if (!strcmp(child->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1921 | node = read_yin_container(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1922 | } else if (!strcmp(child->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1923 | node = read_yin_leaflist(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1924 | } else if (!strcmp(child->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1925 | node = read_yin_leaf(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1926 | } else if (!strcmp(child->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1927 | node = read_yin_list(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1928 | } else if (!strcmp(child->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1929 | node = read_yin_uses(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1930 | } else if (!strcmp(child->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1931 | node = read_yin_case(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1932 | } else if (!strcmp(child->name, "case")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1933 | node = read_yin_case(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1934 | } else if (!strcmp(child->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1935 | node = read_yin_anyxml(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1936 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1937 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1938 | goto error; |
| 1939 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1940 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1941 | if (!node) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1942 | goto error; |
| 1943 | } |
| 1944 | |
| 1945 | /* check for mandatory nodes - if the target node is in another module |
| 1946 | * the added nodes cannot be mandatory |
| 1947 | */ |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 1948 | if ((!parent || (parent->nodetype != LYS_USES)) && lyp_check_mandatory(node)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1949 | 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] | 1950 | goto error; |
| 1951 | } |
| 1952 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1953 | node = NULL; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1954 | lyxml_free(module->ctx, child); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1955 | } |
| 1956 | |
| 1957 | if (c) { |
| 1958 | aug->features = calloc(c, sizeof *aug->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1959 | if (!aug->features) { |
| 1960 | LOGMEM; |
| 1961 | goto error; |
| 1962 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 1966 | if (!strcmp(child->name, "if-feature")) { |
| 1967 | GETVAL(value, child, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 1968 | if (!(value = transform_schema2json(module, value, LOGLINE(child)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 1969 | goto error; |
| 1970 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 1971 | /* hack - store pointer to the parent node for later status check */ |
| 1972 | aug->features[aug->features_size] = (struct lys_feature *)aug; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 1973 | ret = unres_schema_add_str(module, unres, &aug->features[aug->features_size], UNRES_IFFEAT, value, |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 1974 | LOGLINE(child)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 1975 | aug->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 1976 | lydict_remove(module->ctx, value); |
| 1977 | if (ret == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1978 | goto error; |
| 1979 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1980 | lyxml_free(module->ctx, child); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1981 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1982 | } |
| 1983 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1984 | /* aug->child points to the parsed nodes, they must now be |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 1985 | * connected to the tree and adjusted (if possible right now). |
| 1986 | * However, if this is augment in a uses, it gets resolved |
| 1987 | * when the uses does and cannot be resolved now for sure |
| 1988 | * (the grouping was not yet copied into uses). |
| 1989 | */ |
| 1990 | if (!parent || (parent->nodetype != LYS_USES)) { |
Michal Vasko | 1d87a92 | 2015-08-21 12:57:16 +0200 | [diff] [blame] | 1991 | if (resolve_augment(aug, aug->child)) { |
Michal Vasko | 4adc10f | 2015-08-11 15:26:17 +0200 | [diff] [blame] | 1992 | LOGVAL(LYE_INRESOLV, LOGLINE(yin), "augment", aug->target_name); |
| 1993 | goto error; |
| 1994 | } |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 1995 | } |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1996 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1997 | return EXIT_SUCCESS; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1998 | |
| 1999 | error: |
| 2000 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2001 | return EXIT_FAILURE; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 2002 | } |
| 2003 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2004 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2005 | static int |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 2006 | fill_yin_refine(struct lys_module *module, struct lyxml_elem *yin, struct lys_refine *rfn) |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2007 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2008 | struct lyxml_elem *sub, *next; |
| 2009 | const char *value; |
| 2010 | char *endptr; |
| 2011 | int f_mand = 0, f_min = 0, f_max = 0; |
| 2012 | int c_must = 0; |
| 2013 | int r; |
| 2014 | unsigned long int val; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2015 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2016 | 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] | 2017 | goto error; |
| 2018 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2019 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2020 | GETVAL(value, yin, "target-node"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 2021 | rfn->target_name = transform_schema2json(module, value, LOGLINE(yin)); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 2022 | if (!rfn->target_name) { |
| 2023 | goto error; |
| 2024 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2025 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2026 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2027 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2028 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2029 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2030 | continue; |
| 2031 | } |
| 2032 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2033 | /* limited applicability */ |
| 2034 | if (!strcmp(sub->name, "default")) { |
| 2035 | /* leaf or choice */ |
| 2036 | if (rfn->mod.dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2037 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2038 | goto error; |
| 2039 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2040 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2041 | /* check possibility of statements combination */ |
| 2042 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2043 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2044 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2045 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2046 | goto error; |
| 2047 | } |
| 2048 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2049 | rfn->target_type = LYS_LEAF | LYS_CHOICE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2050 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2051 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2052 | GETVAL(value, sub, "value"); |
| 2053 | rfn->mod.dflt = lydict_insert(module->ctx, value, strlen(value)); |
| 2054 | } else if (!strcmp(sub->name, "mandatory")) { |
| 2055 | /* leaf, choice or anyxml */ |
| 2056 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2057 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2058 | goto error; |
| 2059 | } |
| 2060 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2061 | * multiple mandatory statements with the "false" value |
| 2062 | */ |
| 2063 | f_mand = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2064 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2065 | /* check possibility of statements combination */ |
| 2066 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2067 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE | LYS_ANYXML); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2068 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2069 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2070 | goto error; |
| 2071 | } |
| 2072 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2073 | rfn->target_type = LYS_LEAF | LYS_CHOICE | LYS_ANYXML; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2074 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2075 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2076 | GETVAL(value, sub, "value"); |
| 2077 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2078 | rfn->flags |= LYS_MAND_TRUE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2079 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2080 | rfn->flags |= LYS_MAND_FALSE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2081 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2082 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2083 | goto error; |
| 2084 | } |
| 2085 | } else if (!strcmp(sub->name, "min-elements")) { |
| 2086 | /* list or leaf-list */ |
| 2087 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2088 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2089 | goto error; |
| 2090 | } |
| 2091 | f_min = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2092 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2093 | /* check possibility of statements combination */ |
| 2094 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2095 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2096 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2097 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2098 | goto error; |
| 2099 | } |
| 2100 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2101 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2102 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2103 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2104 | GETVAL(value, sub, "value"); |
| 2105 | while (isspace(value[0])) { |
| 2106 | value++; |
| 2107 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2108 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2109 | /* convert it to uint32_t */ |
| 2110 | errno = 0; |
| 2111 | endptr = NULL; |
| 2112 | val = strtoul(value, &endptr, 10); |
| 2113 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2114 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2115 | goto error; |
| 2116 | } |
| 2117 | rfn->mod.list.min = (uint32_t) val; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2118 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2119 | /* magic - bit 3 in flags means min set */ |
| 2120 | rfn->flags |= 0x04; |
| 2121 | } else if (!strcmp(sub->name, "max-elements")) { |
| 2122 | /* list or leaf-list */ |
| 2123 | if (f_max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2124 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2125 | goto error; |
| 2126 | } |
| 2127 | f_max = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2128 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2129 | /* check possibility of statements combination */ |
| 2130 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2131 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2132 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2133 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2134 | goto error; |
| 2135 | } |
| 2136 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2137 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2138 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2139 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2140 | GETVAL(value, sub, "value"); |
| 2141 | while (isspace(value[0])) { |
| 2142 | value++; |
| 2143 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2144 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2145 | /* convert it to uint32_t */ |
| 2146 | errno = 0; |
| 2147 | endptr = NULL; |
| 2148 | val = strtoul(value, &endptr, 10); |
| 2149 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2150 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2151 | goto error; |
| 2152 | } |
| 2153 | rfn->mod.list.max = (uint32_t) val; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2154 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2155 | /* magic - bit 4 in flags means min set */ |
| 2156 | rfn->flags |= 0x08; |
| 2157 | } else if (!strcmp(sub->name, "presence")) { |
| 2158 | /* container */ |
| 2159 | if (rfn->mod.presence) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2160 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2161 | goto error; |
| 2162 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2163 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2164 | /* check possibility of statements combination */ |
| 2165 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2166 | rfn->target_type &= LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2167 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2168 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2169 | goto error; |
| 2170 | } |
| 2171 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2172 | rfn->target_type = LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2173 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2174 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2175 | GETVAL(value, sub, "value"); |
| 2176 | rfn->mod.presence = lydict_insert(module->ctx, value, strlen(value)); |
| 2177 | } else if (!strcmp(sub->name, "must")) { |
| 2178 | /* leaf-list, list, container or anyxml */ |
| 2179 | /* check possibility of statements combination */ |
| 2180 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2181 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST | LYS_CONTAINER | LYS_ANYXML); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2182 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2183 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2184 | goto error; |
| 2185 | } |
| 2186 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2187 | rfn->target_type = LYS_LIST | LYS_LEAFLIST | LYS_CONTAINER | LYS_ANYXML; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2188 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2189 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2190 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 2191 | continue; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2192 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2193 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2194 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2195 | goto error; |
| 2196 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2197 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2198 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2199 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2200 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2201 | /* process nodes with cardinality of 0..n */ |
| 2202 | if (c_must) { |
| 2203 | rfn->must = calloc(c_must, sizeof *rfn->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2204 | if (!rfn->must) { |
| 2205 | LOGMEM; |
| 2206 | goto error; |
| 2207 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2208 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2209 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 2210 | r = fill_yin_must(module, sub, &rfn->must[rfn->must_size]); |
| 2211 | rfn->must_size++; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2212 | if (r) { |
| 2213 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2214 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 2215 | if (lyxp_syntax_check(rfn->must[rfn->must_size-1].expr, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2216 | goto error; |
| 2217 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2218 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2219 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2220 | return EXIT_SUCCESS; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2221 | |
| 2222 | error: |
| 2223 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2224 | return EXIT_FAILURE; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2225 | } |
| 2226 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2227 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2228 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2229 | 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] | 2230 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2231 | struct lyxml_elem *child; |
| 2232 | const char *value; |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2233 | int count; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2234 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2235 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2236 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2237 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2238 | continue; |
| 2239 | } |
| 2240 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2241 | if (!strcmp(child->name, "prefix")) { |
| 2242 | GETVAL(value, child, "value"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 2243 | if (lyp_check_identifier(value, LY_IDENT_PREFIX, LOGLINE(child), module, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2244 | goto error; |
| 2245 | } |
| 2246 | imp->prefix = lydict_insert(module->ctx, value, strlen(value)); |
| 2247 | } else if (!strcmp(child->name, "revision-date")) { |
| 2248 | if (imp->rev[0]) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2249 | LOGVAL(LYE_TOOMANY, LOGLINE(child), "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2250 | goto error; |
| 2251 | } |
| 2252 | GETVAL(value, child, "date"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 2253 | if (lyp_check_date(value, LOGLINE(child))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2254 | goto error; |
| 2255 | } |
| 2256 | memcpy(imp->rev, value, LY_REV_SIZE - 1); |
| 2257 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2258 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2259 | goto error; |
| 2260 | } |
| 2261 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2262 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2263 | /* check mandatory information */ |
| 2264 | if (!imp->prefix) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2265 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "prefix", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2266 | goto error; |
| 2267 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2268 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2269 | GETVAL(value, yin, "module"); |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2270 | |
| 2271 | /* check for circular import, store it if passed */ |
| 2272 | if (!module->ctx->models.parsing) { |
| 2273 | count = 0; |
| 2274 | } else { |
| 2275 | for (count = 0; module->ctx->models.parsing[count]; ++count) { |
| 2276 | if (value == module->ctx->models.parsing[count]) { |
| 2277 | LOGERR(LY_EVALID, "Circular import dependency on the module \"%s\".", value); |
| 2278 | goto error; |
| 2279 | } |
| 2280 | } |
| 2281 | } |
| 2282 | ++count; |
| 2283 | module->ctx->models.parsing = |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2284 | ly_realloc(module->ctx->models.parsing, (count + 1) * sizeof *module->ctx->models.parsing); |
| 2285 | if (!module->ctx->models.parsing) { |
| 2286 | LOGMEM; |
| 2287 | goto error; |
| 2288 | } |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2289 | module->ctx->models.parsing[count - 1] = value; |
| 2290 | module->ctx->models.parsing[count] = NULL; |
| 2291 | |
| 2292 | /* try to load the module */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 2293 | imp->module = (struct lys_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] | 2294 | if (!imp->module) { |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 2295 | /* whether to use a user callback is decided in the function */ |
| 2296 | imp->module = (struct lys_module *)ly_ctx_load_module(module->ctx, value, imp->rev[0] ? imp->rev : NULL); |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2297 | } |
| 2298 | |
| 2299 | /* remove the new module name now that its parsing is finished (even if failed) */ |
| 2300 | if (module->ctx->models.parsing[count] || (module->ctx->models.parsing[count - 1] != value)) { |
| 2301 | LOGINT; |
| 2302 | } |
| 2303 | --count; |
| 2304 | if (count) { |
| 2305 | module->ctx->models.parsing[count] = NULL; |
| 2306 | } else { |
| 2307 | free(module->ctx->models.parsing); |
| 2308 | module->ctx->models.parsing = NULL; |
| 2309 | } |
| 2310 | |
| 2311 | /* check the result */ |
| 2312 | if (!imp->module) { |
| 2313 | LOGVAL(LYE_INARG, LOGLINE(yin), value, yin->name); |
| 2314 | LOGERR(LY_EVALID, "Importing \"%s\" module into \"%s\" failed.", value, module->name); |
| 2315 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2316 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2317 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2318 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2319 | |
| 2320 | error: |
| 2321 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2322 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2323 | } |
| 2324 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2325 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2326 | static int |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 2327 | fill_yin_include(struct lys_module *module, struct lyxml_elem *yin, struct lys_include *inc, struct unres_schema *unres) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2328 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2329 | struct lyxml_elem *child; |
| 2330 | const char *value; |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 2331 | char *module_data; |
| 2332 | void (*module_data_free)(char *module_data) = NULL; |
| 2333 | LYS_INFORMAT format = LYS_IN_UNKNOWN; |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2334 | int count; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2335 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2336 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2337 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2338 | /* garbage */ |
| 2339 | continue; |
| 2340 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2341 | if (!strcmp(child->name, "revision-date")) { |
| 2342 | if (inc->rev[0]) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2343 | LOGVAL(LYE_TOOMANY, LOGLINE(child), "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2344 | goto error; |
| 2345 | } |
| 2346 | GETVAL(value, child, "date"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 2347 | if (lyp_check_date(value, LOGLINE(child))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2348 | goto error; |
| 2349 | } |
| 2350 | memcpy(inc->rev, value, LY_REV_SIZE - 1); |
| 2351 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2352 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2353 | goto error; |
| 2354 | } |
| 2355 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2356 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2357 | GETVAL(value, yin, "module"); |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2358 | |
| 2359 | /* check for circular include, store it if passed */ |
| 2360 | if (!module->ctx->models.parsing) { |
| 2361 | count = 0; |
| 2362 | } else { |
| 2363 | for (count = 0; module->ctx->models.parsing[count]; ++count) { |
| 2364 | if (value == module->ctx->models.parsing[count]) { |
| 2365 | LOGERR(LY_EVALID, "Circular include dependency on the submodule \"%s\".", value); |
| 2366 | goto error; |
| 2367 | } |
| 2368 | } |
| 2369 | } |
| 2370 | ++count; |
| 2371 | module->ctx->models.parsing = |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2372 | ly_realloc(module->ctx->models.parsing, (count + 1) * sizeof *module->ctx->models.parsing); |
| 2373 | if (!module->ctx->models.parsing) { |
| 2374 | LOGMEM; |
| 2375 | goto error; |
| 2376 | } |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2377 | module->ctx->models.parsing[count - 1] = value; |
| 2378 | module->ctx->models.parsing[count] = NULL; |
| 2379 | |
| 2380 | /* try to load the submodule */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 2381 | inc->submodule = (struct lys_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] | 2382 | if (!inc->submodule) { |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 2383 | if (module->ctx->module_clb) { |
| 2384 | module_data = module->ctx->module_clb(value, inc->rev[0] ? inc->rev : NULL, module->ctx->module_clb_data, |
| 2385 | &format, &module_data_free); |
| 2386 | if (module_data) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 2387 | inc->submodule = lys_submodule_parse(module, module_data, format, unres); |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 2388 | if (module_data_free) { |
| 2389 | module_data_free(module_data); |
| 2390 | } else { |
| 2391 | free(module_data); |
| 2392 | } |
| 2393 | } else { |
| 2394 | LOGERR(LY_EVALID, "User module retrieval callback failed!"); |
| 2395 | } |
| 2396 | } else { |
| 2397 | inc->submodule = (struct lys_submodule *)lyp_search_file(module->ctx, module, value, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 2398 | inc->rev[0] ? inc->rev : NULL, unres); |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 2399 | } |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2400 | } |
| 2401 | |
| 2402 | /* remove the new submodule name now that its parsing is finished (even if failed) */ |
| 2403 | if (module->ctx->models.parsing[count] || (module->ctx->models.parsing[count - 1] != value)) { |
| 2404 | LOGINT; |
| 2405 | } |
| 2406 | --count; |
| 2407 | if (count) { |
| 2408 | module->ctx->models.parsing[count] = NULL; |
| 2409 | } else { |
| 2410 | free(module->ctx->models.parsing); |
| 2411 | module->ctx->models.parsing = NULL; |
| 2412 | } |
| 2413 | |
| 2414 | /* check the result */ |
| 2415 | if (!inc->submodule) { |
| 2416 | LOGVAL(LYE_INARG, LOGLINE(yin), value, yin->name); |
| 2417 | LOGERR(LY_EVALID, "Including \"%s\" module into \"%s\" failed.", value, module->name); |
| 2418 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2419 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2420 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2421 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2422 | |
| 2423 | error: |
| 2424 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2425 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2426 | } |
| 2427 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2428 | /* logs directly |
| 2429 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2430 | * Covers: |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 2431 | * description, reference, status, optionaly config |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 2432 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2433 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2434 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2435 | read_yin_common(struct lys_module *module, struct lys_node *parent, |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2436 | struct lys_node *node, struct lyxml_elem *xmlnode, int opt) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2437 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2438 | const char *value; |
| 2439 | struct lyxml_elem *sub, *next; |
| 2440 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2441 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2442 | if (opt & OPT_MODULE) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2443 | node->module = module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2444 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2445 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2446 | if (opt & OPT_IDENT) { |
| 2447 | GETVAL(value, xmlnode, "name"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 2448 | if (lyp_check_identifier(value, LY_IDENT_NAME, LOGLINE(xmlnode), NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2449 | goto error; |
| 2450 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2451 | node->name = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2452 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2453 | |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2454 | /* inherit NACM flags */ |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2455 | if ((opt & OPT_NACMEXT) && parent) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2456 | node->nacm = parent->nacm; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2457 | } |
| 2458 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2459 | /* process local parameters */ |
| 2460 | LY_TREE_FOR_SAFE(xmlnode->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2461 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2462 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2463 | lyxml_free(ctx, sub); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2464 | continue; |
| 2465 | } |
| 2466 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 2467 | /* NACM extensions */ |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2468 | if ((opt & OPT_NACMEXT) && !strcmp(sub->ns->value, LY_NSNACM)) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2469 | if (!strcmp(sub->name, "default-deny-write")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2470 | node->nacm |= LYS_NACM_DENYW; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2471 | } else if (!strcmp(sub->name, "default-deny-all")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2472 | node->nacm |= LYS_NACM_DENYA; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2473 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2474 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2475 | goto error; |
| 2476 | } |
| 2477 | } |
| 2478 | |
| 2479 | /* else garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2480 | lyxml_free(ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2481 | continue; |
| 2482 | } |
| 2483 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2484 | if (!strcmp(sub->name, "description")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2485 | if (node->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2486 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2487 | goto error; |
| 2488 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2489 | node->dsc = read_yin_subnode(ctx, sub, "text"); |
| 2490 | if (!node->dsc) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2491 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2492 | } |
| 2493 | } else if (!strcmp(sub->name, "reference")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2494 | if (node->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2495 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2496 | goto error; |
| 2497 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2498 | node->ref = read_yin_subnode(ctx, sub, "text"); |
| 2499 | if (!node->ref) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2500 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2501 | } |
| 2502 | } else if (!strcmp(sub->name, "status")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2503 | if (node->flags & LYS_STATUS_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2504 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2505 | goto error; |
| 2506 | } |
| 2507 | GETVAL(value, sub, "value"); |
| 2508 | if (!strcmp(value, "current")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2509 | node->flags |= LYS_STATUS_CURR; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2510 | } else if (!strcmp(value, "deprecated")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2511 | node->flags |= LYS_STATUS_DEPRC; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2512 | } else if (!strcmp(value, "obsolete")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2513 | node->flags |= LYS_STATUS_OBSLT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2514 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2515 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2516 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2517 | } |
| 2518 | } else if ((opt & OPT_CONFIG) && !strcmp(sub->name, "config")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2519 | if (node->flags & LYS_CONFIG_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2520 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2521 | goto error; |
| 2522 | } |
| 2523 | GETVAL(value, sub, "value"); |
| 2524 | if (!strcmp(value, "false")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2525 | node->flags |= LYS_CONFIG_R; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2526 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2527 | node->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2528 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2529 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2530 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2531 | } |
| 2532 | } else { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2533 | /* skip the lyxml_free */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2534 | continue; |
| 2535 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2536 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2537 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2538 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2539 | if ((opt & OPT_INHERIT) && !(node->flags & LYS_CONFIG_MASK)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2540 | /* get config flag from parent */ |
| 2541 | if (parent) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2542 | node->flags |= parent->flags & LYS_CONFIG_MASK; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2543 | } else { |
| 2544 | /* default config is true */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2545 | node->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2546 | } |
| 2547 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2548 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2549 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 2550 | |
| 2551 | error: |
| 2552 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2553 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2554 | } |
| 2555 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2556 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2557 | static struct lys_when * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2558 | read_yin_when(struct lys_module *module, struct lyxml_elem *yin) |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2559 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2560 | struct lys_when *retval = NULL; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2561 | struct lyxml_elem *child; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2562 | const char *value; |
| 2563 | |
| 2564 | retval = calloc(1, sizeof *retval); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2565 | if (!retval) { |
| 2566 | LOGMEM; |
| 2567 | return NULL; |
| 2568 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2569 | |
| 2570 | GETVAL(value, yin, "condition"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 2571 | retval->cond = transform_schema2json(module, value, LOGLINE(yin)); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 2572 | if (!retval->cond) { |
| 2573 | goto error; |
| 2574 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2575 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2576 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2577 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2578 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2579 | continue; |
| 2580 | } |
| 2581 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2582 | if (!strcmp(child->name, "description")) { |
| 2583 | if (retval->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2584 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2585 | goto error; |
| 2586 | } |
| 2587 | retval->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 2588 | if (!retval->dsc) { |
| 2589 | goto error; |
| 2590 | } |
| 2591 | } else if (!strcmp(child->name, "reference")) { |
| 2592 | if (retval->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2593 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2594 | goto error; |
| 2595 | } |
| 2596 | retval->ref = read_yin_subnode(module->ctx, child, "text"); |
| 2597 | if (!retval->ref) { |
| 2598 | goto error; |
| 2599 | } |
| 2600 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2601 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2602 | goto error; |
| 2603 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2604 | } |
| 2605 | |
| 2606 | return retval; |
| 2607 | |
| 2608 | error: |
| 2609 | |
Michal Vasko | 0308dd6 | 2015-10-07 09:14:40 +0200 | [diff] [blame] | 2610 | lys_when_free(module->ctx, retval); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2611 | return NULL; |
| 2612 | } |
| 2613 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2614 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2615 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 2616 | read_yin_case(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 2617 | struct unres_schema *unres) |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2618 | { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2619 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2620 | struct lys_node_case *cs; |
| 2621 | struct lys_node *retval, *node = NULL; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 2622 | int c_ftrs = 0, ret; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2623 | const char *value; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2624 | |
Radek Krejci | e867c85 | 2015-08-27 09:52:34 +0200 | [diff] [blame] | 2625 | /* init */ |
| 2626 | memset(&root, 0, sizeof root); |
| 2627 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2628 | cs = calloc(1, sizeof *cs); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2629 | if (!cs) { |
| 2630 | LOGMEM; |
| 2631 | return NULL; |
| 2632 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2633 | cs->nodetype = LYS_CASE; |
| 2634 | cs->prev = (struct lys_node *)cs; |
| 2635 | retval = (struct lys_node *)cs; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2636 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2637 | 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] | 2638 | goto error; |
| 2639 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2640 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 2641 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 2642 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2643 | /* insert the node into the schema tree */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 2644 | if (lys_node_addchild(parent, module->type ? ((struct lys_submodule *)module)->belongsto: module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2645 | goto error; |
| 2646 | } |
| 2647 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2648 | /* process choice's specific children */ |
| 2649 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2650 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2651 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2652 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2653 | continue; |
| 2654 | } |
| 2655 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2656 | if (!strcmp(sub->name, "container") || |
| 2657 | !strcmp(sub->name, "leaf-list") || |
| 2658 | !strcmp(sub->name, "leaf") || |
| 2659 | !strcmp(sub->name, "list") || |
| 2660 | !strcmp(sub->name, "uses") || |
| 2661 | !strcmp(sub->name, "choice") || |
| 2662 | !strcmp(sub->name, "anyxml")) { |
| 2663 | |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 2664 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2665 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2666 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2667 | c_ftrs++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2668 | /* skip lyxml_free() at the end of the loop, sub is processed later */ |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2669 | continue; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2670 | } else if (!strcmp(sub->name, "when")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2671 | if (cs->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2672 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2673 | goto error; |
| 2674 | } |
| 2675 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2676 | cs->when = read_yin_when(module, sub); |
| 2677 | if (!cs->when) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2678 | goto error; |
| 2679 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 2680 | if (lyxp_syntax_check(cs->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2681 | goto error; |
| 2682 | } |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2683 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2684 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2685 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2686 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2687 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2688 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2689 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2690 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2691 | if (c_ftrs) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2692 | cs->features = calloc(c_ftrs, sizeof *cs->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2693 | if (!cs->features) { |
| 2694 | LOGMEM; |
| 2695 | goto error; |
| 2696 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2697 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2698 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2699 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 2700 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 2701 | goto error; |
| 2702 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 2703 | /* hack - store pointer to the parent node for later status check */ |
| 2704 | cs->features[cs->features_size] = (struct lys_feature *)cs; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 2705 | ret = unres_schema_add_str(module, unres, &cs->features[cs->features_size], UNRES_IFFEAT, value, |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 2706 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 2707 | cs->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 2708 | lydict_remove(module->ctx, value); |
| 2709 | if (ret == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2710 | goto error; |
| 2711 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2712 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 2713 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2714 | /* last part - process data nodes */ |
| 2715 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 2716 | if (!strcmp(sub->name, "container")) { |
| 2717 | node = read_yin_container(module, retval, sub, resolve, unres); |
| 2718 | } else if (!strcmp(sub->name, "leaf-list")) { |
| 2719 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
| 2720 | } else if (!strcmp(sub->name, "leaf")) { |
| 2721 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
| 2722 | } else if (!strcmp(sub->name, "list")) { |
| 2723 | node = read_yin_list(module, retval, sub, resolve, unres); |
| 2724 | } else if (!strcmp(sub->name, "choice")) { |
| 2725 | node = read_yin_choice(module, retval, sub, resolve, unres); |
| 2726 | } else if (!strcmp(sub->name, "uses")) { |
| 2727 | node = read_yin_uses(module, retval, sub, resolve, unres); |
| 2728 | } else if (!strcmp(sub->name, "anyxml")) { |
| 2729 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
| 2730 | } |
| 2731 | if (!node) { |
| 2732 | goto error; |
| 2733 | } |
| 2734 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2735 | lyxml_free(module->ctx, sub); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2736 | } |
| 2737 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2738 | return retval; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2739 | |
| 2740 | error: |
| 2741 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2742 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2743 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2744 | } |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 2745 | lys_node_free(retval, NULL); |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2746 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2747 | return NULL; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2748 | } |
| 2749 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2750 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2751 | static struct lys_node * |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 2752 | read_yin_choice(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2753 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2754 | struct lyxml_elem *sub, *next; |
| 2755 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2756 | struct lys_node *retval, *node = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2757 | struct lys_node_choice *choice; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2758 | const char *value, *dflt_str = NULL; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 2759 | int f_mand = 0, c_ftrs = 0, ret; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2760 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2761 | choice = calloc(1, sizeof *choice); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2762 | if (!choice) { |
| 2763 | LOGMEM; |
| 2764 | return NULL; |
| 2765 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2766 | choice->nodetype = LYS_CHOICE; |
| 2767 | choice->prev = (struct lys_node *)choice; |
| 2768 | retval = (struct lys_node *)choice; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2769 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 2770 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 2771 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2772 | goto error; |
| 2773 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2774 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 2775 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 2776 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2777 | /* insert the node into the schema tree */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 2778 | if (lys_node_addchild(parent, module->type ? ((struct lys_submodule *)module)->belongsto: module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2779 | goto error; |
| 2780 | } |
| 2781 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2782 | /* process choice's specific children */ |
| 2783 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2784 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2785 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2786 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2787 | continue; |
| 2788 | } |
| 2789 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2790 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2791 | if (!(node = read_yin_container(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2792 | goto error; |
| 2793 | } |
| 2794 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2795 | if (!(node = read_yin_leaflist(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2796 | goto error; |
| 2797 | } |
| 2798 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2799 | if (!(node = read_yin_leaf(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2800 | goto error; |
| 2801 | } |
| 2802 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2803 | if (!(node = read_yin_list(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2804 | goto error; |
| 2805 | } |
| 2806 | } else if (!strcmp(sub->name, "case")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2807 | if (!(node = read_yin_case(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2808 | goto error; |
| 2809 | } |
| 2810 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2811 | if (!(node = read_yin_anyxml(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2812 | goto error; |
| 2813 | } |
| 2814 | } else if (!strcmp(sub->name, "default")) { |
| 2815 | if (dflt_str) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2816 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2817 | goto error; |
| 2818 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2819 | GETVAL(dflt_str, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2820 | } else if (!strcmp(sub->name, "mandatory")) { |
| 2821 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2822 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2823 | goto error; |
| 2824 | } |
| 2825 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2826 | * multiple mandatory statements with the "false" value |
| 2827 | */ |
| 2828 | f_mand = 1; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2829 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2830 | GETVAL(value, sub, "value"); |
| 2831 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2832 | choice->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2833 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2834 | choice->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2835 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2836 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2837 | goto error; |
| 2838 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2839 | } else if (!strcmp(sub->name, "when")) { |
| 2840 | if (choice->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2841 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2842 | goto error; |
| 2843 | } |
| 2844 | |
| 2845 | choice->when = read_yin_when(module, sub); |
| 2846 | if (!choice->when) { |
| 2847 | goto error; |
| 2848 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 2849 | if (lyxp_syntax_check(choice->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2850 | goto error; |
| 2851 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2852 | } else if (!strcmp(sub->name, "if-feature")) { |
| 2853 | c_ftrs++; |
| 2854 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2855 | /* skip lyxml_free() at the end of the loop, the sub node is processed later */ |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2856 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2857 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2858 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2859 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2860 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2861 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2862 | node = NULL; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2863 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2864 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2865 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2866 | if (c_ftrs) { |
| 2867 | choice->features = calloc(c_ftrs, sizeof *choice->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2868 | if (!choice->features) { |
| 2869 | LOGMEM; |
| 2870 | goto error; |
| 2871 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2872 | } |
| 2873 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2874 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2875 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 2876 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 2877 | goto error; |
| 2878 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 2879 | /* hack - store pointer to the parent node for later status check */ |
| 2880 | choice->features[choice->features_size] = (struct lys_feature *)choice; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 2881 | ret = unres_schema_add_str(module, unres, &choice->features[choice->features_size], UNRES_IFFEAT, value, |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 2882 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 2883 | choice->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 2884 | lydict_remove(module->ctx, value); |
| 2885 | if (ret == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2886 | goto error; |
| 2887 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2888 | } |
| 2889 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2890 | /* check - default is prohibited in combination with mandatory */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2891 | if (dflt_str && (choice->flags & LYS_MAND_TRUE)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2892 | LOGVAL(LYE_SPEC, LOGLINE(yin), |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2893 | "The \"default\" statement MUST NOT be present on choices where \"mandatory\" is true."); |
| 2894 | goto error; |
| 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 | /* link default with the case */ |
| 2898 | if (dflt_str) { |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 2899 | if (unres_schema_add_str(module, unres, choice, UNRES_CHOICE_DFLT, dflt_str, LOGLINE(yin)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2900 | goto error; |
| 2901 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2902 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2903 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2904 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2905 | |
| 2906 | error: |
| 2907 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 2908 | lys_node_free(retval, NULL); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2909 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2910 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2911 | } |
| 2912 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2913 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2914 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2915 | read_yin_anyxml(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 2916 | struct unres_schema *unres) |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2917 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2918 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2919 | struct lys_node_leaf *anyxml; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2920 | struct lyxml_elem *sub, *next; |
| 2921 | const char *value; |
| 2922 | int r; |
| 2923 | int f_mand = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2924 | int c_must = 0, c_ftrs = 0; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2925 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2926 | anyxml = calloc(1, sizeof *anyxml); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2927 | if (!anyxml) { |
| 2928 | LOGMEM; |
| 2929 | return NULL; |
| 2930 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2931 | anyxml->nodetype = LYS_ANYXML; |
| 2932 | anyxml->prev = (struct lys_node *)anyxml; |
| 2933 | retval = (struct lys_node *)anyxml; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2934 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 2935 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 2936 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2937 | goto error; |
| 2938 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2939 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 2940 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 2941 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 2942 | if (lys_node_addchild(parent, module->type ? ((struct lys_submodule *)module)->belongsto: module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2943 | goto error; |
| 2944 | } |
| 2945 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2946 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2947 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2948 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2949 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2950 | continue; |
| 2951 | } |
| 2952 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2953 | if (!strcmp(sub->name, "mandatory")) { |
| 2954 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2955 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2956 | goto error; |
| 2957 | } |
| 2958 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2959 | * multiple mandatory statements with the "false" value |
| 2960 | */ |
| 2961 | f_mand = 1; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2962 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2963 | GETVAL(value, sub, "value"); |
| 2964 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2965 | anyxml->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2966 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2967 | anyxml->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2968 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2969 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2970 | goto error; |
| 2971 | } |
| 2972 | /* else false is the default value, so we can ignore it */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2973 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2974 | } else if (!strcmp(sub->name, "when")) { |
| 2975 | if (anyxml->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2976 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2977 | goto error; |
| 2978 | } |
| 2979 | |
| 2980 | anyxml->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2981 | if (!anyxml->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2982 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2983 | goto error; |
| 2984 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 2985 | if (lyxp_syntax_check(anyxml->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2986 | goto error; |
| 2987 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2988 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2989 | } else if (!strcmp(sub->name, "must")) { |
| 2990 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2991 | } else if (!strcmp(sub->name, "if-feature")) { |
| 2992 | c_ftrs++; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2993 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2994 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2995 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2996 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2997 | } |
| 2998 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2999 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3000 | /* middle part - process nodes with cardinality of 0..n */ |
| 3001 | if (c_must) { |
| 3002 | anyxml->must = calloc(c_must, sizeof *anyxml->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3003 | if (!anyxml->must) { |
| 3004 | LOGMEM; |
| 3005 | goto error; |
| 3006 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3007 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3008 | if (c_ftrs) { |
| 3009 | anyxml->features = calloc(c_ftrs, sizeof *anyxml->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3010 | if (!anyxml->features) { |
| 3011 | LOGMEM; |
| 3012 | goto error; |
| 3013 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3014 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3015 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3016 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3017 | if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3018 | r = fill_yin_must(module, sub, &anyxml->must[anyxml->must_size]); |
| 3019 | anyxml->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3020 | if (r) { |
| 3021 | goto error; |
| 3022 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 3023 | if (lyxp_syntax_check(anyxml->must[anyxml->must_size-1].expr, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3024 | goto error; |
| 3025 | } |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 3026 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3027 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 3028 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3029 | goto error; |
| 3030 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3031 | /* hack - store pointer to the parent node for later status check */ |
| 3032 | anyxml->features[anyxml->features_size] = (struct lys_feature *)anyxml; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3033 | r = unres_schema_add_str(module, unres, &anyxml->features[anyxml->features_size], UNRES_IFFEAT, value, |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3034 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3035 | anyxml->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3036 | lydict_remove(module->ctx, value); |
| 3037 | if (r == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3038 | goto error; |
| 3039 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3040 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3041 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3042 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3043 | return retval; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3044 | |
| 3045 | error: |
| 3046 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 3047 | lys_node_free(retval, NULL); |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3048 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3049 | return NULL; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3050 | } |
| 3051 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3052 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3053 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3054 | read_yin_leaf(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3055 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3056 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3057 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3058 | struct lys_node_leaf *leaf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3059 | struct lyxml_elem *sub, *next; |
| 3060 | const char *value; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3061 | int r, has_type = 0, dflt_line; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3062 | int c_must = 0, c_ftrs = 0, f_mand = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3063 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3064 | leaf = calloc(1, sizeof *leaf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3065 | if (!leaf) { |
| 3066 | LOGMEM; |
| 3067 | return NULL; |
| 3068 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3069 | leaf->nodetype = LYS_LEAF; |
| 3070 | leaf->prev = (struct lys_node *)leaf; |
| 3071 | retval = (struct lys_node *)leaf; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3072 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3073 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3074 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3075 | goto error; |
| 3076 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3077 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3078 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3079 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 3080 | if (lys_node_addchild(parent, module->type ? ((struct lys_submodule *)module)->belongsto: module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3081 | goto error; |
| 3082 | } |
| 3083 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3084 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3085 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3086 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3087 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3088 | continue; |
| 3089 | } |
| 3090 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3091 | if (!strcmp(sub->name, "type")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3092 | if (leaf->type.der || has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3093 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3094 | goto error; |
| 3095 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3096 | /* HACK for unres */ |
| 3097 | leaf->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3098 | leaf->type.parent = (struct lys_tpdf *)leaf; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3099 | if (unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DER, parent, LOGLINE(sub))) { |
| 3100 | leaf->type.der = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3101 | goto error; |
| 3102 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3103 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3104 | } else if (!strcmp(sub->name, "default")) { |
| 3105 | if (leaf->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3106 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3107 | goto error; |
| 3108 | } |
| 3109 | GETVAL(value, sub, "value"); |
| 3110 | leaf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3111 | dflt_line = LOGLINE(sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3112 | } else if (!strcmp(sub->name, "units")) { |
| 3113 | if (leaf->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3114 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3115 | goto error; |
| 3116 | } |
| 3117 | GETVAL(value, sub, "name"); |
| 3118 | leaf->units = lydict_insert(module->ctx, value, strlen(value)); |
| 3119 | } else if (!strcmp(sub->name, "mandatory")) { |
| 3120 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3121 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3122 | goto error; |
| 3123 | } |
| 3124 | /* just checking the flags in leaf is not sufficient, we would allow |
| 3125 | * multiple mandatory statements with the "false" value |
| 3126 | */ |
| 3127 | f_mand = 1; |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3128 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3129 | GETVAL(value, sub, "value"); |
| 3130 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3131 | leaf->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3132 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3133 | leaf->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3134 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3135 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3136 | goto error; |
| 3137 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3138 | } else if (!strcmp(sub->name, "when")) { |
| 3139 | if (leaf->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3140 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3141 | goto error; |
| 3142 | } |
| 3143 | |
| 3144 | leaf->when = read_yin_when(module, sub); |
| 3145 | if (!leaf->when) { |
| 3146 | goto error; |
| 3147 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 3148 | if (lyxp_syntax_check(leaf->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3149 | goto error; |
| 3150 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3151 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3152 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3153 | c_must++; |
| 3154 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3155 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3156 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3157 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3158 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3159 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3160 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3161 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3162 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3163 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3164 | /* do not free sub, it could have been unlinked and stored in unres */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3165 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3166 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3167 | /* check mandatory parameters */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3168 | if (!has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3169 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3170 | goto error; |
| 3171 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3172 | if (leaf->dflt) { |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3173 | if (unres_schema_add_str(module, unres, &leaf->type, UNRES_TYPE_DFLT, leaf->dflt, dflt_line) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3174 | goto error; |
| 3175 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3176 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3177 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3178 | /* middle part - process nodes with cardinality of 0..n */ |
| 3179 | if (c_must) { |
| 3180 | leaf->must = calloc(c_must, sizeof *leaf->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3181 | if (!leaf->must) { |
| 3182 | LOGMEM; |
| 3183 | goto error; |
| 3184 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3185 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3186 | if (c_ftrs) { |
| 3187 | leaf->features = calloc(c_ftrs, sizeof *leaf->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3188 | if (!leaf->features) { |
| 3189 | LOGMEM; |
| 3190 | goto error; |
| 3191 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3192 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3193 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3194 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3195 | if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3196 | r = fill_yin_must(module, sub, &leaf->must[leaf->must_size]); |
| 3197 | leaf->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3198 | if (r) { |
| 3199 | goto error; |
| 3200 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 3201 | if (lyxp_syntax_check(leaf->must[leaf->must_size-1].expr, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3202 | goto error; |
| 3203 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3204 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3205 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 3206 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3207 | goto error; |
| 3208 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3209 | /* hack - store pointer to the parent node for later status check */ |
| 3210 | leaf->features[leaf->features_size] = (struct lys_feature *)leaf; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3211 | r = unres_schema_add_str(module, unres, &leaf->features[leaf->features_size], UNRES_IFFEAT, value, |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3212 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3213 | leaf->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3214 | lydict_remove(module->ctx, value); |
| 3215 | if (r == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3216 | goto error; |
| 3217 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3218 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3219 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3220 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3221 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3222 | |
| 3223 | error: |
| 3224 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 3225 | lys_node_free(retval, NULL); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3226 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3227 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3228 | } |
| 3229 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3230 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3231 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3232 | read_yin_leaflist(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3233 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3234 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3235 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3236 | struct lys_node_leaflist *llist; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3237 | struct lyxml_elem *sub, *next; |
| 3238 | const char *value; |
| 3239 | char *endptr; |
| 3240 | unsigned long val; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3241 | int r, has_type = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3242 | int c_must = 0, c_ftrs = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3243 | int f_ordr = 0, f_min = 0, f_max = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3244 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3245 | llist = calloc(1, sizeof *llist); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3246 | if (!llist) { |
| 3247 | LOGMEM; |
| 3248 | return NULL; |
| 3249 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3250 | llist->nodetype = LYS_LEAFLIST; |
| 3251 | llist->prev = (struct lys_node *)llist; |
| 3252 | retval = (struct lys_node *)llist; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3253 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3254 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3255 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3256 | goto error; |
| 3257 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3258 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3259 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3260 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 3261 | if (lys_node_addchild(parent, module->type ? ((struct lys_submodule *)module)->belongsto: module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3262 | goto error; |
| 3263 | } |
| 3264 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3265 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3266 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3267 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3268 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3269 | continue; |
| 3270 | } |
| 3271 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3272 | if (!strcmp(sub->name, "type")) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3273 | if (llist->type.der || has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3274 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3275 | goto error; |
| 3276 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3277 | /* HACK for unres */ |
| 3278 | llist->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3279 | llist->type.parent = (struct lys_tpdf *)llist; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3280 | if (unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DER, parent, LOGLINE(sub))) { |
| 3281 | llist->type.der = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3282 | goto error; |
| 3283 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3284 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3285 | } else if (!strcmp(sub->name, "units")) { |
| 3286 | if (llist->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3287 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3288 | goto error; |
| 3289 | } |
| 3290 | GETVAL(value, sub, "name"); |
| 3291 | llist->units = lydict_insert(module->ctx, value, strlen(value)); |
| 3292 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 3293 | if (f_ordr) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3294 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3295 | goto error; |
| 3296 | } |
| 3297 | /* just checking the flags in llist is not sufficient, we would |
| 3298 | * allow multiple ordered-by statements with the "system" value |
| 3299 | */ |
| 3300 | f_ordr = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3301 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3302 | if (llist->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3303 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 3304 | * state data |
| 3305 | */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3306 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3307 | continue; |
| 3308 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3309 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3310 | GETVAL(value, sub, "value"); |
| 3311 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3312 | llist->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3313 | } else if (strcmp(value, "system")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3314 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3315 | goto error; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3316 | } /* else system is the default value, so we can ignore it */ |
| 3317 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3318 | } else if (!strcmp(sub->name, "must")) { |
| 3319 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3320 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3321 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3322 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3323 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3324 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3325 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3326 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3327 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3328 | goto error; |
| 3329 | } |
| 3330 | f_min = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3331 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3332 | GETVAL(value, sub, "value"); |
| 3333 | while (isspace(value[0])) { |
| 3334 | value++; |
| 3335 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3336 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3337 | /* convert it to uint32_t */ |
| 3338 | errno = 0; |
| 3339 | endptr = NULL; |
| 3340 | val = strtoul(value, &endptr, 10); |
| 3341 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3342 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3343 | goto error; |
| 3344 | } |
| 3345 | llist->min = (uint32_t) val; |
| 3346 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3347 | if (f_max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3348 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3349 | goto error; |
| 3350 | } |
| 3351 | f_max = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3352 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3353 | GETVAL(value, sub, "value"); |
| 3354 | while (isspace(value[0])) { |
| 3355 | value++; |
| 3356 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3357 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3358 | /* convert it to uint32_t */ |
| 3359 | errno = 0; |
| 3360 | endptr = NULL; |
| 3361 | val = strtoul(value, &endptr, 10); |
| 3362 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3363 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3364 | goto error; |
| 3365 | } |
| 3366 | llist->max = (uint32_t) val; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3367 | } else if (!strcmp(sub->name, "when")) { |
| 3368 | if (llist->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3369 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3370 | goto error; |
| 3371 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3372 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3373 | llist->when = read_yin_when(module, sub); |
| 3374 | if (!llist->when) { |
| 3375 | goto error; |
| 3376 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 3377 | if (lyxp_syntax_check(llist->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3378 | goto error; |
| 3379 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3380 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3381 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3382 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3383 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3384 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3385 | /* do not free sub, it could have been unlinked and stored in unres */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3386 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3387 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3388 | /* check constraints */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3389 | if (!has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3390 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3391 | goto error; |
| 3392 | } |
| 3393 | if (llist->max && llist->min > llist->max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3394 | LOGVAL(LYE_SPEC, LOGLINE(yin), "\"min-elements\" is bigger than \"max-elements\"."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3395 | goto error; |
| 3396 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3397 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3398 | /* middle part - process nodes with cardinality of 0..n */ |
| 3399 | if (c_must) { |
| 3400 | llist->must = calloc(c_must, sizeof *llist->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3401 | if (!llist->must) { |
| 3402 | LOGMEM; |
| 3403 | goto error; |
| 3404 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3405 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3406 | if (c_ftrs) { |
| 3407 | llist->features = calloc(c_ftrs, sizeof *llist->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3408 | if (!llist->features) { |
| 3409 | LOGMEM; |
| 3410 | goto error; |
| 3411 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3412 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3413 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3414 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3415 | if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3416 | r = fill_yin_must(module, sub, &llist->must[llist->must_size]); |
| 3417 | llist->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3418 | if (r) { |
| 3419 | goto error; |
| 3420 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 3421 | if (lyxp_syntax_check(llist->must[llist->must_size-1].expr, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3422 | goto error; |
| 3423 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3424 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3425 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 3426 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3427 | goto error; |
| 3428 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3429 | /* hack - store pointer to the parent node for later status check */ |
| 3430 | llist->features[llist->features_size] = (struct lys_feature *)llist; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3431 | r = unres_schema_add_str(module, unres, &llist->features[llist->features_size], UNRES_IFFEAT, value, |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3432 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3433 | llist->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3434 | lydict_remove(module->ctx, value); |
| 3435 | if (r == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3436 | goto error; |
| 3437 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3438 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3439 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3440 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3441 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3442 | |
| 3443 | error: |
| 3444 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 3445 | lys_node_free(retval, NULL); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3446 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3447 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3448 | } |
| 3449 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3450 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3451 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3452 | read_yin_list(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 3453 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3454 | { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3455 | struct lys_node *retval, *node; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3456 | struct lys_node_list *list; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3457 | struct lyxml_elem *sub, *next, root, uniq; |
Michal Vasko | e38af6e | 2015-08-03 14:39:27 +0200 | [diff] [blame] | 3458 | int r, key_line; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3459 | 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] | 3460 | int f_ordr = 0, f_max = 0, f_min = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3461 | const char *key_str = NULL, *value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3462 | char *auxs; |
| 3463 | unsigned long val; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3464 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3465 | /* init */ |
| 3466 | memset(&root, 0, sizeof root); |
| 3467 | memset(&uniq, 0, sizeof uniq); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3468 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3469 | list = calloc(1, sizeof *list); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3470 | if (!list) { |
| 3471 | LOGMEM; |
| 3472 | return NULL; |
| 3473 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3474 | list->nodetype = LYS_LIST; |
| 3475 | list->prev = (struct lys_node *)list; |
| 3476 | retval = (struct lys_node *)list; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3477 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3478 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3479 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3480 | goto error; |
| 3481 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3482 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3483 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3484 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3485 | /* process list's specific children */ |
| 3486 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3487 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3488 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3489 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3490 | continue; |
| 3491 | } |
| 3492 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3493 | /* data statements */ |
| 3494 | if (!strcmp(sub->name, "container") || |
| 3495 | !strcmp(sub->name, "leaf-list") || |
| 3496 | !strcmp(sub->name, "leaf") || |
| 3497 | !strcmp(sub->name, "list") || |
| 3498 | !strcmp(sub->name, "choice") || |
| 3499 | !strcmp(sub->name, "uses") || |
| 3500 | !strcmp(sub->name, "grouping") || |
| 3501 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 3502 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3503 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3504 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3505 | /* array counters */ |
| 3506 | } else if (!strcmp(sub->name, "key")) { |
| 3507 | /* check cardinality 0..1 */ |
| 3508 | if (list->keys_size) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3509 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, list->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3510 | goto error; |
| 3511 | } |
Radek Krejci | d7f0d01 | 2015-05-25 15:04:52 +0200 | [diff] [blame] | 3512 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3513 | /* count the number of keys */ |
| 3514 | GETVAL(value, sub, "value"); |
| 3515 | key_str = value; |
Michal Vasko | e38af6e | 2015-08-03 14:39:27 +0200 | [diff] [blame] | 3516 | key_line = LOGLINE(sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3517 | while ((value = strpbrk(value, " \t\n"))) { |
| 3518 | list->keys_size++; |
| 3519 | while (isspace(*value)) { |
| 3520 | value++; |
| 3521 | } |
| 3522 | } |
| 3523 | list->keys_size++; |
| 3524 | list->keys = calloc(list->keys_size, sizeof *list->keys); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3525 | if (!list->keys) { |
| 3526 | LOGMEM; |
| 3527 | goto error; |
| 3528 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3529 | } else if (!strcmp(sub->name, "unique")) { |
| 3530 | c_uniq++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 3531 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3532 | lyxml_add_child(module->ctx, &uniq, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3533 | } else if (!strcmp(sub->name, "typedef")) { |
| 3534 | c_tpdf++; |
| 3535 | } else if (!strcmp(sub->name, "must")) { |
| 3536 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3537 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3538 | c_ftrs++; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3539 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3540 | /* optional stetments */ |
| 3541 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 3542 | if (f_ordr) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3543 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3544 | goto error; |
| 3545 | } |
| 3546 | /* just checking the flags in llist is not sufficient, we would |
| 3547 | * allow multiple ordered-by statements with the "system" value |
| 3548 | */ |
| 3549 | f_ordr = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3550 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3551 | if (list->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3552 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 3553 | * state data |
| 3554 | */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3555 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3556 | continue; |
| 3557 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3558 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3559 | GETVAL(value, sub, "value"); |
| 3560 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3561 | list->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3562 | } else if (strcmp(value, "system")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3563 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3564 | goto error; |
| 3565 | } |
| 3566 | /* else system is the default value, so we can ignore it */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3567 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3568 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3569 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3570 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3571 | goto error; |
| 3572 | } |
| 3573 | f_min = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3574 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3575 | GETVAL(value, sub, "value"); |
| 3576 | while (isspace(value[0])) { |
| 3577 | value++; |
| 3578 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3579 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3580 | /* convert it to uint32_t */ |
| 3581 | errno = 0; |
| 3582 | auxs = NULL; |
| 3583 | val = strtoul(value, &auxs, 10); |
| 3584 | if (*auxs || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3585 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3586 | goto error; |
| 3587 | } |
| 3588 | list->min = (uint32_t) val; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3589 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3590 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3591 | if (f_max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3592 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3593 | goto error; |
| 3594 | } |
| 3595 | f_max = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3596 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3597 | GETVAL(value, sub, "value"); |
| 3598 | while (isspace(value[0])) { |
| 3599 | value++; |
| 3600 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3601 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3602 | /* convert it to uint32_t */ |
| 3603 | errno = 0; |
| 3604 | auxs = NULL; |
| 3605 | val = strtoul(value, &auxs, 10); |
| 3606 | if (*auxs || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3607 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3608 | goto error; |
| 3609 | } |
| 3610 | list->max = (uint32_t) val; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3611 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3612 | } else if (!strcmp(sub->name, "when")) { |
| 3613 | if (list->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3614 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3615 | goto error; |
| 3616 | } |
| 3617 | |
| 3618 | list->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3619 | if (!list->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3620 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3621 | goto error; |
| 3622 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 3623 | if (lyxp_syntax_check(list->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3624 | goto error; |
| 3625 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3626 | lyxml_free(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3627 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3628 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3629 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3630 | } |
| 3631 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3632 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3633 | /* check - if list is configuration, key statement is mandatory */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3634 | if ((list->flags & LYS_CONFIG_W) && !key_str) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3635 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "key", "list"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3636 | goto error; |
| 3637 | } |
| 3638 | if (list->max && list->min > list->max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3639 | LOGVAL(LYE_SPEC, LOGLINE(yin), "\"min-elements\" is bigger than \"max-elements\"."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3640 | goto error; |
| 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 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3644 | if (c_tpdf) { |
| 3645 | list->tpdf = calloc(c_tpdf, sizeof *list->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3646 | if (!list->tpdf) { |
| 3647 | LOGMEM; |
| 3648 | goto error; |
| 3649 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3650 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3651 | if (c_must) { |
| 3652 | list->must = calloc(c_must, sizeof *list->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3653 | if (!list->must) { |
| 3654 | LOGMEM; |
| 3655 | goto error; |
| 3656 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3657 | } |
| 3658 | if (c_ftrs) { |
| 3659 | list->features = calloc(c_ftrs, sizeof *list->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3660 | if (!list->features) { |
| 3661 | LOGMEM; |
| 3662 | goto error; |
| 3663 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3664 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3665 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3666 | if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3667 | r = fill_yin_typedef(module, retval, sub, &list->tpdf[list->tpdf_size], unres); |
| 3668 | list->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3669 | if (r) { |
| 3670 | goto error; |
| 3671 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3672 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3673 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 3674 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3675 | goto error; |
| 3676 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3677 | /* hack - store pointer to the parent node for later status check */ |
| 3678 | list->features[list->features_size] = (struct lys_feature *)list; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3679 | r = unres_schema_add_str(module, unres, &list->features[list->features_size], UNRES_IFFEAT, value, |
Radek Krejci | fe8582c | 2015-12-15 15:39:02 +0100 | [diff] [blame] | 3680 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3681 | list->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3682 | lydict_remove(module->ctx, value); |
| 3683 | if (r == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3684 | goto error; |
| 3685 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3686 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3687 | r = fill_yin_must(module, sub, &list->must[list->must_size]); |
| 3688 | list->must_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3689 | if (r) { |
| 3690 | goto error; |
| 3691 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 3692 | if (lyxp_syntax_check(list->must[list->must_size-1].expr, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3693 | goto error; |
| 3694 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3695 | } |
| 3696 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 3697 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 3698 | if (lys_node_addchild(parent, module->type ? ((struct lys_submodule *)module)->belongsto: module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3699 | goto error; |
| 3700 | } |
| 3701 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3702 | /* last part - process data nodes */ |
| 3703 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3704 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3705 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3706 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3707 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3708 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3709 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3710 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3711 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3712 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3713 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3714 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3715 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3716 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3717 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3718 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3719 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Michal Vasko | c07187d | 2015-08-13 15:20:57 +0200 | [diff] [blame] | 3720 | } else { |
| 3721 | LOGINT; |
| 3722 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3723 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3724 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3725 | goto error; |
| 3726 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3727 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3728 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3729 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3730 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3731 | if (!key_str) { |
| 3732 | /* config false list without a key */ |
| 3733 | return retval; |
| 3734 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3735 | if (unres_schema_add_str(module, unres, list, UNRES_LIST_KEYS, key_str, key_line) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3736 | goto error; |
| 3737 | } |
Radek Krejci | 812b10a | 2015-05-28 16:48:25 +0200 | [diff] [blame] | 3738 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3739 | /* process unique statements */ |
| 3740 | if (c_uniq) { |
| 3741 | list->unique = calloc(c_uniq, sizeof *list->unique); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3742 | if (!list->unique) { |
| 3743 | LOGMEM; |
| 3744 | goto error; |
| 3745 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3746 | } |
| 3747 | LY_TREE_FOR_SAFE(uniq.child, next, sub) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3748 | r = fill_yin_unique(module, retval, sub, &list->unique[list->unique_size], unres); |
| 3749 | list->unique_size++; |
| 3750 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3751 | goto error; |
| 3752 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 3753 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3754 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3755 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 3756 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3757 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3758 | |
| 3759 | error: |
| 3760 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 3761 | lys_node_free(retval, NULL); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3762 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3763 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3764 | } |
| 3765 | while (uniq.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3766 | lyxml_free(module->ctx, uniq.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3767 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3768 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3769 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3770 | } |
| 3771 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3772 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3773 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3774 | read_yin_container(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 3775 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3776 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3777 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3778 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3779 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3780 | struct lys_node_container *cont; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3781 | const char *value; |
| 3782 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3783 | int c_tpdf = 0, c_must = 0, c_ftrs = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3784 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3785 | /* init */ |
| 3786 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3787 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3788 | cont = calloc(1, sizeof *cont); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3789 | if (!cont) { |
| 3790 | LOGMEM; |
| 3791 | return NULL; |
| 3792 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3793 | cont->nodetype = LYS_CONTAINER; |
| 3794 | cont->prev = (struct lys_node *)cont; |
| 3795 | retval = (struct lys_node *)cont; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3796 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3797 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3798 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3799 | goto error; |
| 3800 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3801 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3802 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3803 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3804 | /* process container's specific children */ |
| 3805 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3806 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3807 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3808 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3809 | continue; |
| 3810 | } |
| 3811 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3812 | if (!strcmp(sub->name, "presence")) { |
| 3813 | if (cont->presence) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3814 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3815 | goto error; |
| 3816 | } |
| 3817 | GETVAL(value, sub, "value"); |
| 3818 | cont->presence = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 3819 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3820 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3821 | } else if (!strcmp(sub->name, "when")) { |
| 3822 | if (cont->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3823 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3824 | goto error; |
| 3825 | } |
| 3826 | |
| 3827 | cont->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3828 | if (!cont->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3829 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3830 | goto error; |
| 3831 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 3832 | if (lyxp_syntax_check(cont->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3833 | goto error; |
| 3834 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3835 | lyxml_free(module->ctx, sub); |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3836 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3837 | /* data statements */ |
| 3838 | } else if (!strcmp(sub->name, "container") || |
| 3839 | !strcmp(sub->name, "leaf-list") || |
| 3840 | !strcmp(sub->name, "leaf") || |
| 3841 | !strcmp(sub->name, "list") || |
| 3842 | !strcmp(sub->name, "choice") || |
| 3843 | !strcmp(sub->name, "uses") || |
| 3844 | !strcmp(sub->name, "grouping") || |
| 3845 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 3846 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3847 | lyxml_add_child(module->ctx, &root, sub); |
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 | /* array counters */ |
| 3850 | } else if (!strcmp(sub->name, "typedef")) { |
| 3851 | c_tpdf++; |
| 3852 | } else if (!strcmp(sub->name, "must")) { |
| 3853 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3854 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3855 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3856 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3857 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3858 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3859 | } |
| 3860 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3861 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3862 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3863 | if (c_tpdf) { |
| 3864 | cont->tpdf = calloc(c_tpdf, sizeof *cont->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3865 | if (!cont->tpdf) { |
| 3866 | LOGMEM; |
| 3867 | goto error; |
| 3868 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3869 | } |
| 3870 | if (c_must) { |
| 3871 | cont->must = calloc(c_must, sizeof *cont->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3872 | if (!cont->must) { |
| 3873 | LOGMEM; |
| 3874 | goto error; |
| 3875 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3876 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3877 | if (c_ftrs) { |
| 3878 | cont->features = calloc(c_ftrs, sizeof *cont->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3879 | if (!cont->features) { |
| 3880 | LOGMEM; |
| 3881 | goto error; |
| 3882 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3883 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 3884 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3885 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3886 | if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3887 | r = fill_yin_typedef(module, retval, sub, &cont->tpdf[cont->tpdf_size], unres); |
| 3888 | cont->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3889 | if (r) { |
| 3890 | goto error; |
| 3891 | } |
| 3892 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3893 | r = fill_yin_must(module, sub, &cont->must[cont->must_size]); |
| 3894 | cont->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3895 | if (r) { |
| 3896 | goto error; |
| 3897 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 3898 | if (lyxp_syntax_check(cont->must[cont->must_size-1].expr, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3899 | goto error; |
| 3900 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3901 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3902 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 3903 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3904 | goto error; |
| 3905 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3906 | /* hack - store pointer to the parent node for later status check */ |
| 3907 | cont->features[cont->features_size] = (struct lys_feature *)cont; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3908 | r = unres_schema_add_str(module, unres, &cont->features[cont->features_size], UNRES_IFFEAT, value, |
Radek Krejci | fe8582c | 2015-12-15 15:39:02 +0100 | [diff] [blame] | 3909 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3910 | cont->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3911 | lydict_remove(module->ctx, value); |
| 3912 | if (r == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3913 | goto error; |
| 3914 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3915 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3916 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3917 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 3918 | if (lys_node_addchild(parent, module->type ? ((struct lys_submodule *)module)->belongsto: module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 3919 | goto error; |
| 3920 | } |
| 3921 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3922 | /* last part - process data nodes */ |
| 3923 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3924 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3925 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3926 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3927 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3928 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3929 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3930 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3931 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3932 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3933 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3934 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3935 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3936 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3937 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3938 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3939 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3940 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3941 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3942 | goto error; |
| 3943 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3944 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3945 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3946 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3947 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3948 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3949 | |
| 3950 | error: |
| 3951 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 3952 | lys_node_free(retval, NULL); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3953 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3954 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3955 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3956 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3957 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3958 | } |
| 3959 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3960 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3961 | static struct lys_node * |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3962 | read_yin_grouping(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3963 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3964 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3965 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3966 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3967 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3968 | struct lys_node_grp *grp; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3969 | int r; |
| 3970 | int c_tpdf = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3971 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3972 | /* init */ |
| 3973 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3974 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3975 | grp = calloc(1, sizeof *grp); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3976 | if (!grp) { |
| 3977 | LOGMEM; |
| 3978 | return NULL; |
| 3979 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3980 | grp->nodetype = LYS_GROUPING; |
| 3981 | grp->prev = (struct lys_node *)grp; |
| 3982 | retval = (struct lys_node *)grp; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3983 | |
Michal Vasko | 71e1aa8 | 2015-08-12 12:17:51 +0200 | [diff] [blame] | 3984 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3985 | goto error; |
| 3986 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3987 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3988 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3989 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3990 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3991 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3992 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3993 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3994 | continue; |
| 3995 | } |
| 3996 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3997 | /* data statements */ |
| 3998 | if (!strcmp(sub->name, "container") || |
| 3999 | !strcmp(sub->name, "leaf-list") || |
| 4000 | !strcmp(sub->name, "leaf") || |
| 4001 | !strcmp(sub->name, "list") || |
| 4002 | !strcmp(sub->name, "choice") || |
| 4003 | !strcmp(sub->name, "uses") || |
| 4004 | !strcmp(sub->name, "grouping") || |
| 4005 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4006 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4007 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4008 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4009 | /* array counters */ |
| 4010 | } else if (!strcmp(sub->name, "typedef")) { |
| 4011 | c_tpdf++; |
| 4012 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4013 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4014 | goto error; |
| 4015 | } |
| 4016 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4017 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4018 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4019 | if (c_tpdf) { |
| 4020 | grp->tpdf = calloc(c_tpdf, sizeof *grp->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4021 | if (!grp->tpdf) { |
| 4022 | LOGMEM; |
| 4023 | goto error; |
| 4024 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4025 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4026 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4027 | r = fill_yin_typedef(module, retval, sub, &grp->tpdf[grp->tpdf_size], unres); |
| 4028 | grp->tpdf_size++; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4029 | if (r) { |
| 4030 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4031 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4032 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4033 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4034 | if (lys_node_addchild(parent, module->type ? ((struct lys_submodule *)module)->belongsto: module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4035 | goto error; |
| 4036 | } |
| 4037 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4038 | /* last part - process data nodes */ |
| 4039 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4040 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4041 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4042 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4043 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4044 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4045 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4046 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4047 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4048 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4049 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4050 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4051 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4052 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4053 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4054 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4055 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4056 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4057 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4058 | goto error; |
| 4059 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4060 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4061 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4062 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4063 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4064 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4065 | |
| 4066 | error: |
| 4067 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 4068 | lys_node_free(retval, NULL); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4069 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4070 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4071 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4072 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4073 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4074 | } |
| 4075 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4076 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4077 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4078 | read_yin_input_output(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 4079 | struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4080 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4081 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4082 | struct lys_node *node = NULL; |
Radek Krejci | 31fc30d | 2015-08-13 08:27:38 +0200 | [diff] [blame] | 4083 | struct lys_node *retval = NULL; |
Radek Krejci | 4608ada | 2015-08-05 16:04:37 +0200 | [diff] [blame] | 4084 | struct lys_node_rpc_inout *inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4085 | int r; |
| 4086 | int c_tpdf = 0; |
| 4087 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4088 | /* init */ |
| 4089 | memset(&root, 0, sizeof root); |
| 4090 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4091 | inout = calloc(1, sizeof *inout); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4092 | if (!inout) { |
| 4093 | LOGMEM; |
| 4094 | return NULL; |
| 4095 | } |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 4096 | inout->prev = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4097 | |
| 4098 | if (!strcmp(yin->name, "input")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4099 | inout->nodetype = LYS_INPUT; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4100 | } else if (!strcmp(yin->name, "output")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4101 | inout->nodetype = LYS_OUTPUT; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4102 | } else { |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 4103 | LOGINT; |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 4104 | free(inout); |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 4105 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4106 | } |
| 4107 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4108 | retval = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4109 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4110 | if (read_yin_common(module, parent, retval, yin, OPT_MODULE | OPT_NACMEXT)) { |
Michal Vasko | ebeac94 | 2015-06-15 12:11:50 +0200 | [diff] [blame] | 4111 | goto error; |
| 4112 | } |
| 4113 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4114 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4115 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4116 | /* data statements */ |
| 4117 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4118 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4119 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4120 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4121 | continue; |
| 4122 | } |
| 4123 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4124 | if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4125 | !strcmp(sub->name, "leaf-list") || |
| 4126 | !strcmp(sub->name, "leaf") || |
| 4127 | !strcmp(sub->name, "list") || |
| 4128 | !strcmp(sub->name, "choice") || |
| 4129 | !strcmp(sub->name, "uses") || |
| 4130 | !strcmp(sub->name, "grouping") || |
| 4131 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4132 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4133 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4134 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4135 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4136 | } else if (!strcmp(sub->name, "typedef")) { |
| 4137 | c_tpdf++; |
Radek Krejci | d2bfa79 | 2015-07-02 16:45:29 +0200 | [diff] [blame] | 4138 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4139 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4140 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4141 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4142 | } |
| 4143 | } |
| 4144 | |
| 4145 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4146 | if (c_tpdf) { |
| 4147 | inout->tpdf = calloc(c_tpdf, sizeof *inout->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4148 | if (!inout->tpdf) { |
| 4149 | LOGMEM; |
| 4150 | goto error; |
| 4151 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4152 | } |
| 4153 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4154 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4155 | r = fill_yin_typedef(module, retval, sub, &inout->tpdf[inout->tpdf_size], unres); |
| 4156 | inout->tpdf_size++; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4157 | if (r) { |
| 4158 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4159 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4160 | } |
| 4161 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4162 | if (lys_node_addchild(parent, module->type ? ((struct lys_submodule *)module)->belongsto: module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4163 | goto error; |
| 4164 | } |
| 4165 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4166 | /* last part - process data nodes */ |
| 4167 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4168 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4169 | node = read_yin_container(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4170 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4171 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4172 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4173 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4174 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4175 | node = read_yin_list(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4176 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4177 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4178 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4179 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4180 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4181 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4182 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4183 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4184 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4185 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4186 | goto error; |
| 4187 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4188 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4189 | lyxml_free(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4190 | } |
| 4191 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4192 | return retval; |
| 4193 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4194 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4195 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 4196 | lys_node_free(retval, NULL); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 4197 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4198 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4199 | } |
| 4200 | |
| 4201 | return NULL; |
| 4202 | } |
| 4203 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4204 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4205 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4206 | read_yin_notif(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 4207 | struct unres_schema *unres) |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4208 | { |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 4209 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4210 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4211 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4212 | struct lys_node_notif *notif; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4213 | const char *value; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4214 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4215 | int c_tpdf = 0, c_ftrs = 0; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4216 | |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 4217 | memset(&root, 0, sizeof root); |
| 4218 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4219 | notif = calloc(1, sizeof *notif); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4220 | if (!notif) { |
| 4221 | LOGMEM; |
| 4222 | return NULL; |
| 4223 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4224 | notif->nodetype = LYS_NOTIF; |
| 4225 | notif->prev = (struct lys_node *)notif; |
| 4226 | retval = (struct lys_node *)notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4227 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4228 | 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] | 4229 | goto error; |
| 4230 | } |
| 4231 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4232 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4233 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4234 | /* process rpc's specific children */ |
| 4235 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4236 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4237 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4238 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4239 | continue; |
| 4240 | } |
| 4241 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4242 | /* data statements */ |
| 4243 | if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4244 | !strcmp(sub->name, "leaf-list") || |
| 4245 | !strcmp(sub->name, "leaf") || |
| 4246 | !strcmp(sub->name, "list") || |
| 4247 | !strcmp(sub->name, "choice") || |
| 4248 | !strcmp(sub->name, "uses") || |
| 4249 | !strcmp(sub->name, "grouping") || |
| 4250 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4251 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4252 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4253 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4254 | /* array counters */ |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4255 | } else if (!strcmp(sub->name, "typedef")) { |
| 4256 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4257 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4258 | c_ftrs++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4259 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4260 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4261 | goto error; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4262 | } |
| 4263 | } |
| 4264 | |
| 4265 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4266 | if (c_tpdf) { |
| 4267 | notif->tpdf = calloc(c_tpdf, sizeof *notif->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4268 | if (!notif->tpdf) { |
| 4269 | LOGMEM; |
| 4270 | goto error; |
| 4271 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4272 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4273 | if (c_ftrs) { |
| 4274 | notif->features = calloc(c_ftrs, sizeof *notif->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4275 | if (!notif->features) { |
| 4276 | LOGMEM; |
| 4277 | goto error; |
| 4278 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4279 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4280 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4281 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4282 | if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4283 | r = fill_yin_typedef(module, retval, sub, ¬if->tpdf[notif->tpdf_size], unres); |
| 4284 | notif->tpdf_size++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4285 | if (r) { |
| 4286 | goto error; |
| 4287 | } |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 4288 | } else if (!strcmp(sub->name, "if-features")) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4289 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 4290 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 4291 | goto error; |
| 4292 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 4293 | /* hack - store pointer to the parent node for later status check */ |
| 4294 | notif->features[notif->features_size] = (struct lys_feature *)notif; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4295 | r = unres_schema_add_str(module, unres, ¬if->features[notif->features_size], UNRES_IFFEAT, value, |
Radek Krejci | fe8582c | 2015-12-15 15:39:02 +0100 | [diff] [blame] | 4296 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4297 | notif->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 4298 | lydict_remove(module->ctx, value); |
| 4299 | if (r == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4300 | goto error; |
| 4301 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4302 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4303 | } |
| 4304 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4305 | if (lys_node_addchild(parent, module->type ? ((struct lys_submodule *)module)->belongsto: module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4306 | goto error; |
| 4307 | } |
| 4308 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4309 | /* last part - process data nodes */ |
| 4310 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4311 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4312 | node = read_yin_container(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4313 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4314 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4315 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4316 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4317 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4318 | node = read_yin_list(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4319 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4320 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4321 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4322 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4323 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4324 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4325 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4326 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4327 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4328 | if (!node) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4329 | goto error; |
| 4330 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4331 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4332 | lyxml_free(module->ctx, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4333 | } |
| 4334 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4335 | return retval; |
| 4336 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4337 | error: |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4338 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 4339 | lys_node_free(retval, NULL); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4340 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4341 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4342 | } |
| 4343 | |
| 4344 | return NULL; |
| 4345 | } |
| 4346 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4347 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4348 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4349 | read_yin_rpc(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 4350 | struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4351 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4352 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4353 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4354 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4355 | struct lys_node_rpc *rpc; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4356 | const char *value; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4357 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4358 | int c_tpdf = 0, c_ftrs = 0; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4359 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4360 | /* init */ |
| 4361 | memset(&root, 0, sizeof root); |
| 4362 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4363 | rpc = calloc(1, sizeof *rpc); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4364 | if (!rpc) { |
| 4365 | LOGMEM; |
| 4366 | return NULL; |
| 4367 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4368 | rpc->nodetype = LYS_RPC; |
| 4369 | rpc->prev = (struct lys_node *)rpc; |
| 4370 | retval = (struct lys_node *)rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4371 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4372 | 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] | 4373 | goto error; |
| 4374 | } |
| 4375 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4376 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4377 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4378 | /* process rpc's specific children */ |
| 4379 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4380 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4381 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4382 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4383 | continue; |
| 4384 | } |
| 4385 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4386 | if (!strcmp(sub->name, "input")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4387 | if (rpc->child |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4388 | && (rpc->child->nodetype == LYS_INPUT |
| 4389 | || (rpc->child->next && rpc->child->next->nodetype == LYS_INPUT))) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4390 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4391 | goto error; |
| 4392 | } |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4393 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4394 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4395 | } else if (!strcmp(sub->name, "output")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4396 | if (rpc->child |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4397 | && (rpc->child->nodetype == LYS_INPUT |
| 4398 | || (rpc->child->next && rpc->child->next->nodetype == LYS_INPUT))) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4399 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4400 | goto error; |
| 4401 | } |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4402 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4403 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4404 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4405 | /* data statements */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4406 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4407 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4408 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4409 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4410 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4411 | } else if (!strcmp(sub->name, "typedef")) { |
| 4412 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4413 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4414 | c_ftrs++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4415 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4416 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4417 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4418 | } |
| 4419 | } |
| 4420 | |
| 4421 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4422 | if (c_tpdf) { |
| 4423 | rpc->tpdf = calloc(c_tpdf, sizeof *rpc->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4424 | if (!rpc->tpdf) { |
| 4425 | LOGMEM; |
| 4426 | goto error; |
| 4427 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4428 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4429 | if (c_ftrs) { |
| 4430 | rpc->features = calloc(c_ftrs, sizeof *rpc->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4431 | if (!rpc->features) { |
| 4432 | LOGMEM; |
| 4433 | goto error; |
| 4434 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4435 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4436 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4437 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4438 | if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4439 | r = fill_yin_typedef(module, retval, sub, &rpc->tpdf[rpc->tpdf_size], unres); |
| 4440 | rpc->tpdf_size++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4441 | if (r) { |
| 4442 | goto error; |
| 4443 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4444 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4445 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 4446 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 4447 | goto error; |
| 4448 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 4449 | /* hack - store pointer to the parent node for later status check */ |
| 4450 | rpc->features[rpc->features_size] = (struct lys_feature *)rpc; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4451 | r = unres_schema_add_str(module, unres, &rpc->features[rpc->features_size], UNRES_IFFEAT, value, |
Radek Krejci | fe8582c | 2015-12-15 15:39:02 +0100 | [diff] [blame] | 4452 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4453 | rpc->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 4454 | lydict_remove(module->ctx, value); |
| 4455 | if (r == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4456 | goto error; |
| 4457 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4458 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4459 | } |
| 4460 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4461 | if (lys_node_addchild(parent, module->type ? ((struct lys_submodule *)module)->belongsto: module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4462 | goto error; |
| 4463 | } |
| 4464 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4465 | /* last part - process data nodes */ |
| 4466 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4467 | if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4468 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4469 | } else if (!strcmp(sub->name, "input")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4470 | node = read_yin_input_output(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4471 | } else if (!strcmp(sub->name, "output")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4472 | node = read_yin_input_output(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4473 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4474 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4475 | goto error; |
| 4476 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4477 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4478 | lyxml_free(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4479 | } |
| 4480 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4481 | return retval; |
| 4482 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4483 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4484 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 4485 | lys_node_free(retval, NULL); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 4486 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4487 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4488 | } |
| 4489 | |
| 4490 | return NULL; |
| 4491 | } |
| 4492 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4493 | /* logs directly |
| 4494 | * |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4495 | * resolve - referenced grouping should be bounded to the namespace (resolved) |
| 4496 | * only when uses does not appear in grouping. In a case of grouping's uses, |
| 4497 | * we just get information but we do not apply augment or refine to it. |
| 4498 | */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4499 | static struct lys_node * |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4500 | read_yin_uses(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4501 | struct unres_schema *unres) |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4502 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4503 | struct lyxml_elem *sub, *next; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4504 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4505 | struct lys_node_uses *uses; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4506 | const char *value; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4507 | int c_ref = 0, c_aug = 0, c_ftrs = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4508 | int r; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4509 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4510 | uses = calloc(1, sizeof *uses); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4511 | if (!uses) { |
| 4512 | LOGMEM; |
| 4513 | return NULL; |
| 4514 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4515 | uses->nodetype = LYS_USES; |
| 4516 | uses->prev = (struct lys_node *)uses; |
| 4517 | retval = (struct lys_node *)uses; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4518 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4519 | GETVAL(value, yin, "name"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4520 | uses->name = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 4521 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 4522 | if (read_yin_common(module, parent, retval, yin, OPT_MODULE |
| 4523 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4524 | goto error; |
| 4525 | } |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4526 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4527 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4528 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4529 | /* get other properties of uses */ |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4530 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4531 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4532 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4533 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4534 | continue; |
| 4535 | } |
| 4536 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4537 | if (!strcmp(sub->name, "refine")) { |
| 4538 | c_ref++; |
| 4539 | } else if (!strcmp(sub->name, "augment")) { |
| 4540 | c_aug++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4541 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 56e8977 | 2015-06-19 10:00:54 +0200 | [diff] [blame] | 4542 | c_ftrs++; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4543 | } else if (!strcmp(sub->name, "when")) { |
| 4544 | if (uses->when) { |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4545 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4546 | goto error; |
| 4547 | } |
| 4548 | |
| 4549 | uses->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4550 | if (!uses->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4551 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4552 | goto error; |
| 4553 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 4554 | if (lyxp_syntax_check(uses->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4555 | goto error; |
| 4556 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4557 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4558 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4559 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4560 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4561 | } |
| 4562 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4563 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4564 | /* process properties with cardinality 0..n */ |
| 4565 | if (c_ref) { |
| 4566 | uses->refine = calloc(c_ref, sizeof *uses->refine); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4567 | if (!uses->refine) { |
| 4568 | LOGMEM; |
| 4569 | goto error; |
| 4570 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4571 | } |
| 4572 | if (c_aug) { |
| 4573 | uses->augment = calloc(c_aug, sizeof *uses->augment); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4574 | if (!uses->augment) { |
| 4575 | LOGMEM; |
| 4576 | goto error; |
| 4577 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4578 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4579 | if (c_ftrs) { |
| 4580 | uses->features = calloc(c_ftrs, sizeof *uses->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4581 | if (!uses->features) { |
| 4582 | LOGMEM; |
| 4583 | goto error; |
| 4584 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4585 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4586 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4587 | if (lys_node_addchild(parent, module->type ? ((struct lys_submodule *)module)->belongsto: module, retval)) { |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 4588 | goto error; |
| 4589 | } |
| 4590 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4591 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4592 | if (!strcmp(sub->name, "refine")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4593 | r = fill_yin_refine(module, sub, &uses->refine[uses->refine_size]); |
| 4594 | uses->refine_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4595 | if (r) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4596 | goto error; |
| 4597 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4598 | } else if (!strcmp(sub->name, "augment")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4599 | r = fill_yin_augment(module, retval, sub, &uses->augment[uses->augment_size], unres); |
| 4600 | uses->augment_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4601 | if (r) { |
| 4602 | goto error; |
| 4603 | } |
| 4604 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4605 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 4606 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 4607 | goto error; |
| 4608 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 4609 | /* hack - store pointer to the parent node for later status check */ |
| 4610 | uses->features[uses->features_size] = (struct lys_feature *)uses; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4611 | r = unres_schema_add_str(module, unres, &uses->features[uses->features_size], UNRES_IFFEAT, value, |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 4612 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4613 | uses->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 4614 | lydict_remove(module->ctx, value); |
| 4615 | if (r == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4616 | goto error; |
| 4617 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4618 | } |
| 4619 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4620 | |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 4621 | if (unres_schema_add_node(module, unres, uses, UNRES_USES, NULL, LOGLINE(yin)) == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4622 | goto error; |
| 4623 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4624 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4625 | if (resolve) { |
| 4626 | /* inherit config flag */ |
| 4627 | if (parent) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4628 | retval->flags |= parent->flags & LYS_CONFIG_MASK; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4629 | } else { |
| 4630 | /* default config is true */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4631 | retval->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4632 | } |
| 4633 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 4634 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4635 | return retval; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4636 | |
| 4637 | error: |
| 4638 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 4639 | lys_node_free(retval, NULL); |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4640 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4641 | return NULL; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4642 | } |
| 4643 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4644 | /* logs directly |
| 4645 | * |
| 4646 | * common code for yin_read_module() and yin_read_submodule() |
| 4647 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4648 | static int |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4649 | read_sub_module(struct lys_module *module, struct lys_submodule *submodule, struct lyxml_elem *yin, |
| 4650 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4651 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4652 | struct ly_ctx *ctx = module->ctx; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4653 | struct lyxml_elem *next, *child, *child2, root, grps, augs; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4654 | struct lys_node *node = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4655 | struct lys_module *trg; |
| 4656 | struct lys_import *aux_imp; |
| 4657 | struct lys_include *aux_inc, inc; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4658 | const char *value; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4659 | int i, j, r; |
| 4660 | int inc_size_aux = 0; |
| 4661 | int version_flag = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4662 | /* counters */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4663 | 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] | 4664 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4665 | /* to simplify code, store the module/submodule being processed as trg */ |
| 4666 | trg = submodule ? (struct lys_module*)submodule : module; |
| 4667 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4668 | /* init */ |
| 4669 | memset(&root, 0, sizeof root); |
| 4670 | memset(&grps, 0, sizeof grps); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4671 | memset(&augs, 0, sizeof augs); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4672 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4673 | /* |
| 4674 | * in the first run, we process elements with cardinality of 1 or 0..1 and |
| 4675 | * count elements with cardinality 0..n. Data elements (choices, containers, |
| 4676 | * leafs, lists, leaf-lists) are moved aside to be processed last, since we |
| 4677 | * need have all top-level and groupings already prepared at that time. In |
| 4678 | * the middle loop, we process other elements with carinality of 0..n since |
| 4679 | * we need to allocate arrays to store them. |
| 4680 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4681 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 4682 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4683 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4684 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4685 | continue; |
| 4686 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4687 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4688 | if (!submodule && !strcmp(child->name, "namespace")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4689 | if (module->ns) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4690 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4691 | goto error; |
| 4692 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4693 | GETVAL(value, child, "uri"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4694 | module->ns = lydict_insert(ctx, value, strlen(value)); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4695 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4696 | } else if (!submodule && !strcmp(child->name, "prefix")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4697 | if (module->prefix) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4698 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4699 | goto error; |
| 4700 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4701 | GETVAL(value, child, "value"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 4702 | if (lyp_check_identifier(value, LY_IDENT_PREFIX, LOGLINE(child), module, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4703 | goto error; |
| 4704 | } |
| 4705 | module->prefix = lydict_insert(ctx, value, strlen(value)); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4706 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4707 | } else if (submodule && !strcmp(child->name, "belongs-to")) { |
| 4708 | if (submodule->prefix) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4709 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4710 | goto error; |
| 4711 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4712 | GETVAL(value, child, "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4713 | if (value != submodule->belongsto->name) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4714 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4715 | goto error; |
| 4716 | } |
Radek Krejci | f388693 | 2015-06-04 17:36:06 +0200 | [diff] [blame] | 4717 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4718 | /* get the prefix substatement, start with checks */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4719 | if (!child->child) { |
| 4720 | LOGVAL(LYE_MISSSTMT2, LOGLINE(child), "prefix", child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4721 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4722 | } else if (strcmp(child->child->name, "prefix")) { |
| 4723 | LOGVAL(LYE_INSTMT, LOGLINE(child->child), child->child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4724 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4725 | } else if (child->child->next) { |
| 4726 | LOGVAL(LYE_INSTMT, LOGLINE(child->child->next), child->child->next->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4727 | goto error; |
| 4728 | } |
| 4729 | /* and now finally get the value */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4730 | GETVAL(value, child->child, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4731 | /* check here differs from a generic prefix check, since this prefix |
| 4732 | * don't have to be unique |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4733 | */ |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 4734 | if (lyp_check_identifier(value, LY_IDENT_NAME, LOGLINE(child->child), NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4735 | goto error; |
| 4736 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4737 | submodule->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 0af1387 | 2015-05-30 11:50:52 +0200 | [diff] [blame] | 4738 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4739 | /* we are done with belongs-to */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4740 | lyxml_free(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4741 | |
| 4742 | /* counters (statements with n..1 cardinality) */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4743 | } else if (!strcmp(child->name, "import")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4744 | c_imp++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4745 | } else if (!strcmp(child->name, "revision")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4746 | c_rev++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4747 | } else if (!strcmp(child->name, "typedef")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4748 | c_tpdf++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4749 | } else if (!strcmp(child->name, "identity")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4750 | c_ident++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4751 | } else if (!strcmp(child->name, "include")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4752 | c_inc++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4753 | } else if (!strcmp(child->name, "augment")) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4754 | c_aug++; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4755 | /* keep augments separated, processed last */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4756 | lyxml_unlink_elem(ctx, child, 2); |
| 4757 | lyxml_add_child(ctx, &augs, child); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4758 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4759 | } else if (!strcmp(child->name, "feature")) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4760 | c_ftrs++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4761 | } else if (!strcmp(child->name, "deviation")) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4762 | c_dev++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4763 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4764 | /* data statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4765 | } else if (!strcmp(child->name, "container") || |
| 4766 | !strcmp(child->name, "leaf-list") || |
| 4767 | !strcmp(child->name, "leaf") || |
| 4768 | !strcmp(child->name, "list") || |
| 4769 | !strcmp(child->name, "choice") || |
| 4770 | !strcmp(child->name, "uses") || |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 4771 | !strcmp(child->name, "anyxml") || |
| 4772 | !strcmp(child->name, "rpc") || |
| 4773 | !strcmp(child->name, "notification")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4774 | lyxml_unlink_elem(ctx, child, 2); |
| 4775 | lyxml_add_child(ctx, &root, child); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 4776 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4777 | } else if (!strcmp(child->name, "grouping")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4778 | /* keep groupings separated and process them before other data statements */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4779 | lyxml_unlink_elem(ctx, child, 2); |
| 4780 | lyxml_add_child(ctx, &grps, child); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4781 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4782 | /* optional statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4783 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4784 | if (trg->dsc) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4785 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4786 | goto error; |
| 4787 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4788 | trg->dsc = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4789 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4790 | if (!trg->dsc) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4791 | goto error; |
| 4792 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4793 | } else if (!strcmp(child->name, "reference")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4794 | if (trg->ref) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4795 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4796 | goto error; |
| 4797 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4798 | trg->ref = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4799 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4800 | if (!trg->ref) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4801 | goto error; |
| 4802 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4803 | } else if (!strcmp(child->name, "organization")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4804 | if (trg->org) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4805 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4806 | goto error; |
| 4807 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4808 | trg->org = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4809 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4810 | if (!trg->org) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4811 | goto error; |
| 4812 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4813 | } else if (!strcmp(child->name, "contact")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4814 | if (trg->contact) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4815 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4816 | goto error; |
| 4817 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4818 | trg->contact = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4819 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4820 | if (!trg->contact) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4821 | goto error; |
| 4822 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4823 | } else if (!strcmp(child->name, "yang-version")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4824 | /* TODO: support YANG 1.1 ? */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4825 | if (version_flag) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4826 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4827 | goto error; |
| 4828 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4829 | GETVAL(value, child, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4830 | if (strcmp(value, "1")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4831 | LOGVAL(LYE_INARG, LOGLINE(child), value, "yang-version"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4832 | goto error; |
| 4833 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4834 | version_flag = 1; |
| 4835 | if (!submodule) { |
| 4836 | module->version = 1; |
| 4837 | } /* TODO else check for the submodule's same version as in main module, waits for YANG 1.1 support */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4838 | lyxml_free(ctx, child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4839 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4840 | } else if (!strcmp(child->name, "extension")) { |
| 4841 | GETVAL(value, child, "name"); |
Radek Krejci | 5166a89 | 2015-07-02 16:44:24 +0200 | [diff] [blame] | 4842 | |
Radek Krejci | 3d46812 | 2015-10-02 13:36:12 +0200 | [diff] [blame] | 4843 | /* we have the following supported (hardcoded) extensions: */ |
| 4844 | /* ietf-netconf's get-filter-element-attributes */ |
| 4845 | if (!strcmp(module->ns, LY_NSNC) && |
| 4846 | !strcmp(value, "get-filter-element-attributes")) { |
| 4847 | LOGDBG("NETCONF filter extension found"); |
| 4848 | /* NACM's default-deny-write and default-deny-all */ |
| 4849 | } else if (!strcmp(module->ns, LY_NSNACM) && |
| 4850 | (!strcmp(value, "default-deny-write") || !strcmp(value, "default-deny-all"))) { |
| 4851 | LOGDBG("NACM extension found"); |
| 4852 | /* other extensions are not supported, so inform about such an extension */ |
| 4853 | } else { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 4854 | LOGWRN("Not supported \"%s\" extension statement found, ignoring.", value); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4855 | lyxml_free(ctx, child); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 4856 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4857 | } else { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4858 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4859 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4860 | } |
| 4861 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4862 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4863 | /* check for mandatory statements */ |
| 4864 | if (submodule && !submodule->prefix) { |
Michal Vasko | bdf51ef | 2015-12-10 12:11:21 +0100 | [diff] [blame] | 4865 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "belongs-to", "submodule"); |
| 4866 | goto error; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4867 | } else if (!submodule) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4868 | if (!module->ns) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4869 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "namespace", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4870 | goto error; |
| 4871 | } |
| 4872 | if (!module->prefix) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4873 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "prefix", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4874 | goto error; |
| 4875 | } |
| 4876 | } |
Radek Krejci | bb3257d | 2015-05-21 23:03:51 +0200 | [diff] [blame] | 4877 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4878 | /* allocate arrays for elements with cardinality of 0..n */ |
| 4879 | if (c_imp) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4880 | trg->imp = calloc(c_imp, sizeof *trg->imp); |
| 4881 | if (!trg->imp) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4882 | LOGMEM; |
| 4883 | goto error; |
| 4884 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4885 | } |
| 4886 | if (c_rev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4887 | trg->rev = calloc(c_rev, sizeof *trg->rev); |
| 4888 | if (!trg->rev) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4889 | LOGMEM; |
| 4890 | goto error; |
| 4891 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4892 | } |
| 4893 | if (c_tpdf) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4894 | trg->tpdf = calloc(c_tpdf, sizeof *trg->tpdf); |
| 4895 | if (!trg->tpdf) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4896 | LOGMEM; |
| 4897 | goto error; |
| 4898 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4899 | } |
| 4900 | if (c_ident) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4901 | trg->ident = calloc(c_ident, sizeof *trg->ident); |
| 4902 | if (!trg->ident) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4903 | LOGMEM; |
| 4904 | goto error; |
| 4905 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4906 | } |
| 4907 | if (c_inc) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4908 | trg->inc = calloc(c_inc, sizeof *trg->inc); |
| 4909 | if (!trg->inc) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4910 | LOGMEM; |
| 4911 | goto error; |
| 4912 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4913 | trg->inc_size = c_inc; |
| 4914 | /* trg->inc_size can be updated by the included submodules, |
| 4915 | * so we will use inc_size_aux here, trg->inc_size stores the |
| 4916 | * target size of the array |
| 4917 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4918 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4919 | if (c_aug) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4920 | trg->augment = calloc(c_aug, sizeof *trg->augment); |
| 4921 | if (!trg->augment) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4922 | LOGMEM; |
| 4923 | goto error; |
| 4924 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4925 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4926 | if (c_ftrs) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4927 | trg->features = calloc(c_ftrs, sizeof *trg->features); |
| 4928 | if (!trg->features) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4929 | LOGMEM; |
| 4930 | goto error; |
| 4931 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4932 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4933 | if (c_dev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4934 | trg->deviation = calloc(c_dev, sizeof *trg->deviation); |
| 4935 | if (!trg->deviation) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4936 | LOGMEM; |
| 4937 | goto error; |
| 4938 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4939 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4940 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4941 | /* middle part - process nodes with cardinality of 0..n except the data nodes and augments */ |
| 4942 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4943 | if (!strcmp(child->name, "import")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4944 | r = fill_yin_import(trg, child, &trg->imp[trg->imp_size]); |
| 4945 | trg->imp_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4946 | if (r) { |
| 4947 | goto error; |
| 4948 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4949 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4950 | /* check duplicities in imported modules */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4951 | for (i = 0; i < trg->imp_size - 1; i++) { |
| 4952 | if (!strcmp(trg->imp[i].module->name, trg->imp[trg->imp_size - 1].module->name)) { |
| 4953 | LOGVAL(LYE_SPEC, LOGLINE(child), "Importing module \"%s\" repeatedly.", trg->imp[i].module->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4954 | goto error; |
| 4955 | } |
| 4956 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4957 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4958 | } else if (!strcmp(child->name, "include")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4959 | memset(&inc, 0, sizeof inc); |
| 4960 | /* 1) pass module, not trg, since we want to pass the main module |
| 4961 | * 2) we cannot pass directly the structure in the array since |
| 4962 | * submodule parser can realloc our array of includes */ |
| 4963 | r = fill_yin_include(module, child, &inc, unres); |
| 4964 | memcpy(&trg->inc[inc_size_aux], &inc, sizeof inc); |
| 4965 | inc_size_aux++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4966 | if (r) { |
| 4967 | goto error; |
| 4968 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4969 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4970 | /* check duplications in include submodules */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4971 | for (i = 0; i < inc_size_aux - 1; i++) { |
| 4972 | if (!strcmp(trg->inc[i].submodule->name, trg->inc[inc_size_aux - 1].submodule->name)) { |
| 4973 | LOGVAL(LYE_SPEC, LOGLINE(child), "Including submodule \"%s\" repeatedly.", |
| 4974 | trg->inc[i].submodule->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4975 | goto error; |
| 4976 | } |
| 4977 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4978 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4979 | } else if (!strcmp(child->name, "revision")) { |
| 4980 | GETVAL(value, child, "date"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 4981 | if (lyp_check_date(value, LOGLINE(child))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4982 | goto error; |
| 4983 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4984 | memcpy(trg->rev[trg->rev_size].date, value, LY_REV_SIZE - 1); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4985 | /* check uniqueness of the revision date - not required by RFC */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4986 | for (i = 0; i < trg->rev_size; i++) { |
| 4987 | if (!strcmp(value, trg->rev[i].date)) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4988 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4989 | LOGVAL(LYE_SPEC, 0, "Revision is not unique."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4990 | } |
| 4991 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4992 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4993 | LY_TREE_FOR(child->child, child2) { |
| 4994 | if (!strcmp(child2->name, "description")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4995 | if (trg->rev[trg->rev_size].dsc) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4996 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child2->name, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4997 | goto error; |
| 4998 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4999 | trg->rev[trg->rev_size].dsc = read_yin_subnode(ctx, child2, "text"); |
| 5000 | if (!trg->rev[trg->rev_size].dsc) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5001 | goto error; |
| 5002 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5003 | } else if (!strcmp(child2->name, "reference")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5004 | if (trg->rev[trg->rev_size].ref) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5005 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child2->name, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5006 | goto error; |
| 5007 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5008 | trg->rev[trg->rev_size].ref = read_yin_subnode(ctx, child2, "text"); |
| 5009 | if (!trg->rev[trg->rev_size].ref) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5010 | goto error; |
| 5011 | } |
| 5012 | } else { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5013 | LOGVAL(LYE_INSTMT, LOGLINE(child2), child2->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5014 | goto error; |
| 5015 | } |
| 5016 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 5017 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5018 | /* keep the latest revision at position 0 */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5019 | if (trg->rev_size && strcmp(trg->rev[trg->rev_size].date, trg->rev[0].date) > 0) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5020 | /* switch their position */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5021 | value = strdup(trg->rev[0].date); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5022 | if (!value) { |
| 5023 | LOGMEM; |
| 5024 | goto error; |
| 5025 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5026 | memcpy(trg->rev[0].date, trg->rev[trg->rev_size].date, LY_REV_SIZE - 1); |
| 5027 | memcpy(trg->rev[trg->rev_size].date, value, LY_REV_SIZE - 1); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5028 | free((char *)value); |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 5029 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5030 | if (trg->rev[0].dsc != trg->rev[trg->rev_size].dsc) { |
| 5031 | value = trg->rev[0].dsc; |
| 5032 | trg->rev[0].dsc = trg->rev[trg->rev_size].dsc; |
| 5033 | trg->rev[trg->rev_size].dsc = value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5034 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 5035 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5036 | if (trg->rev[0].ref != trg->rev[trg->rev_size].ref) { |
| 5037 | value = trg->rev[0].ref; |
| 5038 | trg->rev[0].ref = trg->rev[trg->rev_size].ref; |
| 5039 | trg->rev[trg->rev_size].ref = value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5040 | } |
| 5041 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 5042 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5043 | trg->rev_size++; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5044 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5045 | } else if (!strcmp(child->name, "typedef")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5046 | r = fill_yin_typedef(trg, NULL, child, &trg->tpdf[trg->tpdf_size], unres); |
| 5047 | trg->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5048 | if (r) { |
| 5049 | goto error; |
| 5050 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5051 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5052 | } else if (!strcmp(child->name, "identity")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5053 | r = fill_yin_identity(trg, child, &trg->ident[trg->ident_size], unres); |
| 5054 | trg->ident_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5055 | if (r) { |
| 5056 | goto error; |
| 5057 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5058 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5059 | } else if (!strcmp(child->name, "feature")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5060 | r = fill_yin_feature(trg, child, &trg->features[trg->features_size], unres); |
| 5061 | trg->features_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5062 | if (r) { |
| 5063 | goto error; |
| 5064 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5065 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5066 | } else if (!strcmp(child->name, "deviation")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5067 | r = fill_yin_deviation(trg, child, &trg->deviation[trg->deviation_size], unres); |
| 5068 | trg->deviation_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 5069 | if (r) { |
| 5070 | goto error; |
| 5071 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5072 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5073 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5074 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5075 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5076 | if (submodule) { |
| 5077 | /* propagate imports into the main module */ |
| 5078 | for (i = r = 0; i < submodule->imp_size; i++) { |
| 5079 | for (j = 0; j < module->imp_size; j++) { |
| 5080 | if (submodule->imp[i].module == module->imp[j].module && |
| 5081 | !strcmp(submodule->imp[i].rev, module->imp[j].rev)) { |
| 5082 | /* check prefix match */ |
| 5083 | if (submodule->imp[i].prefix != module->imp[j].prefix) { |
| 5084 | LOGVAL(LYE_INID, LOGLINE(yin), submodule->imp[i].prefix, |
| 5085 | "non-matching prefixes of imported module in main module and submodule"); |
| 5086 | goto error; |
| 5087 | } |
| 5088 | break; |
| 5089 | } |
| 5090 | } |
| 5091 | if (j == module->imp_size) { |
| 5092 | /* new import */ |
| 5093 | r++; |
| 5094 | } |
| 5095 | } |
| 5096 | if (r) { |
| 5097 | aux_imp = realloc(module->imp, (module->imp_size + r) * sizeof *module->imp); |
| 5098 | if (!aux_imp) { |
| 5099 | LOGMEM; |
| 5100 | goto error; |
| 5101 | } |
| 5102 | module->imp = aux_imp; |
| 5103 | for (i = r = 0; i < submodule->imp_size; i++) { |
| 5104 | for (j = 0; j < module->imp_size; j++) { |
| 5105 | if (submodule->imp[i].module == module->imp[j].module) { |
| 5106 | break; |
| 5107 | } |
| 5108 | } |
| 5109 | if (j == module->imp_size) { |
| 5110 | /* new import */ |
| 5111 | /* check prefix uniqueness */ |
| 5112 | if (dup_prefix_check(submodule->imp[i].prefix, module)) { |
| 5113 | LOGVAL(LYE_DUPID, LOGLINE(yin), "prefix", submodule->imp[i].prefix); |
| 5114 | goto error; |
| 5115 | } |
| 5116 | memcpy(&module->imp[module->imp_size + r], &submodule->imp[i], sizeof *submodule->imp); |
| 5117 | module->imp[module->imp_size + r].external = 1; |
| 5118 | r++; |
| 5119 | } |
| 5120 | } |
| 5121 | module->imp_size += r; |
| 5122 | } |
| 5123 | |
| 5124 | /* propagate imports into the main module */ |
| 5125 | for (i = r = 0; i < submodule->inc_size; i++) { |
| 5126 | for (j = 0; j < module->inc_size; j++) { |
| 5127 | if (submodule->inc[i].submodule == module->inc[j].submodule) { |
| 5128 | break; |
| 5129 | } |
| 5130 | } |
| 5131 | if (j == module->inc_size) { |
| 5132 | /* new include */ |
| 5133 | r++; |
| 5134 | } |
| 5135 | } |
| 5136 | |
| 5137 | if (r) { |
| 5138 | aux_inc = realloc(module->inc, (module->inc_size + r) * sizeof *module->inc); |
| 5139 | if (!aux_inc) { |
| 5140 | LOGMEM; |
| 5141 | goto error; |
| 5142 | } |
| 5143 | module->inc = aux_inc; |
| 5144 | for (i = r = 0; i < submodule->inc_size; i++) { |
| 5145 | for (j = 0; j < module->inc_size; j++) { |
| 5146 | if (submodule->inc[i].submodule == module->inc[j].submodule) { |
| 5147 | break; |
| 5148 | } |
| 5149 | } |
| 5150 | if (j == module->inc_size) { |
| 5151 | /* new include */ |
| 5152 | memcpy(&module->inc[module->inc_size + r], &submodule->inc[i], sizeof *submodule->inc); |
| 5153 | module->inc[module->inc_size + r].external = 1; |
| 5154 | r++; |
| 5155 | } |
| 5156 | } |
| 5157 | module->inc_size += r; |
| 5158 | } |
| 5159 | } |
| 5160 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5161 | /* process data nodes. Start with groupings to allow uses |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5162 | * refer to them. Submodule's data nodes are stored in the |
| 5163 | * main module data tree. |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5164 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5165 | LY_TREE_FOR_SAFE(grps.child, next, child) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5166 | node = read_yin_grouping(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5167 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5168 | goto error; |
| 5169 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 5170 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5171 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5172 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 5173 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5174 | /* parse data nodes, ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5175 | LY_TREE_FOR_SAFE(root.child, next, child) { |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5176 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5177 | if (!strcmp(child->name, "container")) { |
| 5178 | node = read_yin_container(module, NULL, child, 1, unres); |
| 5179 | } else if (!strcmp(child->name, "leaf-list")) { |
| 5180 | node = read_yin_leaflist(module, NULL, child, 1, unres); |
| 5181 | } else if (!strcmp(child->name, "leaf")) { |
| 5182 | node = read_yin_leaf(module, NULL, child, 1, unres); |
| 5183 | } else if (!strcmp(child->name, "list")) { |
| 5184 | node = read_yin_list(module, NULL, child, 1, unres); |
| 5185 | } else if (!strcmp(child->name, "choice")) { |
| 5186 | node = read_yin_choice(module, NULL, child, 1, unres); |
| 5187 | } else if (!strcmp(child->name, "uses")) { |
| 5188 | node = read_yin_uses(module, NULL, child, 1, unres); |
| 5189 | } else if (!strcmp(child->name, "anyxml")) { |
| 5190 | node = read_yin_anyxml(module, NULL, child, 1, unres); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 5191 | } else if (!strcmp(child->name, "rpc")) { |
| 5192 | node = read_yin_rpc(module, NULL, child, 0, unres); |
| 5193 | } else if (!strcmp(child->name, "notification")) { |
| 5194 | node = read_yin_notif(module, NULL, child, 0, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5195 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5196 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5197 | goto error; |
| 5198 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 5199 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5200 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5201 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5202 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5203 | /* ... and finally augments (last, so we can augment our data, for instance) */ |
| 5204 | LY_TREE_FOR_SAFE(augs.child, next, child) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5205 | r = fill_yin_augment(trg, NULL, child, &trg->augment[trg->augment_size], unres); |
| 5206 | trg->augment_size++; |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5207 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5208 | if (r) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5209 | goto error; |
| 5210 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5211 | lyxml_free(ctx, child); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5212 | } |
| 5213 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5214 | return EXIT_SUCCESS; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5215 | |
| 5216 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5217 | /* cleanup */ |
| 5218 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5219 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5220 | } |
| 5221 | while (grps.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5222 | lyxml_free(module->ctx, grps.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5223 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5224 | while (augs.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5225 | lyxml_free(module->ctx, augs.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5226 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5227 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5228 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5229 | } |
| 5230 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5231 | /* logs directly */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5232 | struct lys_submodule * |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5233 | yin_read_submodule(struct lys_module *module, const char *data, struct unres_schema *unres) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5234 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5235 | struct lyxml_elem *yin; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5236 | struct lys_submodule *submodule = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5237 | const char *value; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5238 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5239 | assert(module->ctx); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5240 | |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 5241 | yin = lyxml_parse_mem(module->ctx, data, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5242 | if (!yin) { |
| 5243 | return NULL; |
| 5244 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5245 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5246 | /* check root element */ |
| 5247 | if (!yin->name || strcmp(yin->name, "submodule")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 5248 | LOGVAL(LYE_INSTMT, LOGLINE(yin), yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5249 | goto error; |
| 5250 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5251 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5252 | GETVAL(value, yin, "name"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 5253 | if (lyp_check_identifier(value, LY_IDENT_NAME, LOGLINE(yin), NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5254 | goto error; |
| 5255 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5256 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5257 | submodule = calloc(1, sizeof *submodule); |
| 5258 | if (!submodule) { |
| 5259 | LOGMEM; |
| 5260 | goto error; |
| 5261 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5262 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5263 | submodule->ctx = module->ctx; |
| 5264 | submodule->name = lydict_insert(submodule->ctx, value, strlen(value)); |
| 5265 | submodule->type = 1; |
| 5266 | submodule->belongsto = module; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5267 | |
Michal Vasko | e0b627e | 2015-10-21 15:08:32 +0200 | [diff] [blame] | 5268 | LOGVRB("Reading submodule %s", submodule->name); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5269 | if (read_sub_module(module, submodule, yin, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5270 | goto error; |
| 5271 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5272 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5273 | /* cleanup */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5274 | lyxml_free(module->ctx, yin); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5275 | |
Michal Vasko | e0b627e | 2015-10-21 15:08:32 +0200 | [diff] [blame] | 5276 | LOGVRB("Submodule %s successfully parsed", submodule->name); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5277 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5278 | return submodule; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5279 | |
| 5280 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5281 | /* cleanup */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5282 | unres_schema_free((struct lys_module *)submodule, &unres); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5283 | lyxml_free(module->ctx, yin); |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 5284 | lys_submodule_free(submodule, 0, NULL); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5285 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5286 | return NULL; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5287 | } |
| 5288 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5289 | /* logs directly */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5290 | struct lys_module * |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5291 | yin_read_module(struct ly_ctx *ctx, const char *data, int implement) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5292 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5293 | struct lyxml_elem *yin; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5294 | struct lys_module *module = NULL, **newlist = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5295 | struct unres_schema *unres; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5296 | const char *value; |
| 5297 | int i; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5298 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5299 | unres = calloc(1, sizeof *unres); |
| 5300 | if (!unres) { |
| 5301 | LOGMEM; |
| 5302 | return NULL; |
| 5303 | } |
| 5304 | |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 5305 | yin = lyxml_parse_mem(ctx, data, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5306 | if (!yin) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5307 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5308 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5309 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5310 | /* check root element */ |
| 5311 | if (!yin->name || strcmp(yin->name, "module")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 5312 | LOGVAL(LYE_INSTMT, LOGLINE(yin), yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5313 | goto error; |
| 5314 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5315 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5316 | GETVAL(value, yin, "name"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 5317 | if (lyp_check_identifier(value, LY_IDENT_NAME, LOGLINE(yin), NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5318 | goto error; |
| 5319 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5320 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5321 | module = calloc(1, sizeof *module); |
| 5322 | if (!module) { |
| 5323 | LOGMEM; |
| 5324 | goto error; |
| 5325 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5326 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5327 | module->ctx = ctx; |
| 5328 | module->name = lydict_insert(ctx, value, strlen(value)); |
| 5329 | module->type = 0; |
Michal Vasko | d8aa32d | 2015-07-24 11:50:01 +0200 | [diff] [blame] | 5330 | module->implemented = (implement ? 1 : 0); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5331 | |
Michal Vasko | e0b627e | 2015-10-21 15:08:32 +0200 | [diff] [blame] | 5332 | LOGVRB("Reading module %s", module->name); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5333 | if (read_sub_module(module, NULL, yin, unres)) { |
| 5334 | goto error; |
| 5335 | } |
| 5336 | |
| 5337 | /* resolve rest of unres items */ |
| 5338 | if (unres->count && resolve_unres_schema(module, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5339 | goto error; |
| 5340 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5341 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5342 | /* add to the context's list of modules */ |
| 5343 | if (ctx->models.used == ctx->models.size) { |
Michal Vasko | f2e1a99 | 2015-11-09 09:54:47 +0100 | [diff] [blame] | 5344 | newlist = realloc(ctx->models.list, (2 * ctx->models.size) * sizeof *newlist); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5345 | if (!newlist) { |
| 5346 | LOGMEM; |
| 5347 | goto error; |
| 5348 | } |
| 5349 | for (i = ctx->models.size; i < ctx->models.size * 2; i++) { |
| 5350 | newlist[i] = NULL; |
| 5351 | } |
| 5352 | ctx->models.size *= 2; |
| 5353 | ctx->models.list = newlist; |
| 5354 | } |
| 5355 | for (i = 0; ctx->models.list[i]; i++) { |
| 5356 | /* check name (name/revision) and namespace uniqueness */ |
| 5357 | if (!strcmp(ctx->models.list[i]->name, module->name)) { |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 5358 | if (ctx->models.list[i]->rev_size == module->rev_size) { |
| 5359 | /* both have the same number of revisions */ |
| 5360 | if (!module->rev_size || !strcmp(ctx->models.list[i]->rev[0].date, module->rev[0].date)) { |
| 5361 | /* both have the same revision -> we already have the same module */ |
| 5362 | /* so free the new one and update the old one's implement flag if needed */ |
Michal Vasko | e0b627e | 2015-10-21 15:08:32 +0200 | [diff] [blame] | 5363 | LOGVRB("Module %s already in context", ctx->models.list[i]->name); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 5364 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 5365 | lys_free(module, 0, NULL); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5366 | module = ctx->models.list[i]; |
| 5367 | if (implement && !module->implemented) { |
| 5368 | lyp_set_implemented(module); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 5369 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5370 | |
| 5371 | goto success; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5372 | } |
| 5373 | } |
Radek Krejci | f647e61 | 2015-07-30 11:36:07 +0200 | [diff] [blame] | 5374 | /* else (both elses) keep searching, for now the caller is just adding |
| 5375 | * another revision of an already present schema |
| 5376 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5377 | } else if (!strcmp(ctx->models.list[i]->ns, module->ns)) { |
| 5378 | LOGERR(LY_EINVAL, "Two different modules (\"%s\" and \"%s\") have the same namespace \"%s\"", |
| 5379 | ctx->models.list[i]->name, module->name, module->ns); |
| 5380 | goto error; |
| 5381 | } |
| 5382 | } |
| 5383 | ctx->models.list[i] = module; |
| 5384 | ctx->models.used++; |
Michal Vasko | 68cffd7 | 2015-08-03 12:50:11 +0200 | [diff] [blame] | 5385 | ctx->models.module_set_id++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5386 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5387 | success: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5388 | /* cleanup */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5389 | lyxml_free(ctx, yin); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5390 | unres_schema_free(NULL, &unres); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5391 | |
Michal Vasko | e0b627e | 2015-10-21 15:08:32 +0200 | [diff] [blame] | 5392 | LOGVRB("Module %s successfully parsed", module->name); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5393 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5394 | return module; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5395 | |
| 5396 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5397 | /* cleanup */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5398 | unres_schema_free(module, &unres); |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 5399 | lys_free(module, 0, NULL); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5400 | lyxml_free(ctx, yin); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5401 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5402 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5403 | } |