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)) { |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 88 | LOGERR(LY_EVALID, "Expected \"%s\" element in \"%s\" element.", name, node->name); |
| 89 | LOGVAL(LYE_INARG, LOGLINE(node), name, node->name); |
| 90 | return NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 91 | } else if (node->child->content) { |
| 92 | len = strlen(node->child->content); |
| 93 | return lydict_insert(ctx, node->child->content, len); |
Radek Krejci | 218436d | 2016-02-10 12:54:06 +0100 | [diff] [blame] | 94 | } else { |
| 95 | return lydict_insert(ctx, "", 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 96 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 97 | } |
| 98 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 99 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 100 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 101 | 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] | 102 | { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 103 | struct lyxml_elem *node; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 104 | const char *value; |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 105 | int base_flag = 0; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 106 | |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 107 | GETVAL(value, yin, "name"); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 108 | ident->name = value; |
Michal Vasko | 4cfcd25 | 2015-08-03 14:31:10 +0200 | [diff] [blame] | 109 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 110 | 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] | 111 | return EXIT_FAILURE; |
| 112 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 113 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 114 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 115 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 116 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 117 | continue; |
| 118 | } |
| 119 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 120 | if (!strcmp(node->name, "base")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 121 | if (base_flag) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 122 | LOGVAL(LYE_TOOMANY, LOGLINE(node), "base", "identity"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 123 | return EXIT_FAILURE; |
| 124 | } |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 125 | base_flag = 1; |
| 126 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 127 | GETVAL(value, node, "name"); |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 128 | value = transform_schema2json(module, value, LOGLINE(node)); |
| 129 | if (!value) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 130 | return EXIT_FAILURE; |
| 131 | } |
Michal Vasko | c94283a | 2015-10-29 09:07:20 +0100 | [diff] [blame] | 132 | |
| 133 | if (unres_schema_add_str(module, unres, ident, UNRES_IDENT, value, LOGLINE(node)) == -1) { |
| 134 | lydict_remove(module->ctx, value); |
| 135 | return EXIT_FAILURE; |
| 136 | } |
| 137 | lydict_remove(module->ctx, value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 138 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 139 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name, "identity"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 140 | return EXIT_FAILURE; |
| 141 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 142 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 143 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 144 | return EXIT_SUCCESS; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 145 | |
| 146 | error: |
| 147 | return EXIT_FAILURE; |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 148 | } |
| 149 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 150 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 151 | static int |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 152 | 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] | 153 | { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 154 | struct lyxml_elem *child; |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 155 | const char *value; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 156 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 157 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 158 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 159 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 160 | continue; |
| 161 | } |
| 162 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 163 | if (!strcmp(child->name, "description")) { |
| 164 | if (restr->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 165 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 166 | return EXIT_FAILURE; |
| 167 | } |
| 168 | restr->dsc = read_yin_subnode(ctx, child, "text"); |
| 169 | if (!restr->dsc) { |
| 170 | return EXIT_FAILURE; |
| 171 | } |
| 172 | } else if (!strcmp(child->name, "reference")) { |
| 173 | if (restr->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 174 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 175 | return EXIT_FAILURE; |
| 176 | } |
| 177 | restr->ref = read_yin_subnode(ctx, child, "text"); |
| 178 | if (!restr->ref) { |
| 179 | return EXIT_FAILURE; |
| 180 | } |
| 181 | } else if (!strcmp(child->name, "error-app-tag")) { |
| 182 | if (restr->eapptag) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 183 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 184 | return EXIT_FAILURE; |
| 185 | } |
Michal Vasko | 54e426f | 2015-07-07 15:38:02 +0200 | [diff] [blame] | 186 | GETVAL(value, child, "value"); |
Radek Krejci | 461d162 | 2015-06-30 14:06:28 +0200 | [diff] [blame] | 187 | restr->eapptag = lydict_insert(ctx, value, 0); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 188 | } else if (!strcmp(child->name, "error-message")) { |
| 189 | if (restr->emsg) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 190 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 191 | return EXIT_FAILURE; |
| 192 | } |
| 193 | restr->emsg = read_yin_subnode(ctx, child, "value"); |
| 194 | if (!restr->emsg) { |
| 195 | return EXIT_FAILURE; |
| 196 | } |
| 197 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 198 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 199 | return EXIT_FAILURE; |
| 200 | } |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | return EXIT_SUCCESS; |
Michal Vasko | c8ef47f | 2015-06-29 14:56:19 +0200 | [diff] [blame] | 204 | |
| 205 | error: |
| 206 | return EXIT_FAILURE; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 207 | } |
| 208 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 209 | /* logs directly, returns EXIT_SUCCESS, EXIT_FAILURE, -1 */ |
| 210 | int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 211 | 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] | 212 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 213 | { |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 214 | const char *value, *name, *err_ptr; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 215 | struct lyxml_elem *next, *node; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 216 | struct lys_restr **restr; |
| 217 | struct lys_type_bit bit; |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 218 | pcre *precomp; |
| 219 | int i, j, rc, err_offset; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 220 | int64_t v, v_; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 221 | int64_t p, p_; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 222 | |
Radek Krejci | 8de7b0f | 2015-07-02 11:43:42 +0200 | [diff] [blame] | 223 | GETVAL(value, yin, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 224 | value = transform_schema2json(module, value, LOGLINE(yin)); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 225 | if (!value) { |
| 226 | goto error; |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 227 | } |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 228 | |
| 229 | i = parse_identifier(value); |
| 230 | if (i < 1) { |
Michal Vasko | 0160ffe | 2015-10-21 13:25:26 +0200 | [diff] [blame] | 231 | LOGVAL(LYE_INCHAR, LOGLINE(yin), value[-i], &value[-i]); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 232 | lydict_remove(module->ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 233 | goto error; |
| 234 | } |
| 235 | /* module name */ |
| 236 | if (value[i]) { |
| 237 | type->module_name = lydict_insert(module->ctx, value, i); |
| 238 | value += i; |
Michal Vasko | 534f844 | 2015-10-21 13:25:49 +0200 | [diff] [blame] | 239 | if ((value[0] != ':') || (parse_identifier(value + 1) < 1)) { |
Michal Vasko | 0160ffe | 2015-10-21 13:25:26 +0200 | [diff] [blame] | 240 | LOGVAL(LYE_INCHAR, LOGLINE(yin), value[0], value); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 241 | lydict_remove(module->ctx, value); |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 242 | goto error; |
| 243 | } |
Michal Vasko | 534f844 | 2015-10-21 13:25:49 +0200 | [diff] [blame] | 244 | ++value; |
Michal Vasko | b362b4c | 2015-10-20 15:15:46 +0200 | [diff] [blame] | 245 | } |
Michal Vasko | a5835e9 | 2015-10-20 15:07:39 +0200 | [diff] [blame] | 246 | |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 247 | rc = resolve_superior_type(value, type->module_name, module, parent, &type->der); |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 248 | lydict_remove(module->ctx, value); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 249 | if (rc == -1) { |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 250 | LOGVAL(LYE_INMOD, LOGLINE(yin), type->module_name); |
Michal Vasko | f7eee89 | 2015-08-24 15:03:11 +0200 | [diff] [blame] | 251 | goto error; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 252 | |
| 253 | /* 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] | 254 | } else if (rc == EXIT_FAILURE) { |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 255 | return EXIT_FAILURE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 256 | } |
| 257 | type->base = type->der->type.base; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 258 | |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 259 | /* check status */ |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 260 | 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] | 261 | type->der->flags, type->der->module, type->der->name, LOGLINE(yin))) { |
| 262 | return -1; |
| 263 | } |
| 264 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 265 | switch (type->base) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 266 | case LY_TYPE_BITS: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 267 | /* RFC 6020 9.7.4 - bit */ |
| 268 | |
| 269 | /* get bit specifications, at least one must be present */ |
| 270 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 271 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 272 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 273 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 274 | continue; |
| 275 | } |
| 276 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 277 | if (!strcmp(node->name, "bit")) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 278 | type->info.bits.count++; |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 279 | } else { |
Michal Vasko | e29c662 | 2015-11-27 15:02:31 +0100 | [diff] [blame] | 280 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 281 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 282 | } |
| 283 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 284 | if (!type->der->type.der && !type->info.bits.count) { |
| 285 | /* 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] | 286 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "bit", "type"); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 287 | goto error; |
| 288 | } |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 289 | if (type->der->type.der && type->info.bits.count) { |
| 290 | /* 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] | 291 | LOGVAL(LYE_INSTMT, LOGLINE(yin), "bit"); |
Radek Krejci | ac78192 | 2015-07-09 15:35:14 +0200 | [diff] [blame] | 292 | goto error; |
| 293 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 294 | |
| 295 | 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] | 296 | if (!type->info.bits.bit) { |
| 297 | LOGMEM; |
| 298 | goto error; |
| 299 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 300 | p = 0; |
| 301 | i = -1; |
| 302 | LY_TREE_FOR(yin->child, next) { |
| 303 | i++; |
| 304 | |
| 305 | GETVAL(value, next, "name"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 306 | if (lyp_check_identifier(value, LY_IDENT_SIMPLE, LOGLINE(next), NULL, NULL)) { |
Michal Vasko | 2d26a02 | 2015-12-07 09:27:21 +0100 | [diff] [blame] | 307 | goto error; |
| 308 | } |
| 309 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 310 | 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] | 311 | 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] | 312 | type->info.bits.count = i + 1; |
| 313 | goto error; |
| 314 | } |
| 315 | |
| 316 | /* check the name uniqueness */ |
| 317 | for (j = 0; j < i; j++) { |
| 318 | 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] | 319 | LOGVAL(LYE_BITS_DUPNAME, LOGLINE(next), type->info.bits.bit[i].name); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 320 | type->info.bits.count = i + 1; |
| 321 | goto error; |
| 322 | } |
| 323 | } |
| 324 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 325 | p_ = -1; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 326 | LY_TREE_FOR(next->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 327 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 328 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 329 | continue; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 330 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 331 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 332 | if (!strcmp(node->name, "position")) { |
| 333 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 334 | p_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 335 | |
| 336 | /* range check */ |
Radek Krejci | b8ca108 | 2015-07-10 11:24:11 +0200 | [diff] [blame] | 337 | if (p_ < 0 || p_ > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 338 | LOGVAL(LYE_INARG, LOGLINE(node), value, "bit/position"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 339 | type->info.bits.count = i + 1; |
| 340 | goto error; |
| 341 | } |
| 342 | type->info.bits.bit[i].pos = (uint32_t)p_; |
| 343 | |
| 344 | /* keep the highest enum value for automatic increment */ |
Michal Vasko | 9ab0594 | 2015-07-07 15:38:26 +0200 | [diff] [blame] | 345 | if (type->info.bits.bit[i].pos >= p) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 346 | p = type->info.bits.bit[i].pos; |
| 347 | p++; |
| 348 | } else { |
| 349 | /* check that the value is unique */ |
| 350 | for (j = 0; j < i; j++) { |
| 351 | 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] | 352 | 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] | 353 | type->info.bits.count = i + 1; |
| 354 | goto error; |
| 355 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 356 | } |
| 357 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 358 | } else { |
Michal Vasko | e29c662 | 2015-11-27 15:02:31 +0100 | [diff] [blame] | 359 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 360 | goto error; |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 361 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 362 | } |
| 363 | if (p_ == -1) { |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 364 | /* assign value automatically */ |
| 365 | if (p > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 366 | LOGVAL(LYE_INARG, LOGLINE(next), "4294967295", "bit/position"); |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 367 | type->info.bits.count = i + 1; |
| 368 | goto error; |
| 369 | } |
| 370 | type->info.bits.bit[i].pos = (uint32_t)p; |
| 371 | p++; |
| 372 | } |
Radek Krejci | 9a1b95a | 2015-07-09 15:32:21 +0200 | [diff] [blame] | 373 | |
| 374 | /* keep them ordered by position */ |
| 375 | j = i; |
| 376 | while (j && type->info.bits.bit[j - 1].pos > type->info.bits.bit[j].pos) { |
| 377 | /* switch them */ |
| 378 | memcpy(&bit, &type->info.bits.bit[j], sizeof bit); |
| 379 | memcpy(&type->info.bits.bit[j], &type->info.bits.bit[j - 1], sizeof bit); |
| 380 | memcpy(&type->info.bits.bit[j - 1], &bit, sizeof bit); |
| 381 | j--; |
| 382 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 383 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 384 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 385 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 386 | case LY_TYPE_DEC64: |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 387 | /* RFC 6020 9.2.4 - range and 9.3.4 - fraction-digits */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 388 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 389 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 390 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 391 | continue; |
| 392 | } |
| 393 | |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 394 | if (!strcmp(node->name, "range")) { |
| 395 | if (type->info.dec64.range) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 396 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 397 | goto error; |
| 398 | } |
| 399 | |
| 400 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 401 | if (lyp_check_length_range(value, type)) { |
Michal Vasko | 9c1bc64 | 2015-08-05 16:25:53 +0200 | [diff] [blame] | 402 | LOGVAL(LYE_INARG, LOGLINE(node), value, "range"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 403 | goto error; |
| 404 | } |
| 405 | type->info.dec64.range = calloc(1, sizeof *type->info.dec64.range); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 406 | if (!type->info.dec64.range) { |
| 407 | LOGMEM; |
| 408 | goto error; |
| 409 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 410 | type->info.dec64.range->expr = lydict_insert(module->ctx, value, 0); |
| 411 | |
| 412 | /* get possible substatements */ |
| 413 | if (read_restr_substmt(module->ctx, type->info.dec64.range, node)) { |
| 414 | goto error; |
| 415 | } |
| 416 | } else if (!strcmp(node->name, "fraction-digits")) { |
| 417 | if (type->info.dec64.dig) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 418 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 419 | goto error; |
| 420 | } |
| 421 | GETVAL(value, node, "value"); |
| 422 | v = strtol(value, NULL, 10); |
| 423 | |
| 424 | /* range check */ |
| 425 | if (v < 1 || v > 18) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 426 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 427 | goto error; |
| 428 | } |
| 429 | type->info.dec64.dig = (uint8_t)v; |
| 430 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 431 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 432 | goto error; |
| 433 | } |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | /* mandatory sub-statement(s) check */ |
| 437 | if (!type->info.dec64.dig && !type->der->type.der) { |
| 438 | /* decimal64 type directly derived from built-in type requires fraction-digits */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 439 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "fraction-digits", "type"); |
Radek Krejci | f9401c3 | 2015-06-26 16:47:36 +0200 | [diff] [blame] | 440 | goto error; |
| 441 | } |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 442 | if (type->info.dec64.dig && type->der->type.der) { |
| 443 | /* 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] | 444 | LOGVAL(LYE_INSTMT, LOGLINE(yin), "fraction-digits"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 445 | goto error; |
| 446 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 447 | break; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 448 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 449 | case LY_TYPE_ENUM: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 450 | /* RFC 6020 9.6 - enum */ |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 451 | |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 452 | /* get enum specifications, at least one must be present */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 453 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 454 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 455 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 456 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 457 | continue; |
| 458 | } |
| 459 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 460 | if (!strcmp(node->name, "enum")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 461 | type->info.enums.count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 462 | } else { |
Michal Vasko | e29c662 | 2015-11-27 15:02:31 +0100 | [diff] [blame] | 463 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 464 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 465 | } |
| 466 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 467 | if (!type->der->type.der && !type->info.enums.count) { |
| 468 | /* 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] | 469 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "enum", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 470 | goto error; |
| 471 | } |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 472 | if (type->der->type.der && type->info.enums.count) { |
| 473 | /* 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] | 474 | LOGVAL(LYE_INSTMT, LOGLINE(yin), "enum"); |
Radek Krejci | b54bcb1 | 2015-07-10 13:16:40 +0200 | [diff] [blame] | 475 | goto error; |
| 476 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 477 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 478 | 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] | 479 | if (!type->info.enums.enm) { |
| 480 | LOGMEM; |
| 481 | goto error; |
| 482 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 483 | v = 0; |
| 484 | i = -1; |
| 485 | LY_TREE_FOR(yin->child, next) { |
| 486 | i++; |
| 487 | |
| 488 | GETVAL(value, next, "name"); |
Michal Vasko | 0fb58e9 | 2015-12-07 09:27:44 +0100 | [diff] [blame] | 489 | if (!value[0]) { |
| 490 | LOGVAL(LYE_SPEC, LOGLINE(next), "Enum name must not be empty."); |
| 491 | goto error; |
| 492 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 493 | 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] | 494 | 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] | 495 | type->info.enums.count = i + 1; |
| 496 | goto error; |
| 497 | } |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 498 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 499 | /* the assigned name MUST NOT have any leading or trailing whitespace characters */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 500 | value = type->info.enums.enm[i].name; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 501 | if (isspace(value[0]) || isspace(value[strlen(value) - 1])) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 502 | LOGVAL(LYE_ENUM_WS, LOGLINE(next), value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 503 | type->info.enums.count = i + 1; |
| 504 | goto error; |
| 505 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 506 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 507 | /* check the name uniqueness */ |
| 508 | for (j = 0; j < i; j++) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 509 | 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] | 510 | LOGVAL(LYE_ENUM_DUPNAME, LOGLINE(next), type->info.enums.enm[i].name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 511 | type->info.enums.count = i + 1; |
| 512 | goto error; |
| 513 | } |
| 514 | } |
Radek Krejci | 04581c6 | 2015-05-22 21:24:00 +0200 | [diff] [blame] | 515 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 516 | v_ = -1; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 517 | LY_TREE_FOR(next->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 518 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 519 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 520 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 521 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 522 | |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 523 | if (!strcmp(node->name, "value")) { |
| 524 | GETVAL(value, node, "value"); |
Radek Krejci | 7511f40 | 2015-07-10 09:56:30 +0200 | [diff] [blame] | 525 | v_ = strtoll(value, NULL, 10); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 526 | |
| 527 | /* range check */ |
| 528 | if (v_ < INT32_MIN || v_ > INT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 529 | LOGVAL(LYE_INARG, LOGLINE(node), value, "enum/value"); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 530 | type->info.enums.count = i + 1; |
| 531 | goto error; |
| 532 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 533 | type->info.enums.enm[i].value = v_; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 534 | |
| 535 | /* keep the highest enum value for automatic increment */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 536 | if (type->info.enums.enm[i].value > v) { |
| 537 | v = type->info.enums.enm[i].value; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 538 | v++; |
| 539 | } else { |
| 540 | /* check that the value is unique */ |
| 541 | for (j = 0; j < i; j++) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 542 | 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] | 543 | LOGVAL(LYE_ENUM_DUPVAL, LOGLINE(node), type->info.enums.enm[i].value, |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 544 | type->info.enums.enm[i].name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 545 | type->info.enums.count = i + 1; |
| 546 | goto error; |
| 547 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 548 | } |
| 549 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 550 | } else { |
Michal Vasko | e29c662 | 2015-11-27 15:02:31 +0100 | [diff] [blame] | 551 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 552 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 553 | } |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 554 | } |
| 555 | if (v_ == -1) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 556 | /* assign value automatically */ |
| 557 | if (v > INT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 558 | LOGVAL(LYE_INARG, LOGLINE(next), "2147483648", "enum/value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 559 | type->info.enums.count = i + 1; |
| 560 | goto error; |
| 561 | } |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 562 | type->info.enums.enm[i].value = v; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 563 | v++; |
| 564 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 565 | } |
| 566 | break; |
| 567 | |
| 568 | case LY_TYPE_IDENT: |
Radek Krejci | 994b6f6 | 2015-06-18 16:47:27 +0200 | [diff] [blame] | 569 | /* RFC 6020 9.10 - base */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 570 | |
| 571 | /* get base specification, exactly one must be present */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 572 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 573 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 574 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 575 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 576 | continue; |
| 577 | } |
| 578 | |
Michal Vasko | e29c662 | 2015-11-27 15:02:31 +0100 | [diff] [blame] | 579 | if (strcmp(node->name, "base")) { |
| 580 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 581 | goto error; |
| 582 | } |
| 583 | } |
| 584 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 585 | if (!yin->child) { |
Radek Krejci | 65c889c | 2015-06-22 10:17:22 +0200 | [diff] [blame] | 586 | if (type->der->type.der) { |
| 587 | /* this is just a derived type with no base specified/required */ |
| 588 | break; |
| 589 | } |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 590 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "base", "type"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 591 | goto error; |
| 592 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 593 | if (yin->child->next) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 594 | 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] | 595 | goto error; |
| 596 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 597 | GETVAL(value, yin->child, "name"); |
Michal Vasko | bdfb1e0 | 2016-02-05 13:15:11 +0100 | [diff] [blame] | 598 | /* store in the JSON format */ |
| 599 | value = transform_schema2json(module, value, LOGLINE(yin->child)); |
| 600 | if (!value) { |
| 601 | goto error; |
| 602 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 603 | 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] | 604 | goto error; |
| 605 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 606 | break; |
| 607 | |
| 608 | case LY_TYPE_INST: |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 609 | /* RFC 6020 9.13.2 - require-instance */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 610 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 611 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 612 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 613 | continue; |
| 614 | } |
| 615 | |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 616 | if (!strcmp(node->name, "require-instance")) { |
| 617 | if (type->info.inst.req) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 618 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 619 | goto error; |
| 620 | } |
| 621 | GETVAL(value, node, "value"); |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 622 | if (!strcmp(value, "true")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 623 | type->info.inst.req = 1; |
Michal Vasko | 25fa5ac | 2015-07-17 10:53:38 +0200 | [diff] [blame] | 624 | } else if (!strcmp(value, "false")) { |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 625 | type->info.inst.req = -1; |
| 626 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 627 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 628 | goto error; |
| 629 | } |
| 630 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 631 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 632 | goto error; |
| 633 | } |
Radek Krejci | af35142 | 2015-06-19 14:49:38 +0200 | [diff] [blame] | 634 | } |
Michal Vasko | 8548cf9 | 2015-07-20 15:17:53 +0200 | [diff] [blame] | 635 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 636 | break; |
| 637 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 638 | case LY_TYPE_BINARY: |
| 639 | /* 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] | 640 | case LY_TYPE_INT8: |
| 641 | case LY_TYPE_INT16: |
| 642 | case LY_TYPE_INT32: |
| 643 | case LY_TYPE_INT64: |
| 644 | case LY_TYPE_UINT8: |
| 645 | case LY_TYPE_UINT16: |
| 646 | case LY_TYPE_UINT32: |
| 647 | case LY_TYPE_UINT64: |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 648 | /* RFC 6020 9.2.4 - range */ |
| 649 | |
| 650 | /* length and range are actually the same restriction, so process |
| 651 | * them by this common code, we just need to differ the name and |
| 652 | * structure where the information will be stored |
| 653 | */ |
| 654 | if (type->base == LY_TYPE_BINARY) { |
| 655 | restr = &type->info.binary.length; |
| 656 | name = "length"; |
| 657 | } else { |
| 658 | restr = &type->info.num.range; |
| 659 | name = "range"; |
| 660 | } |
| 661 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 662 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 663 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 664 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 665 | continue; |
| 666 | } |
| 667 | |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 668 | if (!strcmp(node->name, name)) { |
| 669 | if (*restr) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 670 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 671 | goto error; |
| 672 | } |
| 673 | |
| 674 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 675 | if (lyp_check_length_range(value, type)) { |
Michal Vasko | 9c1bc64 | 2015-08-05 16:25:53 +0200 | [diff] [blame] | 676 | LOGVAL(LYE_INARG, LOGLINE(node), value, name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 677 | goto error; |
| 678 | } |
| 679 | *restr = calloc(1, sizeof **restr); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 680 | if (!(*restr)) { |
| 681 | LOGMEM; |
| 682 | goto error; |
| 683 | } |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 684 | (*restr)->expr = lydict_insert(module->ctx, value, 0); |
| 685 | |
| 686 | /* get possible substatements */ |
| 687 | if (read_restr_substmt(module->ctx, *restr, node)) { |
| 688 | goto error; |
| 689 | } |
| 690 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 691 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 692 | goto error; |
| 693 | } |
Radek Krejci | f286013 | 2015-06-20 12:37:20 +0200 | [diff] [blame] | 694 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 695 | break; |
| 696 | |
| 697 | case LY_TYPE_LEAFREF: |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 698 | /* RFC 6020 9.9.2 - path */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 699 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 700 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 701 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 702 | continue; |
| 703 | } |
| 704 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 705 | if (!strcmp(node->name, "path") && !type->der->type.der) { |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 706 | if (type->info.lref.path) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 707 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 708 | goto error; |
| 709 | } |
| 710 | |
| 711 | GETVAL(value, node, "value"); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 712 | /* store in the JSON format */ |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 713 | type->info.lref.path = transform_schema2json(module, value, LOGLINE(node)); |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 714 | if (!type->info.lref.path) { |
| 715 | goto error; |
| 716 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 717 | 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] | 718 | goto error; |
| 719 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 720 | |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 721 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 722 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 723 | goto error; |
| 724 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 725 | } |
| 726 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 727 | if (!type->info.lref.path && !type->der->type.der) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 728 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "path", "type"); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 729 | goto error; |
Radek Krejci | dc4c141 | 2015-06-19 15:39:54 +0200 | [diff] [blame] | 730 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 731 | break; |
| 732 | |
| 733 | case LY_TYPE_STRING: |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 734 | /* RFC 6020 9.4.4 - length */ |
| 735 | /* RFC 6020 9.4.6 - pattern */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 736 | i = 0; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 737 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 738 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 739 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 740 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 741 | continue; |
| 742 | } |
| 743 | |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 744 | if (!strcmp(node->name, "length")) { |
| 745 | if (type->info.str.length) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 746 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 747 | goto error; |
| 748 | } |
| 749 | |
| 750 | GETVAL(value, node, "value"); |
Radek Krejci | 6dc53a2 | 2015-08-17 13:27:59 +0200 | [diff] [blame] | 751 | if (lyp_check_length_range(value, type)) { |
Michal Vasko | 9c1bc64 | 2015-08-05 16:25:53 +0200 | [diff] [blame] | 752 | LOGVAL(LYE_INARG, LOGLINE(node), value, "length"); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 753 | goto error; |
| 754 | } |
| 755 | type->info.str.length = calloc(1, sizeof *type->info.str.length); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 756 | if (!type->info.str.length) { |
| 757 | LOGMEM; |
| 758 | goto error; |
| 759 | } |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 760 | type->info.str.length->expr = lydict_insert(module->ctx, value, 0); |
| 761 | |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 762 | /* get possible sub-statements */ |
| 763 | if (read_restr_substmt(module->ctx, type->info.str.length, node)) { |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 764 | goto error; |
| 765 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 766 | lyxml_free(module->ctx, node); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 767 | } else if (!strcmp(node->name, "pattern")) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 768 | i++; |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 769 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 770 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | 3733a80 | 2015-06-19 13:43:21 +0200 | [diff] [blame] | 771 | goto error; |
| 772 | } |
| 773 | } |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 774 | /* store patterns in array */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 775 | if (i) { |
| 776 | type->info.str.patterns = calloc(i, sizeof *type->info.str.patterns); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 777 | if (!type->info.str.patterns) { |
| 778 | LOGMEM; |
| 779 | goto error; |
| 780 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 781 | LY_TREE_FOR(yin->child, node) { |
Michal Vasko | 5b64da2 | 2015-11-23 15:22:30 +0100 | [diff] [blame] | 782 | GETVAL(value, node, "value"); |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 783 | |
| 784 | /* check that the regex is valid */ |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 785 | precomp = pcre_compile(value, PCRE_NO_AUTO_CAPTURE, &err_ptr, &err_offset, NULL); |
| 786 | if (!precomp) { |
| 787 | LOGVAL(LYE_INREGEX, LOGLINE(node), value, err_ptr); |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 788 | free(type->info.str.patterns); |
| 789 | goto error; |
| 790 | } |
Michal Vasko | e4e8fbd | 2015-08-24 14:54:49 +0200 | [diff] [blame] | 791 | free(precomp); |
Michal Vasko | 6906885 | 2015-07-13 14:34:31 +0200 | [diff] [blame] | 792 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 793 | 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] | 794 | |
| 795 | /* get possible sub-statements */ |
Michal Vasko | 5b64da2 | 2015-11-23 15:22:30 +0100 | [diff] [blame] | 796 | 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] | 797 | free(type->info.str.patterns); |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 798 | goto error; |
| 799 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 800 | type->info.str.pat_count++; |
Radek Krejci | 5fbc916 | 2015-06-19 14:11:11 +0200 | [diff] [blame] | 801 | } |
| 802 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 803 | break; |
| 804 | |
| 805 | case LY_TYPE_UNION: |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 806 | /* RFC 6020 7.4 - type */ |
| 807 | /* count number of types in union */ |
| 808 | i = 0; |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 809 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
| 810 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 811 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 812 | lyxml_free(module->ctx, node); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 813 | continue; |
| 814 | } |
| 815 | |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 816 | if (!strcmp(node->name, "type")) { |
| 817 | i++; |
| 818 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 819 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 820 | goto error; |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | if (!i) { |
| 825 | if (type->der->type.der) { |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 826 | /* this is just a derived type with no additional type specified/required */ |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 827 | break; |
| 828 | } |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 829 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", "(union) type"); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 830 | goto error; |
| 831 | } |
| 832 | |
| 833 | /* allocate array for union's types ... */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 834 | type->info.uni.types = calloc(i, sizeof *type->info.uni.types); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 835 | if (!type->info.uni.types) { |
| 836 | LOGMEM; |
| 837 | goto error; |
| 838 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 839 | /* ... and fill the structures */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 840 | LY_TREE_FOR(yin->child, node) { |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 841 | type->info.uni.types[type->info.uni.count].parent = type->parent; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 842 | rc = fill_yin_type(module, parent, node, &type->info.uni.types[type->info.uni.count], unres); |
| 843 | if (!rc) { |
| 844 | type->info.uni.count++; |
| 845 | |
| 846 | /* union's type cannot be empty or leafref */ |
| 847 | if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_EMPTY) { |
| 848 | LOGVAL(LYE_INARG, LOGLINE(node), "empty", node->name); |
| 849 | rc = -1; |
| 850 | } else if (type->info.uni.types[type->info.uni.count - 1].base == LY_TYPE_LEAFREF) { |
| 851 | LOGVAL(LYE_INARG, LOGLINE(node), "leafref", node->name); |
| 852 | rc = -1; |
| 853 | } |
| 854 | } |
| 855 | if (rc) { |
| 856 | /* even if we got EXIT_FAILURE, throw it all away, too much trouble doing something else */ |
| 857 | for (i = 0; i < type->info.uni.count; ++i) { |
| 858 | lys_type_free(module->ctx, &type->info.uni.types[i]); |
| 859 | } |
| 860 | free(type->info.uni.types); |
| 861 | type->info.uni.types = NULL; |
| 862 | type->info.uni.count = 0; |
| 863 | |
| 864 | if (rc == EXIT_FAILURE) { |
| 865 | return EXIT_FAILURE; |
| 866 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 867 | goto error; |
| 868 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 869 | } |
| 870 | break; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 871 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 872 | case LY_TYPE_BOOL: |
| 873 | case LY_TYPE_EMPTY: |
| 874 | /* no sub-statement allowed */ |
| 875 | LY_TREE_FOR(yin->child, node) { |
| 876 | if (node->ns && !strcmp(node->ns->value, LY_NSYIN)) { |
| 877 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 878 | goto error; |
| 879 | } |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 880 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 881 | break; |
| 882 | |
| 883 | default: |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 884 | LOGINT; |
| 885 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | return EXIT_SUCCESS; |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 889 | |
| 890 | error: |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 891 | return -1; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 892 | } |
| 893 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 894 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 895 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 896 | 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] | 897 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 898 | const char *value; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 899 | struct lyxml_elem *node, *next; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 900 | int has_type = 0, dflt_line; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 901 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 902 | GETVAL(value, yin, "name"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 903 | if (lyp_check_identifier(value, LY_IDENT_TYPE, LOGLINE(yin), module, parent)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 904 | goto error; |
| 905 | } |
| 906 | tpdf->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 907 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 908 | /* generic part - status, description, reference */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 909 | 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] | 910 | goto error; |
| 911 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 912 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 913 | LY_TREE_FOR_SAFE(yin->child, next, node) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 914 | if (!node->ns || strcmp(node->ns->value, LY_NSYIN)) { |
| 915 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 916 | continue; |
| 917 | } |
| 918 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 919 | if (!strcmp(node->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 920 | if (has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 921 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 922 | goto error; |
| 923 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 924 | /* HACK for unres */ |
| 925 | tpdf->type.der = (struct lys_tpdf *)node; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 926 | tpdf->type.parent = tpdf; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 927 | 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] | 928 | goto error; |
| 929 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 930 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 931 | } else if (!strcmp(node->name, "default")) { |
| 932 | if (tpdf->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 933 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 934 | goto error; |
| 935 | } |
| 936 | GETVAL(value, node, "value"); |
| 937 | tpdf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 938 | dflt_line = LOGLINE(node); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 939 | } else if (!strcmp(node->name, "units")) { |
| 940 | if (tpdf->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 941 | LOGVAL(LYE_TOOMANY, LOGLINE(node), node->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 942 | goto error; |
| 943 | } |
| 944 | GETVAL(value, node, "name"); |
| 945 | tpdf->units = lydict_insert(module->ctx, value, strlen(value)); |
| 946 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 947 | LOGVAL(LYE_INSTMT, LOGLINE(node), value); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 948 | goto error; |
| 949 | } |
| 950 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 951 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 952 | /* check mandatory value */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 953 | if (!has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 954 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 955 | goto error; |
| 956 | } |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 957 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 958 | /* check default value */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 959 | if (tpdf->dflt) { |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 960 | 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] | 961 | goto error; |
| 962 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 963 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 964 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 965 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 966 | |
| 967 | error: |
| 968 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 969 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 970 | } |
| 971 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 972 | /* logs directly */ |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 973 | static int |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 974 | 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] | 975 | { |
| 976 | const char *value; |
| 977 | struct lyxml_elem *child, *next; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 978 | int c = 0, ret; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 979 | |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 980 | GETVAL(value, yin, "name"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 981 | if (lyp_check_identifier(value, LY_IDENT_FEATURE, LOGLINE(yin), module, NULL)) { |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 982 | goto error; |
| 983 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 984 | f->name = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 985 | f->module = module; |
Radek Krejci | b05774c | 2015-06-18 13:52:59 +0200 | [diff] [blame] | 986 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 987 | if (read_yin_common(module, NULL, (struct lys_node *)f, yin, 0)) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 988 | goto error; |
| 989 | } |
| 990 | |
| 991 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 992 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 993 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 994 | lyxml_free(module->ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 995 | continue; |
| 996 | } |
| 997 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 998 | if (!strcmp(child->name, "if-feature")) { |
| 999 | c++; |
| 1000 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1001 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1002 | goto error; |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | if (c) { |
| 1007 | f->features = calloc(c, sizeof *f->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1008 | if (!f->features) { |
| 1009 | LOGMEM; |
| 1010 | goto error; |
| 1011 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1012 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1013 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1014 | GETVAL(value, child, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 1015 | if (!(value = transform_schema2json(module, value, LOGLINE(child)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 1016 | goto error; |
| 1017 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 1018 | /* hack - store pointer to the parent node for later status check */ |
| 1019 | f->features[f->features_size] = f; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 1020 | 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] | 1021 | LOGLINE(child)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 1022 | f->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 1023 | lydict_remove(module->ctx, value); |
| 1024 | if (ret == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1025 | goto error; |
| 1026 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1027 | } |
| 1028 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1029 | return EXIT_SUCCESS; |
| 1030 | |
| 1031 | error: |
| 1032 | |
| 1033 | return EXIT_FAILURE; |
| 1034 | } |
| 1035 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1036 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1037 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1038 | 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] | 1039 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1040 | const char *value; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1041 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1042 | GETVAL(value, yin, "condition"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 1043 | must->expr = transform_schema2json(module, value, LOGLINE(yin)); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 1044 | if (!must->expr) { |
| 1045 | goto error; |
| 1046 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1047 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 1048 | return read_restr_substmt(module->ctx, must, yin); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1049 | |
Radek Krejci | 41726f9 | 2015-06-19 13:11:05 +0200 | [diff] [blame] | 1050 | error: /* GETVAL requires this label */ |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1051 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1052 | return EXIT_FAILURE; |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 1053 | } |
| 1054 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1055 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1056 | fill_yin_unique(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, struct lys_unique *unique, |
| 1057 | struct unres_schema *unres) |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1058 | { |
| 1059 | int i, j; |
| 1060 | const char *value, *vaux; |
| 1061 | |
| 1062 | /* get unique value (list of leafs supposed to be unique */ |
| 1063 | GETVAL(value, yin, "tag"); |
| 1064 | |
| 1065 | /* count the number of unique leafs in the value */ |
| 1066 | vaux = value; |
| 1067 | while ((vaux = strpbrk(vaux, " \t\n"))) { |
| 1068 | unique->expr_size++; |
| 1069 | while (isspace(*vaux)) { |
| 1070 | vaux++; |
| 1071 | } |
| 1072 | } |
| 1073 | unique->expr_size++; |
| 1074 | unique->expr = calloc(unique->expr_size, sizeof *unique->expr); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1075 | if (!unique->expr) { |
| 1076 | LOGMEM; |
| 1077 | goto error; |
| 1078 | } |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1079 | |
| 1080 | for (i = 0; i < unique->expr_size; i++) { |
| 1081 | vaux = strpbrk(value, " \t\n"); |
| 1082 | if (!vaux) { |
| 1083 | /* the last token, lydict_insert() will count its size on its own */ |
| 1084 | vaux = value; |
| 1085 | } |
| 1086 | |
| 1087 | /* store token into unique structure */ |
| 1088 | unique->expr[i] = lydict_insert(module->ctx, value, vaux - value); |
| 1089 | |
| 1090 | /* check that the expression does not repeat */ |
| 1091 | for (j = 0; j < i; j++) { |
| 1092 | if (unique->expr[j] == unique->expr[i]) { |
| 1093 | LOGVAL(LYE_INARG, LOGLINE(yin), unique->expr[i], "unique"); |
| 1094 | LOGVAL(LYE_SPEC, 0, "The identifier is not unique"); |
| 1095 | goto error; |
| 1096 | } |
| 1097 | } |
| 1098 | |
| 1099 | /* try to resolve leaf */ |
| 1100 | if (unres) { |
| 1101 | unres_schema_add_str(module, unres, parent, UNRES_LIST_UNIQ, unique->expr[i], LOGLINE(yin)); |
| 1102 | } else { |
| 1103 | if (resolve_unique(parent, value, 0, LOGLINE(yin))) { |
| 1104 | goto error; |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | /* move to next token */ |
| 1109 | value = vaux; |
| 1110 | while(isspace(*value)) { |
| 1111 | value++; |
| 1112 | } |
| 1113 | } |
| 1114 | |
| 1115 | return EXIT_SUCCESS; |
| 1116 | |
| 1117 | error: |
| 1118 | return EXIT_FAILURE; |
| 1119 | } |
| 1120 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1121 | /* logs directly |
| 1122 | * |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1123 | * type: 0 - min, 1 - max |
| 1124 | */ |
| 1125 | static int |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1126 | 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] | 1127 | { |
| 1128 | const char *value; |
| 1129 | char *endptr; |
| 1130 | unsigned long val; |
| 1131 | uint32_t *ui32val; |
| 1132 | |
| 1133 | /* check target node type */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1134 | if (target->nodetype == LYS_LEAFLIST) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1135 | if (type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1136 | ui32val = &((struct lys_node_leaflist *)target)->max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1137 | } else { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1138 | ui32val = &((struct lys_node_leaflist *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1139 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1140 | } else if (target->nodetype == LYS_LIST) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1141 | if (type) { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1142 | ui32val = &((struct lys_node_list *)target)->max; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1143 | } else { |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1144 | ui32val = &((struct lys_node_list *)target)->min; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1145 | } |
| 1146 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1147 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
| 1148 | 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] | 1149 | goto error; |
| 1150 | } |
| 1151 | |
| 1152 | GETVAL(value, node, "value"); |
| 1153 | while (isspace(value[0])) { |
| 1154 | value++; |
| 1155 | } |
| 1156 | |
| 1157 | /* convert it to uint32_t */ |
| 1158 | errno = 0; |
| 1159 | endptr = NULL; |
| 1160 | val = strtoul(value, &endptr, 10); |
| 1161 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1162 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1163 | goto error; |
| 1164 | } |
| 1165 | if (type) { |
| 1166 | d->max = (uint32_t)val; |
| 1167 | } else { |
| 1168 | d->min = (uint32_t)val; |
| 1169 | } |
| 1170 | |
| 1171 | if (d->mod == LY_DEVIATE_ADD) { |
| 1172 | /* check that there is no current value */ |
| 1173 | if (*ui32val) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1174 | LOGVAL(LYE_INSTMT, LOGLINE(node), node->name); |
| 1175 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1176 | goto error; |
| 1177 | } |
| 1178 | } |
| 1179 | |
| 1180 | if (d->mod == LY_DEVIATE_DEL) { |
| 1181 | /* check values */ |
| 1182 | if ((uint32_t)val != *ui32val) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1183 | LOGVAL(LYE_INARG, LOGLINE(node), value, node->name); |
| 1184 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1185 | goto error; |
| 1186 | } |
| 1187 | /* remove current min-elements value of the target */ |
| 1188 | *ui32val = 0; |
| 1189 | } else { /* add (already checked) and replace */ |
| 1190 | /* set new value specified in deviation */ |
| 1191 | *ui32val = (uint32_t)val; |
| 1192 | } |
| 1193 | |
| 1194 | return EXIT_SUCCESS; |
| 1195 | |
| 1196 | error: |
| 1197 | |
| 1198 | return EXIT_FAILURE; |
| 1199 | } |
| 1200 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1201 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1202 | static int |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1203 | fill_yin_deviation(struct lys_module *module, struct lyxml_elem *yin, struct lys_deviation *dev, |
| 1204 | struct unres_schema *unres) |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1205 | { |
| 1206 | const char *value, **stritem; |
| 1207 | struct lyxml_elem *next, *child, *develem; |
| 1208 | int c_dev = 0, c_must, c_uniq; |
| 1209 | int f_min = 0; /* flags */ |
Michal Vasko | b40b451 | 2016-02-11 11:35:37 +0100 | [diff] [blame] | 1210 | int i, j, rc; |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1211 | struct ly_ctx *ctx; |
Radek Krejci | a52656e | 2015-08-05 13:41:50 +0200 | [diff] [blame] | 1212 | struct lys_deviate *d = NULL; |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1213 | struct lys_node *node = NULL, *dev_target = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1214 | struct lys_node_choice *choice = NULL; |
| 1215 | struct lys_node_leaf *leaf = NULL; |
| 1216 | struct lys_node_list *list = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1217 | struct lys_type *t = NULL; |
Radek Krejci | e4c366b | 2015-07-02 10:11:31 +0200 | [diff] [blame] | 1218 | uint8_t *trg_must_size = NULL; |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1219 | struct lys_restr **trg_must = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1220 | |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1221 | ctx = module->ctx; |
| 1222 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1223 | GETVAL(value, yin, "target-node"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 1224 | dev->target_name = transform_schema2json(module, value, LOGLINE(yin)); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 1225 | if (!dev->target_name) { |
| 1226 | goto error; |
| 1227 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1228 | |
| 1229 | /* resolve target node */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1230 | rc = resolve_augment_schema_nodeid(dev->target_name, NULL, module, (const struct lys_node **)&dev_target); |
| 1231 | if (rc || !dev_target) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1232 | LOGVAL(LYE_INARG, LOGLINE(yin), dev->target_name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1233 | goto error; |
| 1234 | } |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1235 | if (dev_target->module == module) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1236 | LOGVAL(LYE_SPEC, LOGLINE(yin), "Deviating own module is not allowed."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1237 | goto error; |
| 1238 | } |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1239 | dev->target_module = dev_target->module; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1240 | /* mark the target module as deviated */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1241 | dev->target_module->deviated = 1; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1242 | |
| 1243 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1244 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1245 | /* garbage */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1246 | lyxml_free(ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1247 | continue; |
| 1248 | } |
| 1249 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1250 | if (!strcmp(child->name, "description")) { |
| 1251 | if (dev->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1252 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1253 | goto error; |
| 1254 | } |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1255 | dev->dsc = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1256 | if (!dev->dsc) { |
| 1257 | goto error; |
| 1258 | } |
| 1259 | } else if (!strcmp(child->name, "reference")) { |
| 1260 | if (dev->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1261 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1262 | goto error; |
| 1263 | } |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1264 | dev->ref = read_yin_subnode(ctx, child, "text"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1265 | if (!dev->ref) { |
| 1266 | goto error; |
| 1267 | } |
| 1268 | } else if (!strcmp(child->name, "deviate")) { |
| 1269 | c_dev++; |
| 1270 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1271 | /* skip lyxml_free() at the end of the loop, node will be |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1272 | * further processed later |
| 1273 | */ |
| 1274 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 1275 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1276 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1277 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1278 | goto error; |
| 1279 | } |
| 1280 | |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1281 | lyxml_free(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | if (c_dev) { |
| 1285 | dev->deviate = calloc(c_dev, sizeof *dev->deviate); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1286 | if (!dev->deviate) { |
| 1287 | LOGMEM; |
| 1288 | goto error; |
| 1289 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1290 | } |
| 1291 | |
| 1292 | LY_TREE_FOR(yin->child, develem) { |
| 1293 | /* init */ |
| 1294 | f_min = 0; |
| 1295 | c_must = 0; |
| 1296 | c_uniq = 0; |
| 1297 | |
| 1298 | /* get deviation type */ |
| 1299 | GETVAL(value, develem, "value"); |
| 1300 | if (!strcmp(value, "not-supported")) { |
| 1301 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_NO; |
| 1302 | /* no property expected in this case */ |
| 1303 | if (develem->child) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1304 | LOGVAL(LYE_INSTMT, LOGLINE(develem->child), develem->child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1305 | goto error; |
| 1306 | } |
| 1307 | |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1308 | /* and neither any other deviate statement is expected, |
| 1309 | * not-supported deviation must be the only deviation of the target |
| 1310 | */ |
| 1311 | if (dev->deviate_size || develem->next) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1312 | LOGVAL(LYE_INARG, LOGLINE(develem), value, develem->name); |
| 1313 | 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] | 1314 | goto error; |
| 1315 | } |
| 1316 | |
| 1317 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1318 | /* remove target node */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1319 | lys_node_free(dev_target, NULL); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1320 | |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1321 | dev->deviate_size = 1; |
| 1322 | return EXIT_SUCCESS; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1323 | } else if (!strcmp(value, "add")) { |
| 1324 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_ADD; |
| 1325 | } else if (!strcmp(value, "replace")) { |
| 1326 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_RPL; |
| 1327 | } else if (!strcmp(value, "delete")) { |
| 1328 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_DEL; |
| 1329 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1330 | LOGVAL(LYE_INARG, LOGLINE(develem), value, develem->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1331 | goto error; |
| 1332 | } |
| 1333 | d = &dev->deviate[dev->deviate_size]; |
| 1334 | |
| 1335 | /* process deviation properties */ |
| 1336 | LY_TREE_FOR_SAFE(develem->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1337 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1338 | /* garbage */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1339 | lyxml_free(ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1340 | continue; |
| 1341 | } |
| 1342 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1343 | if (!strcmp(child->name, "config")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1344 | if (d->flags & LYS_CONFIG_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1345 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1346 | goto error; |
| 1347 | } |
| 1348 | |
| 1349 | /* for we deviate from RFC 6020 and allow config property even it is/is not |
| 1350 | * specified in the target explicitly since config property inherits. So we expect |
| 1351 | * that config is specified in every node. But for delete, we check that the value |
| 1352 | * is the same as here in deviation |
| 1353 | */ |
| 1354 | GETVAL(value, child, "value"); |
| 1355 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1356 | d->flags |= LYS_CONFIG_R; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1357 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1358 | d->flags |= LYS_CONFIG_W; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1359 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1360 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1361 | goto error; |
| 1362 | } |
| 1363 | |
| 1364 | if (d->mod == LY_DEVIATE_DEL) { |
| 1365 | /* check values */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1366 | if ((d->flags & LYS_CONFIG_MASK) != (dev_target->flags & LYS_CONFIG_MASK)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1367 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1368 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1369 | goto error; |
| 1370 | } |
| 1371 | /* remove current config value of the target ... */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1372 | dev_target->flags &= ~LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1373 | |
| 1374 | /* ... and inherit config value from the target's parent */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1375 | if (dev_target->parent) { |
| 1376 | dev_target->flags |= dev_target->parent->flags & LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1377 | } else { |
| 1378 | /* default config is true */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1379 | dev_target->flags |= LYS_CONFIG_W; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1380 | } |
| 1381 | } else { /* add and replace are the same in this case */ |
| 1382 | /* remove current config value of the target ... */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1383 | dev_target->flags &= ~LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1384 | |
| 1385 | /* ... and replace it with the value specified in deviation */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1386 | dev_target->flags |= d->flags & LYS_CONFIG_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1387 | } |
| 1388 | } else if (!strcmp(child->name, "default")) { |
| 1389 | if (d->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1390 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1391 | goto error; |
| 1392 | } |
| 1393 | GETVAL(value, child, "value"); |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1394 | d->dflt = lydict_insert(ctx, value, 0); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1395 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1396 | if (dev_target->nodetype == LYS_CHOICE) { |
| 1397 | choice = (struct lys_node_choice *)dev_target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1398 | |
| 1399 | if (d->mod == LY_DEVIATE_ADD) { |
| 1400 | /* check that there is no current value */ |
| 1401 | if (choice->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1402 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1403 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1404 | goto error; |
| 1405 | } |
| 1406 | } |
| 1407 | |
Michal Vasko | 3edeaf7 | 2016-02-11 13:17:43 +0100 | [diff] [blame] | 1408 | rc = resolve_choice_default_schema_nodeid(d->dflt, choice->child, (const struct lys_node **)&node); |
Michal Vasko | 9bb061b | 2016-02-12 11:00:19 +0100 | [diff] [blame] | 1409 | if (rc || !node) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1410 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1411 | goto error; |
| 1412 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1413 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1414 | if (!choice->dflt || (choice->dflt != node)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1415 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1416 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1417 | goto error; |
| 1418 | } |
| 1419 | } else { /* add (already checked) and replace */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1420 | choice->dflt = node; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1421 | if (!choice->dflt) { |
| 1422 | /* default branch not found */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1423 | LOGVAL(LYE_INARG, LOGLINE(yin), value, "default"); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1424 | goto error; |
| 1425 | } |
| 1426 | } |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1427 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 1428 | leaf = (struct lys_node_leaf *)dev_target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1429 | |
| 1430 | if (d->mod == LY_DEVIATE_ADD) { |
| 1431 | /* check that there is no current value */ |
| 1432 | if (leaf->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1433 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1434 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1435 | goto error; |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1440 | if (!leaf->dflt || (leaf->dflt != d->dflt)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1441 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1442 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1443 | goto error; |
| 1444 | } |
| 1445 | /* remove value */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1446 | lydict_remove(ctx, leaf->dflt); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1447 | leaf->dflt = NULL; |
| 1448 | } else { /* add (already checked) and replace */ |
| 1449 | /* remove value */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1450 | lydict_remove(ctx, leaf->dflt); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1451 | |
| 1452 | /* set new value */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1453 | leaf->dflt = lydict_insert(ctx, d->dflt, 0); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1454 | } |
| 1455 | } else { |
| 1456 | /* invalid target for default value */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1457 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1458 | 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] | 1459 | goto error; |
| 1460 | } |
| 1461 | } else if (!strcmp(child->name, "mandatory")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1462 | if (d->flags & LYS_MAND_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1463 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1464 | goto error; |
| 1465 | } |
| 1466 | |
| 1467 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1468 | if (!(dev_target->nodetype & (LYS_LEAF | LYS_CHOICE | LYS_ANYXML))) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1469 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1470 | 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] | 1471 | goto error; |
| 1472 | } |
| 1473 | |
| 1474 | GETVAL(value, child, "value"); |
| 1475 | if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1476 | d->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1477 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 1478 | d->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1479 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1480 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1481 | goto error; |
| 1482 | } |
| 1483 | |
| 1484 | if (d->mod == LY_DEVIATE_ADD) { |
| 1485 | /* check that there is no current value */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1486 | if (dev_target->flags & LYS_MAND_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1487 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1488 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1489 | goto error; |
| 1490 | } |
| 1491 | } |
| 1492 | |
| 1493 | if (d->mod == LY_DEVIATE_DEL) { |
| 1494 | /* check values */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1495 | if ((d->flags & LYS_MAND_MASK) != (dev_target->flags & LYS_MAND_MASK)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1496 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1497 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1498 | goto error; |
| 1499 | } |
| 1500 | /* remove current mandatory value of the target */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1501 | dev_target->flags &= ~LYS_MAND_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1502 | } else { /* add (already checked) and replace */ |
| 1503 | /* remove current mandatory value of the target ... */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1504 | dev_target->flags &= ~LYS_MAND_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1505 | |
| 1506 | /* ... and replace it with the value specified in deviation */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1507 | dev_target->flags |= d->flags & LYS_MAND_MASK; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1508 | } |
| 1509 | } else if (!strcmp(child->name, "min-elements")) { |
| 1510 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1511 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1512 | goto error; |
| 1513 | } |
| 1514 | f_min = 1; |
| 1515 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1516 | if (deviate_minmax(dev_target, child, d, 0)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1517 | goto error; |
| 1518 | } |
| 1519 | } else if (!strcmp(child->name, "max-elements")) { |
| 1520 | if (d->max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1521 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1522 | goto error; |
| 1523 | } |
| 1524 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1525 | if (deviate_minmax(dev_target, child, d, 1)) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1526 | goto error; |
| 1527 | } |
| 1528 | } else if (!strcmp(child->name, "must")) { |
| 1529 | c_must++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1530 | /* 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] | 1531 | continue; |
| 1532 | } else if (!strcmp(child->name, "type")) { |
| 1533 | if (d->type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1534 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1535 | goto error; |
| 1536 | } |
| 1537 | |
| 1538 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1539 | if (dev_target->nodetype == LYS_LEAF) { |
| 1540 | t = &((struct lys_node_leaf *)dev_target)->type; |
| 1541 | } else if (dev_target->nodetype == LYS_LEAFLIST) { |
| 1542 | t = &((struct lys_node_leaflist *)dev_target)->type; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1543 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1544 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1545 | 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] | 1546 | goto error; |
| 1547 | } |
| 1548 | |
| 1549 | if (d->mod == LY_DEVIATE_ADD) { |
| 1550 | /* not allowed, type is always present at the target */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1551 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1552 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1553 | goto error; |
| 1554 | } else if (d->mod == LY_DEVIATE_DEL) { |
| 1555 | /* not allowed, type cannot be deleted from the target */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1556 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1557 | LOGVAL(LYE_SPEC, 0, "Deleteing type from the target is not allowed."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1558 | goto error; |
| 1559 | } |
| 1560 | |
| 1561 | /* replace */ |
| 1562 | /* remove current units value of the target ... */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1563 | lys_type_free(ctx, t); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1564 | |
| 1565 | /* ... and replace it with the value specified in deviation */ |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1566 | /* HACK for unres */ |
| 1567 | t->der = (struct lys_tpdf *)child; |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1568 | 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] | 1569 | goto error; |
| 1570 | } |
| 1571 | d->type = t; |
| 1572 | } else if (!strcmp(child->name, "unique")) { |
| 1573 | c_uniq++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1574 | /* 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] | 1575 | continue; |
| 1576 | } else if (!strcmp(child->name, "units")) { |
| 1577 | if (d->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1578 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1579 | goto error; |
| 1580 | } |
| 1581 | |
| 1582 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1583 | if (dev_target->nodetype == LYS_LEAFLIST) { |
| 1584 | stritem = &((struct lys_node_leaflist *)dev_target)->units; |
| 1585 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 1586 | stritem = &((struct lys_node_leaf *)dev_target)->units; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1587 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1588 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1589 | 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] | 1590 | goto error; |
| 1591 | } |
| 1592 | |
| 1593 | /* get units value */ |
| 1594 | GETVAL(value, child, "name"); |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1595 | d->units = lydict_insert(ctx, value, 0); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1596 | |
| 1597 | /* apply to target */ |
| 1598 | if (d->mod == LY_DEVIATE_ADD) { |
| 1599 | /* check that there is no current value */ |
| 1600 | if (*stritem) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1601 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1602 | LOGVAL(LYE_SPEC, 0, "Adding property that already exists."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1603 | goto error; |
| 1604 | } |
| 1605 | } |
| 1606 | |
| 1607 | if (d->mod == LY_DEVIATE_DEL) { |
| 1608 | /* check values */ |
| 1609 | if (*stritem != d->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1610 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
| 1611 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1612 | goto error; |
| 1613 | } |
| 1614 | /* remove current units value of the target */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1615 | lydict_remove(ctx, *stritem); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1616 | } else { /* add (already checked) and replace */ |
| 1617 | /* remove current units value of the target ... */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1618 | lydict_remove(ctx, *stritem); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1619 | |
| 1620 | /* ... and replace it with the value specified in deviation */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1621 | *stritem = lydict_insert(ctx, value, 0); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1622 | } |
| 1623 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1624 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1625 | goto error; |
| 1626 | } |
| 1627 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 1628 | /* 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] | 1629 | } |
| 1630 | |
| 1631 | if (c_must) { |
| 1632 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1633 | switch (dev_target->nodetype) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1634 | case LYS_LEAF: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1635 | trg_must = &((struct lys_node_leaf *)dev_target)->must; |
| 1636 | trg_must_size = &((struct lys_node_leaf *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1637 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1638 | case LYS_CONTAINER: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1639 | trg_must = &((struct lys_node_container *)dev_target)->must; |
| 1640 | trg_must_size = &((struct lys_node_container *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1641 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1642 | case LYS_LEAFLIST: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1643 | trg_must = &((struct lys_node_leaflist *)dev_target)->must; |
| 1644 | trg_must_size = &((struct lys_node_leaflist *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1645 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1646 | case LYS_LIST: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1647 | trg_must = &((struct lys_node_list *)dev_target)->must; |
| 1648 | trg_must_size = &((struct lys_node_list *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1649 | break; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 1650 | case LYS_ANYXML: |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1651 | trg_must = &((struct lys_node_anyxml *)dev_target)->must; |
| 1652 | trg_must_size = &((struct lys_node_anyxml *)dev_target)->must_size; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1653 | break; |
| 1654 | default: |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1655 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1656 | 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] | 1657 | goto error; |
| 1658 | } |
| 1659 | |
| 1660 | if (d->mod == LY_DEVIATE_RPL) { |
| 1661 | /* remove target's musts and allocate new array for it */ |
| 1662 | if (!*trg_must) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1663 | LOGVAL(LYE_INARG, LOGLINE(develem), "replace", "deviate"); |
| 1664 | 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] | 1665 | goto error; |
| 1666 | } |
| 1667 | |
| 1668 | for (i = 0; i < list->must_size; i++) { |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1669 | lys_restr_free(ctx, &(*trg_must[i])); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1670 | } |
| 1671 | free(*trg_must); |
| 1672 | *trg_must = d->must = calloc(c_must, sizeof *d->must); |
| 1673 | d->must_size = c_must; |
| 1674 | *trg_must_size = 0; |
| 1675 | } else if (d->mod == LY_DEVIATE_ADD) { |
| 1676 | /* reallocate the must array of the target */ |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1677 | d->must = ly_realloc(*trg_must, (c_must + *trg_must_size) * sizeof *d->must); |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1678 | if (!d->must) { |
| 1679 | LOGMEM; |
| 1680 | goto error; |
| 1681 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1682 | *trg_must = d->must; |
Michal Vasko | 979ad5b | 2015-10-23 10:12:55 +0200 | [diff] [blame] | 1683 | d->must = &((*trg_must)[*trg_must_size]); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1684 | d->must_size = c_must; |
| 1685 | } else { /* LY_DEVIATE_DEL */ |
| 1686 | d->must = calloc(c_must, sizeof *d->must); |
| 1687 | } |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1688 | if (!d->must) { |
| 1689 | LOGMEM; |
| 1690 | goto error; |
| 1691 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1692 | } |
| 1693 | if (c_uniq) { |
| 1694 | /* check target node type */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1695 | if (dev_target->nodetype != LYS_LIST) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1696 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
| 1697 | 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] | 1698 | goto error; |
| 1699 | } |
| 1700 | |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1701 | list = (struct lys_node_list *)dev_target; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1702 | if (d->mod == LY_DEVIATE_RPL) { |
| 1703 | /* remove target's unique and allocate new array for it */ |
| 1704 | if (!list->unique) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1705 | LOGVAL(LYE_INARG, LOGLINE(develem), "replace", "deviate"); |
| 1706 | 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] | 1707 | goto error; |
| 1708 | } |
| 1709 | |
| 1710 | for (i = 0; i < list->unique_size; i++) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1711 | for (j = 0; j < list->unique[i].expr_size; j++) { |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1712 | lydict_remove(ctx, list->unique[i].expr[j]); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1713 | } |
| 1714 | free(list->unique[i].expr); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1715 | } |
| 1716 | free(list->unique); |
| 1717 | list->unique = d->unique = calloc(c_uniq, sizeof *d->unique); |
| 1718 | d->unique_size = c_uniq; |
| 1719 | list->unique_size = 0; |
| 1720 | } else if (d->mod == LY_DEVIATE_ADD) { |
| 1721 | /* reallocate the unique array of the target */ |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1722 | 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] | 1723 | list->unique = d->unique; |
| 1724 | d->unique = &list->unique[list->unique_size]; |
| 1725 | d->unique_size = c_uniq; |
| 1726 | } else { /* LY_DEVIATE_DEL */ |
| 1727 | d->unique = calloc(c_uniq, sizeof *d->unique); |
| 1728 | } |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1729 | if (!d->unique) { |
| 1730 | LOGMEM; |
| 1731 | goto error; |
| 1732 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | /* process deviation properties with 0..n cardinality */ |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 1736 | LY_TREE_FOR(develem->child, child) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1737 | if (!strcmp(child->name, "must")) { |
| 1738 | if (d->mod == LY_DEVIATE_DEL) { |
| 1739 | if (fill_yin_must(module, child, &d->must[d->must_size])) { |
| 1740 | goto error; |
| 1741 | } |
| 1742 | |
| 1743 | /* find must to delete, we are ok with just matching conditions */ |
| 1744 | for (i = 0; i < *trg_must_size; i++) { |
| 1745 | if (d->must[d->must_size].expr == (*trg_must)[i].expr) { |
| 1746 | /* we have a match, free the must structure ... */ |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1747 | lys_restr_free(ctx, &((*trg_must)[i])); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1748 | /* ... and maintain the array */ |
| 1749 | (*trg_must_size)--; |
| 1750 | if (i != *trg_must_size) { |
| 1751 | (*trg_must)[i].expr = (*trg_must)[*trg_must_size].expr; |
| 1752 | (*trg_must)[i].dsc = (*trg_must)[*trg_must_size].dsc; |
| 1753 | (*trg_must)[i].ref = (*trg_must)[*trg_must_size].ref; |
| 1754 | (*trg_must)[i].eapptag = (*trg_must)[*trg_must_size].eapptag; |
| 1755 | (*trg_must)[i].emsg = (*trg_must)[*trg_must_size].emsg; |
| 1756 | } |
| 1757 | if (!(*trg_must_size)) { |
| 1758 | free(*trg_must); |
| 1759 | *trg_must = NULL; |
| 1760 | } else { |
| 1761 | (*trg_must)[*trg_must_size].expr = NULL; |
| 1762 | (*trg_must)[*trg_must_size].dsc = NULL; |
| 1763 | (*trg_must)[*trg_must_size].ref = NULL; |
| 1764 | (*trg_must)[*trg_must_size].eapptag = NULL; |
| 1765 | (*trg_must)[*trg_must_size].emsg = NULL; |
| 1766 | } |
| 1767 | |
| 1768 | i = -1; /* set match flag */ |
| 1769 | break; |
| 1770 | } |
| 1771 | } |
| 1772 | d->must_size++; |
| 1773 | if (i != -1) { |
| 1774 | /* no match found */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1775 | LOGVAL(LYE_INARG, LOGLINE(child), d->must[d->must_size - 1].expr, child->name); |
| 1776 | 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] | 1777 | goto error; |
| 1778 | } |
| 1779 | } else { /* replace or add */ |
Michal Vasko | f92a728 | 2016-02-11 12:35:57 +0100 | [diff] [blame] | 1780 | memset(&((*trg_must)[*trg_must_size]), 0, sizeof **trg_must); |
| 1781 | if (fill_yin_must(module, child, &((*trg_must)[*trg_must_size]))) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1782 | goto error; |
| 1783 | } |
| 1784 | (*trg_must_size)++; |
| 1785 | } |
| 1786 | } else if (!strcmp(child->name, "unique")) { |
| 1787 | if (d->mod == LY_DEVIATE_DEL) { |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1788 | if (fill_yin_unique(module, dev_target, child, &d->unique[d->unique_size], NULL)) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1789 | d->unique_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1790 | goto error; |
| 1791 | } |
| 1792 | |
| 1793 | /* find unique structures to delete */ |
| 1794 | for (i = 0; i < list->unique_size; i++) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1795 | 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] | 1796 | continue; |
| 1797 | } |
| 1798 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1799 | for (j = 0; j < d->unique[d->unique_size].expr_size; j++) { |
| 1800 | 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] | 1801 | break; |
| 1802 | } |
| 1803 | } |
| 1804 | |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1805 | if (j == d->unique[d->unique_size].expr_size) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1806 | /* we have a match, free the unique structure ... */ |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1807 | for (j = 0; j < list->unique[i].expr_size; j++) { |
Michal Vasko | dc48e7f | 2016-02-11 12:35:27 +0100 | [diff] [blame] | 1808 | lydict_remove(ctx, list->unique[i].expr[j]); |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1809 | } |
| 1810 | free(list->unique[i].expr); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1811 | /* ... and maintain the array */ |
| 1812 | list->unique_size--; |
| 1813 | if (i != list->unique_size) { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1814 | list->unique[i].expr_size = list->unique[list->unique_size].expr_size; |
| 1815 | list->unique[i].expr = list->unique[list->unique_size].expr; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | if (!list->unique_size) { |
| 1819 | free(list->unique); |
| 1820 | list->unique = NULL; |
| 1821 | } else { |
Radek Krejci | 581ce77 | 2015-11-10 17:22:40 +0100 | [diff] [blame] | 1822 | list->unique[list->unique_size].expr_size = 0; |
| 1823 | list->unique[list->unique_size].expr = NULL; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1824 | } |
| 1825 | |
| 1826 | i = -1; /* set match flag */ |
| 1827 | break; |
| 1828 | } |
| 1829 | } |
| 1830 | |
| 1831 | d->unique_size++; |
| 1832 | if (i != -1) { |
| 1833 | /* no match found */ |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1834 | LOGVAL(LYE_INARG, LOGLINE(child), lyxml_get_attr(child, "tag", NULL), child->name); |
| 1835 | LOGVAL(LYE_SPEC, 0, "Value differs from the target being deleted."); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1836 | goto error; |
| 1837 | } |
| 1838 | } else { /* replace or add */ |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 1839 | i = fill_yin_unique(module, dev_target, child, &list->unique[list->unique_size], NULL); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 1840 | list->unique_size++; |
| 1841 | if (i) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1842 | goto error; |
| 1843 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1844 | } |
| 1845 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1846 | } |
Radek Krejci | 5b91764 | 2015-07-02 09:03:13 +0200 | [diff] [blame] | 1847 | |
| 1848 | dev->deviate_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1849 | } |
| 1850 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1851 | return EXIT_SUCCESS; |
| 1852 | |
| 1853 | error: |
| 1854 | |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1855 | return EXIT_FAILURE; |
| 1856 | } |
| 1857 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1858 | /* logs directly */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 1859 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 1860 | 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] | 1861 | struct unres_schema *unres) |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1862 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1863 | const char *value; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1864 | struct lyxml_elem *child, *next; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1865 | struct lys_node *node; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 1866 | int c = 0, ret; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1867 | |
Michal Vasko | 591e0b2 | 2015-08-13 13:53:43 +0200 | [diff] [blame] | 1868 | aug->nodetype = LYS_AUGMENT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1869 | GETVAL(value, yin, "target-node"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 1870 | aug->target_name = transform_schema2json(module, value, LOGLINE(yin)); |
Michal Vasko | 488c19e | 2015-10-20 15:21:00 +0200 | [diff] [blame] | 1871 | if (!aug->target_name) { |
| 1872 | goto error; |
| 1873 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1874 | aug->parent = parent; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1875 | |
Michal Vasko | 1d87a92 | 2015-08-21 12:57:16 +0200 | [diff] [blame] | 1876 | 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] | 1877 | goto error; |
| 1878 | } |
| 1879 | |
| 1880 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1881 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 1882 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1883 | lyxml_free(module->ctx, child); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 1884 | continue; |
| 1885 | } |
| 1886 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1887 | if (!strcmp(child->name, "if-feature")) { |
| 1888 | c++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1889 | continue; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1890 | } else if (!strcmp(child->name, "when")) { |
| 1891 | if (aug->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1892 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1893 | goto error; |
| 1894 | } |
| 1895 | |
| 1896 | aug->when = read_yin_when(module, child); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1897 | if (!aug->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1898 | lyxml_free(module->ctx, child); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 1899 | goto error; |
| 1900 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 1901 | if (lyxp_syntax_check(aug->when->cond, LOGLINE(child))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1902 | goto error; |
| 1903 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1904 | lyxml_free(module->ctx, child); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1905 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1906 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1907 | /* check allowed data sub-statements */ |
| 1908 | } else if (!strcmp(child->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1909 | node = read_yin_container(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1910 | } else if (!strcmp(child->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1911 | node = read_yin_leaflist(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1912 | } else if (!strcmp(child->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1913 | node = read_yin_leaf(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1914 | } else if (!strcmp(child->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1915 | node = read_yin_list(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1916 | } else if (!strcmp(child->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1917 | node = read_yin_uses(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1918 | } else if (!strcmp(child->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1919 | node = read_yin_case(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1920 | } else if (!strcmp(child->name, "case")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1921 | node = read_yin_case(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, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1923 | node = read_yin_anyxml(module, (struct lys_node *)aug, child, 0, unres); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1924 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1925 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1926 | goto error; |
| 1927 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1928 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1929 | if (!node) { |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1930 | goto error; |
| 1931 | } |
| 1932 | |
| 1933 | /* check for mandatory nodes - if the target node is in another module |
| 1934 | * the added nodes cannot be mandatory |
| 1935 | */ |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 1936 | if ((!parent || (parent->nodetype != LYS_USES)) && lyp_check_mandatory(node)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 1937 | 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] | 1938 | goto error; |
| 1939 | } |
| 1940 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 1941 | node = NULL; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1942 | lyxml_free(module->ctx, child); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | if (c) { |
| 1946 | aug->features = calloc(c, sizeof *aug->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 1947 | if (!aug->features) { |
| 1948 | LOGMEM; |
| 1949 | goto error; |
| 1950 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1951 | } |
| 1952 | |
| 1953 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 1954 | if (!strcmp(child->name, "if-feature")) { |
| 1955 | GETVAL(value, child, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 1956 | if (!(value = transform_schema2json(module, value, LOGLINE(child)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 1957 | goto error; |
| 1958 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 1959 | /* hack - store pointer to the parent node for later status check */ |
| 1960 | aug->features[aug->features_size] = (struct lys_feature *)aug; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 1961 | 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] | 1962 | LOGLINE(child)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 1963 | aug->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 1964 | lydict_remove(module->ctx, value); |
| 1965 | if (ret == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 1966 | goto error; |
| 1967 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 1968 | lyxml_free(module->ctx, child); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1969 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 1970 | } |
| 1971 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 1972 | /* aug->child points to the parsed nodes, they must now be |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 1973 | * connected to the tree and adjusted (if possible right now). |
| 1974 | * However, if this is augment in a uses, it gets resolved |
| 1975 | * when the uses does and cannot be resolved now for sure |
| 1976 | * (the grouping was not yet copied into uses). |
| 1977 | */ |
| 1978 | if (!parent || (parent->nodetype != LYS_USES)) { |
Michal Vasko | 3edeaf7 | 2016-02-11 13:17:43 +0100 | [diff] [blame] | 1979 | if (resolve_augment(aug, NULL)) { |
Michal Vasko | 4adc10f | 2015-08-11 15:26:17 +0200 | [diff] [blame] | 1980 | LOGVAL(LYE_INRESOLV, LOGLINE(yin), "augment", aug->target_name); |
| 1981 | goto error; |
| 1982 | } |
Michal Vasko | 49291b3 | 2015-08-06 09:49:41 +0200 | [diff] [blame] | 1983 | } |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1984 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1985 | return EXIT_SUCCESS; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1986 | |
| 1987 | error: |
| 1988 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1989 | return EXIT_FAILURE; |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 1990 | } |
| 1991 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 1992 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1993 | static int |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 1994 | 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] | 1995 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 1996 | struct lyxml_elem *sub, *next; |
| 1997 | const char *value; |
| 1998 | char *endptr; |
| 1999 | int f_mand = 0, f_min = 0, f_max = 0; |
| 2000 | int c_must = 0; |
| 2001 | int r; |
| 2002 | unsigned long int val; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2003 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2004 | 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] | 2005 | goto error; |
| 2006 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2007 | |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2008 | GETVAL(value, yin, "target-node"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 2009 | rfn->target_name = transform_schema2json(module, value, LOGLINE(yin)); |
Michal Vasko | a8b2595 | 2015-10-20 15:30:25 +0200 | [diff] [blame] | 2010 | if (!rfn->target_name) { |
| 2011 | goto error; |
| 2012 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2013 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2014 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2015 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2016 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2017 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2018 | continue; |
| 2019 | } |
| 2020 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2021 | /* limited applicability */ |
| 2022 | if (!strcmp(sub->name, "default")) { |
| 2023 | /* leaf or choice */ |
| 2024 | if (rfn->mod.dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2025 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2026 | goto error; |
| 2027 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2028 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2029 | /* check possibility of statements combination */ |
| 2030 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2031 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2032 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2033 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2034 | goto error; |
| 2035 | } |
| 2036 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2037 | rfn->target_type = LYS_LEAF | LYS_CHOICE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2038 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2039 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2040 | GETVAL(value, sub, "value"); |
| 2041 | rfn->mod.dflt = lydict_insert(module->ctx, value, strlen(value)); |
| 2042 | } else if (!strcmp(sub->name, "mandatory")) { |
| 2043 | /* leaf, choice or anyxml */ |
| 2044 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2045 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2046 | goto error; |
| 2047 | } |
| 2048 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2049 | * multiple mandatory statements with the "false" value |
| 2050 | */ |
| 2051 | f_mand = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2052 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2053 | /* check possibility of statements combination */ |
| 2054 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2055 | rfn->target_type &= (LYS_LEAF | LYS_CHOICE | LYS_ANYXML); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2056 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2057 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2058 | goto error; |
| 2059 | } |
| 2060 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2061 | rfn->target_type = LYS_LEAF | LYS_CHOICE | LYS_ANYXML; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2062 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2063 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2064 | GETVAL(value, sub, "value"); |
| 2065 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2066 | rfn->flags |= LYS_MAND_TRUE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2067 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2068 | rfn->flags |= LYS_MAND_FALSE; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2069 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2070 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2071 | goto error; |
| 2072 | } |
| 2073 | } else if (!strcmp(sub->name, "min-elements")) { |
| 2074 | /* list or leaf-list */ |
| 2075 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2076 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2077 | goto error; |
| 2078 | } |
| 2079 | f_min = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2080 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2081 | /* check possibility of statements combination */ |
| 2082 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2083 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2084 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2085 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2086 | goto error; |
| 2087 | } |
| 2088 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2089 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2090 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2091 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2092 | GETVAL(value, sub, "value"); |
| 2093 | while (isspace(value[0])) { |
| 2094 | value++; |
| 2095 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2096 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2097 | /* convert it to uint32_t */ |
| 2098 | errno = 0; |
| 2099 | endptr = NULL; |
| 2100 | val = strtoul(value, &endptr, 10); |
| 2101 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2102 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2103 | goto error; |
| 2104 | } |
| 2105 | rfn->mod.list.min = (uint32_t) val; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2106 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2107 | /* magic - bit 3 in flags means min set */ |
| 2108 | rfn->flags |= 0x04; |
| 2109 | } else if (!strcmp(sub->name, "max-elements")) { |
| 2110 | /* list or leaf-list */ |
| 2111 | if (f_max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2112 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2113 | goto error; |
| 2114 | } |
| 2115 | f_max = 1; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2116 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2117 | /* check possibility of statements combination */ |
| 2118 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2119 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2120 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2121 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2122 | goto error; |
| 2123 | } |
| 2124 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2125 | rfn->target_type = LYS_LIST | LYS_LEAFLIST; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2126 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2127 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2128 | GETVAL(value, sub, "value"); |
| 2129 | while (isspace(value[0])) { |
| 2130 | value++; |
| 2131 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2132 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2133 | /* convert it to uint32_t */ |
| 2134 | errno = 0; |
| 2135 | endptr = NULL; |
| 2136 | val = strtoul(value, &endptr, 10); |
| 2137 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2138 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2139 | goto error; |
| 2140 | } |
| 2141 | rfn->mod.list.max = (uint32_t) val; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2142 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2143 | /* magic - bit 4 in flags means min set */ |
| 2144 | rfn->flags |= 0x08; |
| 2145 | } else if (!strcmp(sub->name, "presence")) { |
| 2146 | /* container */ |
| 2147 | if (rfn->mod.presence) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2148 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2149 | goto error; |
| 2150 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2151 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2152 | /* check possibility of statements combination */ |
| 2153 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2154 | rfn->target_type &= LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2155 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2156 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2157 | goto error; |
| 2158 | } |
| 2159 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2160 | rfn->target_type = LYS_CONTAINER; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2161 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2162 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2163 | GETVAL(value, sub, "value"); |
| 2164 | rfn->mod.presence = lydict_insert(module->ctx, value, strlen(value)); |
| 2165 | } else if (!strcmp(sub->name, "must")) { |
| 2166 | /* leaf-list, list, container or anyxml */ |
| 2167 | /* check possibility of statements combination */ |
| 2168 | if (rfn->target_type) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2169 | rfn->target_type &= (LYS_LIST | LYS_LEAFLIST | LYS_CONTAINER | LYS_ANYXML); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2170 | if (!rfn->target_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2171 | LOGVAL(LYE_SPEC, LOGLINE(sub), "invalid combination of refine substatements"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2172 | goto error; |
| 2173 | } |
| 2174 | } else { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2175 | rfn->target_type = LYS_LIST | LYS_LEAFLIST | LYS_CONTAINER | LYS_ANYXML; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2176 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2177 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2178 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 2179 | continue; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2180 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2181 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2182 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2183 | goto error; |
| 2184 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2185 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2186 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2187 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2188 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2189 | /* process nodes with cardinality of 0..n */ |
| 2190 | if (c_must) { |
| 2191 | rfn->must = calloc(c_must, sizeof *rfn->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2192 | if (!rfn->must) { |
| 2193 | LOGMEM; |
| 2194 | goto error; |
| 2195 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2196 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2197 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 2198 | r = fill_yin_must(module, sub, &rfn->must[rfn->must_size]); |
| 2199 | rfn->must_size++; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2200 | if (r) { |
| 2201 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2202 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 2203 | 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] | 2204 | goto error; |
| 2205 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2206 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2207 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2208 | return EXIT_SUCCESS; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2209 | |
| 2210 | error: |
| 2211 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2212 | return EXIT_FAILURE; |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 2213 | } |
| 2214 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2215 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2216 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2217 | 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] | 2218 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2219 | struct lyxml_elem *child; |
| 2220 | const char *value; |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2221 | int count; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2222 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2223 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2224 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2225 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2226 | continue; |
| 2227 | } |
| 2228 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2229 | if (!strcmp(child->name, "prefix")) { |
| 2230 | GETVAL(value, child, "value"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 2231 | if (lyp_check_identifier(value, LY_IDENT_PREFIX, LOGLINE(child), module, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2232 | goto error; |
| 2233 | } |
| 2234 | imp->prefix = lydict_insert(module->ctx, value, strlen(value)); |
| 2235 | } else if (!strcmp(child->name, "revision-date")) { |
| 2236 | if (imp->rev[0]) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2237 | LOGVAL(LYE_TOOMANY, LOGLINE(child), "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2238 | goto error; |
| 2239 | } |
| 2240 | GETVAL(value, child, "date"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 2241 | if (lyp_check_date(value, LOGLINE(child))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2242 | goto error; |
| 2243 | } |
| 2244 | memcpy(imp->rev, value, LY_REV_SIZE - 1); |
| 2245 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2246 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2247 | goto error; |
| 2248 | } |
| 2249 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2250 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2251 | /* check mandatory information */ |
| 2252 | if (!imp->prefix) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2253 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "prefix", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2254 | goto error; |
| 2255 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2256 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2257 | GETVAL(value, yin, "module"); |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2258 | |
| 2259 | /* check for circular import, store it if passed */ |
| 2260 | if (!module->ctx->models.parsing) { |
| 2261 | count = 0; |
| 2262 | } else { |
| 2263 | for (count = 0; module->ctx->models.parsing[count]; ++count) { |
| 2264 | if (value == module->ctx->models.parsing[count]) { |
| 2265 | LOGERR(LY_EVALID, "Circular import dependency on the module \"%s\".", value); |
| 2266 | goto error; |
| 2267 | } |
| 2268 | } |
| 2269 | } |
| 2270 | ++count; |
| 2271 | module->ctx->models.parsing = |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2272 | ly_realloc(module->ctx->models.parsing, (count + 1) * sizeof *module->ctx->models.parsing); |
| 2273 | if (!module->ctx->models.parsing) { |
| 2274 | LOGMEM; |
| 2275 | goto error; |
| 2276 | } |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2277 | module->ctx->models.parsing[count - 1] = value; |
| 2278 | module->ctx->models.parsing[count] = NULL; |
| 2279 | |
| 2280 | /* try to load the module */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 2281 | 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] | 2282 | if (!imp->module) { |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 2283 | /* whether to use a user callback is decided in the function */ |
| 2284 | 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] | 2285 | } |
| 2286 | |
| 2287 | /* remove the new module name now that its parsing is finished (even if failed) */ |
| 2288 | if (module->ctx->models.parsing[count] || (module->ctx->models.parsing[count - 1] != value)) { |
| 2289 | LOGINT; |
| 2290 | } |
| 2291 | --count; |
| 2292 | if (count) { |
| 2293 | module->ctx->models.parsing[count] = NULL; |
| 2294 | } else { |
| 2295 | free(module->ctx->models.parsing); |
| 2296 | module->ctx->models.parsing = NULL; |
| 2297 | } |
| 2298 | |
| 2299 | /* check the result */ |
| 2300 | if (!imp->module) { |
| 2301 | LOGVAL(LYE_INARG, LOGLINE(yin), value, yin->name); |
| 2302 | LOGERR(LY_EVALID, "Importing \"%s\" module into \"%s\" failed.", value, module->name); |
| 2303 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2304 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2305 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2306 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2307 | |
| 2308 | error: |
| 2309 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2310 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2311 | } |
| 2312 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2313 | /* logs directly */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2314 | static int |
Michal Vasko | 5ff7882 | 2016-02-12 09:33:31 +0100 | [diff] [blame] | 2315 | fill_yin_include(struct lys_module *module, struct lys_submodule *submodule, struct lyxml_elem *yin, |
| 2316 | struct lys_include *inc, struct unres_schema *unres) |
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 | struct lyxml_elem *child; |
| 2319 | const char *value; |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 2320 | char *module_data; |
| 2321 | void (*module_data_free)(char *module_data) = NULL; |
| 2322 | LYS_INFORMAT format = LYS_IN_UNKNOWN; |
Michal Vasko | 9c4c99d | 2016-02-11 15:47:08 +0100 | [diff] [blame] | 2323 | int count, i; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2324 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2325 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2326 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2327 | /* garbage */ |
| 2328 | continue; |
| 2329 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2330 | if (!strcmp(child->name, "revision-date")) { |
| 2331 | if (inc->rev[0]) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2332 | LOGVAL(LYE_TOOMANY, LOGLINE(child), "revision-date", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2333 | goto error; |
| 2334 | } |
| 2335 | GETVAL(value, child, "date"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 2336 | if (lyp_check_date(value, LOGLINE(child))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2337 | goto error; |
| 2338 | } |
| 2339 | memcpy(inc->rev, value, LY_REV_SIZE - 1); |
| 2340 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2341 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2342 | goto error; |
| 2343 | } |
| 2344 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2345 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2346 | GETVAL(value, yin, "module"); |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2347 | |
Michal Vasko | 9c4c99d | 2016-02-11 15:47:08 +0100 | [diff] [blame] | 2348 | /* check that the submodule was not included yet (previous submodule could have included it) */ |
| 2349 | for (i = 0; i < module->inc_size; ++i) { |
| 2350 | if (module->inc[i].submodule && (module->inc[i].submodule->name == value)) { |
Michal Vasko | 5ff7882 | 2016-02-12 09:33:31 +0100 | [diff] [blame] | 2351 | /* copy the duplicate into the result */ |
Michal Vasko | 9c4c99d | 2016-02-11 15:47:08 +0100 | [diff] [blame] | 2352 | memcpy(inc, &module->inc[i], sizeof *inc); |
Michal Vasko | 9c4c99d | 2016-02-11 15:47:08 +0100 | [diff] [blame] | 2353 | |
Michal Vasko | 5ff7882 | 2016-02-12 09:33:31 +0100 | [diff] [blame] | 2354 | if (submodule) { |
| 2355 | /* we don't care if it was external or not */ |
| 2356 | inc->external = 0; |
| 2357 | } else if (inc->external) { |
| 2358 | /* remove the duplicate */ |
| 2359 | --module->inc_size; |
| 2360 | memmove(&module->inc[i], &module->inc[i + 1], (module->inc_size - i) * sizeof *inc); |
| 2361 | module->inc = ly_realloc(module->inc, module->inc_size * sizeof *module->inc); |
| 2362 | |
| 2363 | /* it is no longer external */ |
| 2364 | inc->external = 0; |
| 2365 | } |
| 2366 | /* if !submodule && !inc->external, we just create a duplicate so it is detected and ended with error */ |
Michal Vasko | 9c4c99d | 2016-02-11 15:47:08 +0100 | [diff] [blame] | 2367 | |
| 2368 | return EXIT_SUCCESS; |
| 2369 | } |
| 2370 | } |
| 2371 | |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2372 | /* check for circular include, store it if passed */ |
| 2373 | if (!module->ctx->models.parsing) { |
| 2374 | count = 0; |
| 2375 | } else { |
| 2376 | for (count = 0; module->ctx->models.parsing[count]; ++count) { |
| 2377 | if (value == module->ctx->models.parsing[count]) { |
| 2378 | LOGERR(LY_EVALID, "Circular include dependency on the submodule \"%s\".", value); |
| 2379 | goto error; |
| 2380 | } |
| 2381 | } |
| 2382 | } |
| 2383 | ++count; |
| 2384 | module->ctx->models.parsing = |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2385 | ly_realloc(module->ctx->models.parsing, (count + 1) * sizeof *module->ctx->models.parsing); |
| 2386 | if (!module->ctx->models.parsing) { |
| 2387 | LOGMEM; |
| 2388 | goto error; |
| 2389 | } |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2390 | module->ctx->models.parsing[count - 1] = value; |
| 2391 | module->ctx->models.parsing[count] = NULL; |
| 2392 | |
| 2393 | /* try to load the submodule */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 2394 | 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] | 2395 | if (!inc->submodule) { |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 2396 | if (module->ctx->module_clb) { |
| 2397 | module_data = module->ctx->module_clb(value, inc->rev[0] ? inc->rev : NULL, module->ctx->module_clb_data, |
| 2398 | &format, &module_data_free); |
| 2399 | if (module_data) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 2400 | inc->submodule = lys_submodule_parse(module, module_data, format, unres); |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 2401 | if (module_data_free) { |
| 2402 | module_data_free(module_data); |
| 2403 | } else { |
| 2404 | free(module_data); |
| 2405 | } |
| 2406 | } else { |
| 2407 | LOGERR(LY_EVALID, "User module retrieval callback failed!"); |
| 2408 | } |
| 2409 | } else { |
| 2410 | inc->submodule = (struct lys_submodule *)lyp_search_file(module->ctx, module, value, |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 2411 | inc->rev[0] ? inc->rev : NULL, unres); |
Michal Vasko | 99b0aad | 2015-12-01 12:28:51 +0100 | [diff] [blame] | 2412 | } |
Michal Vasko | 1b882eb | 2015-10-22 11:43:14 +0200 | [diff] [blame] | 2413 | } |
| 2414 | |
| 2415 | /* remove the new submodule name now that its parsing is finished (even if failed) */ |
| 2416 | if (module->ctx->models.parsing[count] || (module->ctx->models.parsing[count - 1] != value)) { |
| 2417 | LOGINT; |
| 2418 | } |
| 2419 | --count; |
| 2420 | if (count) { |
| 2421 | module->ctx->models.parsing[count] = NULL; |
| 2422 | } else { |
| 2423 | free(module->ctx->models.parsing); |
| 2424 | module->ctx->models.parsing = NULL; |
| 2425 | } |
| 2426 | |
| 2427 | /* check the result */ |
| 2428 | if (!inc->submodule) { |
| 2429 | LOGVAL(LYE_INARG, LOGLINE(yin), value, yin->name); |
| 2430 | LOGERR(LY_EVALID, "Including \"%s\" module into \"%s\" failed.", value, module->name); |
| 2431 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2432 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2433 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2434 | return EXIT_SUCCESS; |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 2435 | |
| 2436 | error: |
| 2437 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2438 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 2439 | } |
| 2440 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2441 | /* logs directly |
| 2442 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2443 | * Covers: |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 2444 | * description, reference, status, optionaly config |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 2445 | * |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2446 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2447 | static int |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2448 | read_yin_common(struct lys_module *module, struct lys_node *parent, |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2449 | struct lys_node *node, struct lyxml_elem *xmlnode, int opt) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2450 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2451 | const char *value; |
| 2452 | struct lyxml_elem *sub, *next; |
| 2453 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2454 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2455 | if (opt & OPT_MODULE) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2456 | node->module = module; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2457 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2458 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2459 | if (opt & OPT_IDENT) { |
| 2460 | GETVAL(value, xmlnode, "name"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 2461 | if (lyp_check_identifier(value, LY_IDENT_NAME, LOGLINE(xmlnode), NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2462 | goto error; |
| 2463 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2464 | node->name = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2465 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2466 | |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2467 | /* inherit NACM flags */ |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2468 | if ((opt & OPT_NACMEXT) && parent) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2469 | node->nacm = parent->nacm; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2470 | } |
| 2471 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2472 | /* process local parameters */ |
| 2473 | LY_TREE_FOR_SAFE(xmlnode->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2474 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2475 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2476 | lyxml_free(ctx, sub); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2477 | continue; |
| 2478 | } |
| 2479 | if (strcmp(sub->ns->value, LY_NSYIN)) { |
| 2480 | /* NACM extensions */ |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2481 | if ((opt & OPT_NACMEXT) && !strcmp(sub->ns->value, LY_NSNACM)) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2482 | if (!strcmp(sub->name, "default-deny-write")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2483 | node->nacm |= LYS_NACM_DENYW; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2484 | } else if (!strcmp(sub->name, "default-deny-all")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2485 | node->nacm |= LYS_NACM_DENYA; |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2486 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2487 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 2488 | goto error; |
| 2489 | } |
| 2490 | } |
| 2491 | |
| 2492 | /* else garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2493 | lyxml_free(ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2494 | continue; |
| 2495 | } |
| 2496 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2497 | if (!strcmp(sub->name, "description")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2498 | if (node->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2499 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2500 | goto error; |
| 2501 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2502 | node->dsc = read_yin_subnode(ctx, sub, "text"); |
| 2503 | if (!node->dsc) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2504 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2505 | } |
| 2506 | } else if (!strcmp(sub->name, "reference")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2507 | if (node->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2508 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2509 | goto error; |
| 2510 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2511 | node->ref = read_yin_subnode(ctx, sub, "text"); |
| 2512 | if (!node->ref) { |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2513 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2514 | } |
| 2515 | } else if (!strcmp(sub->name, "status")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2516 | if (node->flags & LYS_STATUS_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2517 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2518 | goto error; |
| 2519 | } |
| 2520 | GETVAL(value, sub, "value"); |
| 2521 | if (!strcmp(value, "current")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2522 | node->flags |= LYS_STATUS_CURR; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2523 | } else if (!strcmp(value, "deprecated")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2524 | node->flags |= LYS_STATUS_DEPRC; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2525 | } else if (!strcmp(value, "obsolete")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2526 | node->flags |= LYS_STATUS_OBSLT; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2527 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2528 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2529 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2530 | } |
| 2531 | } else if ((opt & OPT_CONFIG) && !strcmp(sub->name, "config")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2532 | if (node->flags & LYS_CONFIG_MASK) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2533 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, xmlnode->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2534 | goto error; |
| 2535 | } |
| 2536 | GETVAL(value, sub, "value"); |
| 2537 | if (!strcmp(value, "false")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2538 | node->flags |= LYS_CONFIG_R; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2539 | } else if (!strcmp(value, "true")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2540 | node->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2541 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2542 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2543 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2544 | } |
| 2545 | } else { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2546 | /* skip the lyxml_free */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2547 | continue; |
| 2548 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2549 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2550 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2551 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2552 | if ((opt & OPT_INHERIT) && !(node->flags & LYS_CONFIG_MASK)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2553 | /* get config flag from parent */ |
| 2554 | if (parent) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2555 | node->flags |= parent->flags & LYS_CONFIG_MASK; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2556 | } else { |
| 2557 | /* default config is true */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2558 | node->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2559 | } |
| 2560 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2561 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2562 | return EXIT_SUCCESS; |
Radek Krejci | eac3553 | 2015-05-31 19:09:15 +0200 | [diff] [blame] | 2563 | |
| 2564 | error: |
| 2565 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2566 | return EXIT_FAILURE; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2567 | } |
| 2568 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2569 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2570 | static struct lys_when * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2571 | read_yin_when(struct lys_module *module, struct lyxml_elem *yin) |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2572 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2573 | struct lys_when *retval = NULL; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2574 | struct lyxml_elem *child; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2575 | const char *value; |
| 2576 | |
| 2577 | retval = calloc(1, sizeof *retval); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2578 | if (!retval) { |
| 2579 | LOGMEM; |
| 2580 | return NULL; |
| 2581 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2582 | |
| 2583 | GETVAL(value, yin, "condition"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 2584 | retval->cond = transform_schema2json(module, value, LOGLINE(yin)); |
Michal Vasko | f989338 | 2015-10-09 14:03:04 +0200 | [diff] [blame] | 2585 | if (!retval->cond) { |
| 2586 | goto error; |
| 2587 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2588 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2589 | LY_TREE_FOR(yin->child, child) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2590 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
| 2591 | /* garbage */ |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2592 | continue; |
| 2593 | } |
| 2594 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2595 | if (!strcmp(child->name, "description")) { |
| 2596 | if (retval->dsc) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2597 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2598 | goto error; |
| 2599 | } |
| 2600 | retval->dsc = read_yin_subnode(module->ctx, child, "text"); |
| 2601 | if (!retval->dsc) { |
| 2602 | goto error; |
| 2603 | } |
| 2604 | } else if (!strcmp(child->name, "reference")) { |
| 2605 | if (retval->ref) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2606 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2607 | goto error; |
| 2608 | } |
| 2609 | retval->ref = read_yin_subnode(module->ctx, child, "text"); |
| 2610 | if (!retval->ref) { |
| 2611 | goto error; |
| 2612 | } |
| 2613 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2614 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2615 | goto error; |
| 2616 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | return retval; |
| 2620 | |
| 2621 | error: |
| 2622 | |
Michal Vasko | 0308dd6 | 2015-10-07 09:14:40 +0200 | [diff] [blame] | 2623 | lys_when_free(module->ctx, retval); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2624 | return NULL; |
| 2625 | } |
| 2626 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2627 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2628 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 2629 | read_yin_case(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 2630 | struct unres_schema *unres) |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2631 | { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2632 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2633 | struct lys_node_case *cs; |
| 2634 | struct lys_node *retval, *node = NULL; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 2635 | int c_ftrs = 0, ret; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2636 | const char *value; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2637 | |
Radek Krejci | e867c85 | 2015-08-27 09:52:34 +0200 | [diff] [blame] | 2638 | /* init */ |
| 2639 | memset(&root, 0, sizeof root); |
| 2640 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2641 | cs = calloc(1, sizeof *cs); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2642 | if (!cs) { |
| 2643 | LOGMEM; |
| 2644 | return NULL; |
| 2645 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2646 | cs->nodetype = LYS_CASE; |
| 2647 | cs->prev = (struct lys_node *)cs; |
| 2648 | retval = (struct lys_node *)cs; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2649 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 2650 | 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] | 2651 | goto error; |
| 2652 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2653 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 2654 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 2655 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2656 | /* insert the node into the schema tree */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 2657 | 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] | 2658 | goto error; |
| 2659 | } |
| 2660 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2661 | /* process choice's specific children */ |
| 2662 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2663 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2664 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2665 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2666 | continue; |
| 2667 | } |
| 2668 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2669 | if (!strcmp(sub->name, "container") || |
| 2670 | !strcmp(sub->name, "leaf-list") || |
| 2671 | !strcmp(sub->name, "leaf") || |
| 2672 | !strcmp(sub->name, "list") || |
| 2673 | !strcmp(sub->name, "uses") || |
| 2674 | !strcmp(sub->name, "choice") || |
| 2675 | !strcmp(sub->name, "anyxml")) { |
| 2676 | |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 2677 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2678 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2679 | } else if (!strcmp(sub->name, "if-feature")) { |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2680 | c_ftrs++; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2681 | /* 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] | 2682 | continue; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2683 | } else if (!strcmp(sub->name, "when")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2684 | if (cs->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2685 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2686 | goto error; |
| 2687 | } |
| 2688 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2689 | cs->when = read_yin_when(module, sub); |
| 2690 | if (!cs->when) { |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2691 | goto error; |
| 2692 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 2693 | if (lyxp_syntax_check(cs->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2694 | goto error; |
| 2695 | } |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2696 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2697 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2698 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2699 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2700 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2701 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2702 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2703 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2704 | if (c_ftrs) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2705 | cs->features = calloc(c_ftrs, sizeof *cs->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2706 | if (!cs->features) { |
| 2707 | LOGMEM; |
| 2708 | goto error; |
| 2709 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2710 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2711 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2712 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 2713 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 2714 | goto error; |
| 2715 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 2716 | /* hack - store pointer to the parent node for later status check */ |
| 2717 | cs->features[cs->features_size] = (struct lys_feature *)cs; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 2718 | 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] | 2719 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 2720 | cs->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 2721 | lydict_remove(module->ctx, value); |
| 2722 | if (ret == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2723 | goto error; |
| 2724 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2725 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 2726 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2727 | /* last part - process data nodes */ |
| 2728 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 2729 | if (!strcmp(sub->name, "container")) { |
| 2730 | node = read_yin_container(module, retval, sub, resolve, unres); |
| 2731 | } else if (!strcmp(sub->name, "leaf-list")) { |
| 2732 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
| 2733 | } else if (!strcmp(sub->name, "leaf")) { |
| 2734 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
| 2735 | } else if (!strcmp(sub->name, "list")) { |
| 2736 | node = read_yin_list(module, retval, sub, resolve, unres); |
| 2737 | } else if (!strcmp(sub->name, "choice")) { |
| 2738 | node = read_yin_choice(module, retval, sub, resolve, unres); |
| 2739 | } else if (!strcmp(sub->name, "uses")) { |
| 2740 | node = read_yin_uses(module, retval, sub, resolve, unres); |
| 2741 | } else if (!strcmp(sub->name, "anyxml")) { |
| 2742 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
| 2743 | } |
| 2744 | if (!node) { |
| 2745 | goto error; |
| 2746 | } |
| 2747 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2748 | lyxml_free(module->ctx, sub); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2749 | } |
| 2750 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2751 | return retval; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2752 | |
| 2753 | error: |
| 2754 | |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2755 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2756 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 29fc018 | 2015-08-24 15:02:39 +0200 | [diff] [blame] | 2757 | } |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 2758 | lys_node_free(retval, NULL); |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2759 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2760 | return NULL; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2761 | } |
| 2762 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2763 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2764 | static struct lys_node * |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 2765 | 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] | 2766 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2767 | struct lyxml_elem *sub, *next; |
| 2768 | struct ly_ctx *const ctx = module->ctx; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2769 | struct lys_node *retval, *node = NULL; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2770 | struct lys_node_choice *choice; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2771 | const char *value, *dflt_str = NULL; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 2772 | int f_mand = 0, c_ftrs = 0, ret; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2773 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2774 | choice = calloc(1, sizeof *choice); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2775 | if (!choice) { |
| 2776 | LOGMEM; |
| 2777 | return NULL; |
| 2778 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2779 | choice->nodetype = LYS_CHOICE; |
| 2780 | choice->prev = (struct lys_node *)choice; |
| 2781 | retval = (struct lys_node *)choice; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2782 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 2783 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 2784 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2785 | goto error; |
| 2786 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2787 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 2788 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 2789 | |
Michal Vasko | 3a0043f | 2015-08-12 12:11:30 +0200 | [diff] [blame] | 2790 | /* insert the node into the schema tree */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 2791 | 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] | 2792 | goto error; |
| 2793 | } |
| 2794 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2795 | /* process choice's specific children */ |
| 2796 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2797 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2798 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2799 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2800 | continue; |
| 2801 | } |
| 2802 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2803 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2804 | if (!(node = read_yin_container(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2805 | goto error; |
| 2806 | } |
| 2807 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2808 | if (!(node = read_yin_leaflist(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2809 | goto error; |
| 2810 | } |
| 2811 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2812 | if (!(node = read_yin_leaf(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2813 | goto error; |
| 2814 | } |
| 2815 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2816 | if (!(node = read_yin_list(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2817 | goto error; |
| 2818 | } |
| 2819 | } else if (!strcmp(sub->name, "case")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2820 | if (!(node = read_yin_case(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2821 | goto error; |
| 2822 | } |
| 2823 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2824 | if (!(node = read_yin_anyxml(module, retval, sub, resolve, unres))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2825 | goto error; |
| 2826 | } |
| 2827 | } else if (!strcmp(sub->name, "default")) { |
| 2828 | if (dflt_str) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2829 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2830 | goto error; |
| 2831 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 2832 | GETVAL(dflt_str, sub, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2833 | } else if (!strcmp(sub->name, "mandatory")) { |
| 2834 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2835 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2836 | goto error; |
| 2837 | } |
| 2838 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2839 | * multiple mandatory statements with the "false" value |
| 2840 | */ |
| 2841 | f_mand = 1; |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2842 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2843 | GETVAL(value, sub, "value"); |
| 2844 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2845 | choice->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2846 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2847 | choice->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2848 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2849 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2850 | goto error; |
| 2851 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2852 | } else if (!strcmp(sub->name, "when")) { |
| 2853 | if (choice->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2854 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2855 | goto error; |
| 2856 | } |
| 2857 | |
| 2858 | choice->when = read_yin_when(module, sub); |
| 2859 | if (!choice->when) { |
| 2860 | goto error; |
| 2861 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 2862 | if (lyxp_syntax_check(choice->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2863 | goto error; |
| 2864 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2865 | } else if (!strcmp(sub->name, "if-feature")) { |
| 2866 | c_ftrs++; |
| 2867 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2868 | /* 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] | 2869 | continue; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2870 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2871 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2872 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2873 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2874 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 2875 | node = NULL; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2876 | lyxml_free(ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2877 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2878 | |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2879 | if (c_ftrs) { |
| 2880 | choice->features = calloc(c_ftrs, sizeof *choice->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2881 | if (!choice->features) { |
| 2882 | LOGMEM; |
| 2883 | goto error; |
| 2884 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2885 | } |
| 2886 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 2887 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2888 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 2889 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 2890 | goto error; |
| 2891 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 2892 | /* hack - store pointer to the parent node for later status check */ |
| 2893 | choice->features[choice->features_size] = (struct lys_feature *)choice; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 2894 | 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] | 2895 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 2896 | choice->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 2897 | lydict_remove(module->ctx, value); |
| 2898 | if (ret == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2899 | goto error; |
| 2900 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2901 | } |
| 2902 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2903 | /* check - default is prohibited in combination with mandatory */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2904 | if (dflt_str && (choice->flags & LYS_MAND_TRUE)) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2905 | LOGVAL(LYE_SPEC, LOGLINE(yin), |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2906 | "The \"default\" statement MUST NOT be present on choices where \"mandatory\" is true."); |
| 2907 | goto error; |
| 2908 | } |
Radek Krejci | b4cf202 | 2015-06-03 14:40:05 +0200 | [diff] [blame] | 2909 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2910 | /* link default with the case */ |
| 2911 | if (dflt_str) { |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 2912 | 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] | 2913 | goto error; |
| 2914 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2915 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2916 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2917 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2918 | |
| 2919 | error: |
| 2920 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 2921 | lys_node_free(retval, NULL); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2922 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2923 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 2924 | } |
| 2925 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 2926 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2927 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2928 | 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] | 2929 | struct unres_schema *unres) |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2930 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2931 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 2932 | struct lys_node_leaf *anyxml; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2933 | struct lyxml_elem *sub, *next; |
| 2934 | const char *value; |
| 2935 | int r; |
| 2936 | int f_mand = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 2937 | int c_must = 0, c_ftrs = 0; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2938 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2939 | anyxml = calloc(1, sizeof *anyxml); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 2940 | if (!anyxml) { |
| 2941 | LOGMEM; |
| 2942 | return NULL; |
| 2943 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 2944 | anyxml->nodetype = LYS_ANYXML; |
| 2945 | anyxml->prev = (struct lys_node *)anyxml; |
| 2946 | retval = (struct lys_node *)anyxml; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2947 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 2948 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 2949 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2950 | goto error; |
| 2951 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2952 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 2953 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 2954 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 2955 | 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] | 2956 | goto error; |
| 2957 | } |
| 2958 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2959 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2960 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 2961 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2962 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 2963 | continue; |
| 2964 | } |
| 2965 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2966 | if (!strcmp(sub->name, "mandatory")) { |
| 2967 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2968 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2969 | goto error; |
| 2970 | } |
| 2971 | /* just checking the flags in leaf is not sufficient, we would allow |
| 2972 | * multiple mandatory statements with the "false" value |
| 2973 | */ |
| 2974 | f_mand = 1; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 2975 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2976 | GETVAL(value, sub, "value"); |
| 2977 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2978 | anyxml->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2979 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 2980 | anyxml->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 2981 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2982 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 2983 | goto error; |
| 2984 | } |
| 2985 | /* else false is the default value, so we can ignore it */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2986 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2987 | } else if (!strcmp(sub->name, "when")) { |
| 2988 | if (anyxml->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 2989 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2990 | goto error; |
| 2991 | } |
| 2992 | |
| 2993 | anyxml->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2994 | if (!anyxml->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 2995 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 2996 | goto error; |
| 2997 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 2998 | if (lyxp_syntax_check(anyxml->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 2999 | goto error; |
| 3000 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3001 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3002 | } else if (!strcmp(sub->name, "must")) { |
| 3003 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3004 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3005 | c_ftrs++; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3006 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3007 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3008 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3009 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3010 | } |
| 3011 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3012 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3013 | /* middle part - process nodes with cardinality of 0..n */ |
| 3014 | if (c_must) { |
| 3015 | anyxml->must = calloc(c_must, sizeof *anyxml->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3016 | if (!anyxml->must) { |
| 3017 | LOGMEM; |
| 3018 | goto error; |
| 3019 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3020 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3021 | if (c_ftrs) { |
| 3022 | anyxml->features = calloc(c_ftrs, sizeof *anyxml->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3023 | if (!anyxml->features) { |
| 3024 | LOGMEM; |
| 3025 | goto error; |
| 3026 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3027 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3028 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3029 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3030 | if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3031 | r = fill_yin_must(module, sub, &anyxml->must[anyxml->must_size]); |
| 3032 | anyxml->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3033 | if (r) { |
| 3034 | goto error; |
| 3035 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 3036 | 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] | 3037 | goto error; |
| 3038 | } |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 3039 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3040 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 3041 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3042 | goto error; |
| 3043 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3044 | /* hack - store pointer to the parent node for later status check */ |
| 3045 | anyxml->features[anyxml->features_size] = (struct lys_feature *)anyxml; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3046 | 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] | 3047 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3048 | anyxml->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3049 | lydict_remove(module->ctx, value); |
| 3050 | if (r == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3051 | goto error; |
| 3052 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3053 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3054 | } |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3055 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3056 | return retval; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3057 | |
| 3058 | error: |
| 3059 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 3060 | lys_node_free(retval, NULL); |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3061 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3062 | return NULL; |
Radek Krejci | 863c285 | 2015-06-03 15:47:11 +0200 | [diff] [blame] | 3063 | } |
| 3064 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3065 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3066 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3067 | 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] | 3068 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3069 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3070 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3071 | struct lys_node_leaf *leaf; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3072 | struct lyxml_elem *sub, *next; |
| 3073 | const char *value; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3074 | int r, has_type = 0, dflt_line; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3075 | int c_must = 0, c_ftrs = 0, f_mand = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3076 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3077 | leaf = calloc(1, sizeof *leaf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3078 | if (!leaf) { |
| 3079 | LOGMEM; |
| 3080 | return NULL; |
| 3081 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3082 | leaf->nodetype = LYS_LEAF; |
| 3083 | leaf->prev = (struct lys_node *)leaf; |
| 3084 | retval = (struct lys_node *)leaf; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3085 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3086 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3087 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3088 | goto error; |
| 3089 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3090 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3091 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3092 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 3093 | 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] | 3094 | goto error; |
| 3095 | } |
| 3096 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3097 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3098 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3099 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3100 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3101 | continue; |
| 3102 | } |
| 3103 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3104 | if (!strcmp(sub->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 3105 | if (has_type) { |
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 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3109 | /* HACK for unres */ |
| 3110 | leaf->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3111 | leaf->type.parent = (struct lys_tpdf *)leaf; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3112 | if (unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DER, parent, LOGLINE(sub))) { |
| 3113 | leaf->type.der = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3114 | goto error; |
| 3115 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3116 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3117 | } else if (!strcmp(sub->name, "default")) { |
| 3118 | if (leaf->dflt) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3119 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3120 | goto error; |
| 3121 | } |
| 3122 | GETVAL(value, sub, "value"); |
| 3123 | leaf->dflt = lydict_insert(module->ctx, value, strlen(value)); |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3124 | dflt_line = LOGLINE(sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3125 | } else if (!strcmp(sub->name, "units")) { |
| 3126 | if (leaf->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3127 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3128 | goto error; |
| 3129 | } |
| 3130 | GETVAL(value, sub, "name"); |
| 3131 | leaf->units = lydict_insert(module->ctx, value, strlen(value)); |
| 3132 | } else if (!strcmp(sub->name, "mandatory")) { |
| 3133 | if (f_mand) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3134 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3135 | goto error; |
| 3136 | } |
| 3137 | /* just checking the flags in leaf is not sufficient, we would allow |
| 3138 | * multiple mandatory statements with the "false" value |
| 3139 | */ |
| 3140 | f_mand = 1; |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3141 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3142 | GETVAL(value, sub, "value"); |
| 3143 | if (!strcmp(value, "true")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3144 | leaf->flags |= LYS_MAND_TRUE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3145 | } else if (!strcmp(value, "false")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3146 | leaf->flags |= LYS_MAND_FALSE; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3147 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3148 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3149 | goto error; |
| 3150 | } /* else false is the default value, so we can ignore it */ |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3151 | } else if (!strcmp(sub->name, "when")) { |
| 3152 | if (leaf->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3153 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3154 | goto error; |
| 3155 | } |
| 3156 | |
| 3157 | leaf->when = read_yin_when(module, sub); |
| 3158 | if (!leaf->when) { |
| 3159 | goto error; |
| 3160 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 3161 | if (lyxp_syntax_check(leaf->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3162 | goto error; |
| 3163 | } |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3164 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3165 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3166 | c_must++; |
| 3167 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3168 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3169 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3170 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3171 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3172 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3173 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3174 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3175 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3176 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3177 | /* 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] | 3178 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3179 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3180 | /* check mandatory parameters */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3181 | if (!has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3182 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3183 | goto error; |
| 3184 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3185 | if (leaf->dflt) { |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3186 | 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] | 3187 | goto error; |
| 3188 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3189 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3190 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3191 | /* middle part - process nodes with cardinality of 0..n */ |
| 3192 | if (c_must) { |
| 3193 | leaf->must = calloc(c_must, sizeof *leaf->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3194 | if (!leaf->must) { |
| 3195 | LOGMEM; |
| 3196 | goto error; |
| 3197 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3198 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3199 | if (c_ftrs) { |
| 3200 | leaf->features = calloc(c_ftrs, sizeof *leaf->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3201 | if (!leaf->features) { |
| 3202 | LOGMEM; |
| 3203 | goto error; |
| 3204 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3205 | } |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3206 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3207 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3208 | if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3209 | r = fill_yin_must(module, sub, &leaf->must[leaf->must_size]); |
| 3210 | leaf->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3211 | if (r) { |
| 3212 | goto error; |
| 3213 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 3214 | 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] | 3215 | goto error; |
| 3216 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3217 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3218 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 3219 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3220 | goto error; |
| 3221 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3222 | /* hack - store pointer to the parent node for later status check */ |
| 3223 | leaf->features[leaf->features_size] = (struct lys_feature *)leaf; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3224 | 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] | 3225 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3226 | leaf->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3227 | lydict_remove(module->ctx, value); |
| 3228 | if (r == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3229 | goto error; |
| 3230 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3231 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3232 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3233 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3234 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3235 | |
| 3236 | error: |
| 3237 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 3238 | lys_node_free(retval, NULL); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3239 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3240 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3241 | } |
| 3242 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3243 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3244 | static struct lys_node * |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3245 | 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] | 3246 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3247 | { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3248 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3249 | struct lys_node_leaflist *llist; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3250 | struct lyxml_elem *sub, *next; |
| 3251 | const char *value; |
| 3252 | char *endptr; |
| 3253 | unsigned long val; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3254 | int r, has_type = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3255 | int c_must = 0, c_ftrs = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3256 | int f_ordr = 0, f_min = 0, f_max = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3257 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3258 | llist = calloc(1, sizeof *llist); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3259 | if (!llist) { |
| 3260 | LOGMEM; |
| 3261 | return NULL; |
| 3262 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3263 | llist->nodetype = LYS_LEAFLIST; |
| 3264 | llist->prev = (struct lys_node *)llist; |
| 3265 | retval = (struct lys_node *)llist; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3266 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3267 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3268 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3269 | goto error; |
| 3270 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3271 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3272 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
Radek Krejci | 10c760e | 2015-08-14 14:45:43 +0200 | [diff] [blame] | 3273 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 3274 | 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] | 3275 | goto error; |
| 3276 | } |
| 3277 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3278 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3279 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3280 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3281 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3282 | continue; |
| 3283 | } |
| 3284 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3285 | if (!strcmp(sub->name, "type")) { |
Radek Krejci | ad73b6f | 2016-02-09 15:42:55 +0100 | [diff] [blame] | 3286 | if (has_type) { |
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 | } |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3290 | /* HACK for unres */ |
| 3291 | llist->type.der = (struct lys_tpdf *)sub; |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3292 | llist->type.parent = (struct lys_tpdf *)llist; |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3293 | if (unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DER, parent, LOGLINE(sub))) { |
| 3294 | llist->type.der = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3295 | goto error; |
| 3296 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3297 | has_type = 1; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3298 | } else if (!strcmp(sub->name, "units")) { |
| 3299 | if (llist->units) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3300 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3301 | goto error; |
| 3302 | } |
| 3303 | GETVAL(value, sub, "name"); |
| 3304 | llist->units = lydict_insert(module->ctx, value, strlen(value)); |
| 3305 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 3306 | if (f_ordr) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3307 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3308 | goto error; |
| 3309 | } |
| 3310 | /* just checking the flags in llist is not sufficient, we would |
| 3311 | * allow multiple ordered-by statements with the "system" value |
| 3312 | */ |
| 3313 | f_ordr = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3314 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3315 | if (llist->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3316 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 3317 | * state data |
| 3318 | */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3319 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3320 | continue; |
| 3321 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3322 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3323 | GETVAL(value, sub, "value"); |
| 3324 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3325 | llist->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3326 | } else if (strcmp(value, "system")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3327 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3328 | goto error; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3329 | } /* else system is the default value, so we can ignore it */ |
| 3330 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3331 | } else if (!strcmp(sub->name, "must")) { |
| 3332 | c_must++; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3333 | continue; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3334 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3335 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3336 | continue; |
Radek Krejci | 41882de | 2015-07-02 16:34:58 +0200 | [diff] [blame] | 3337 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3338 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3339 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3340 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3341 | goto error; |
| 3342 | } |
| 3343 | f_min = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3344 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3345 | GETVAL(value, sub, "value"); |
| 3346 | while (isspace(value[0])) { |
| 3347 | value++; |
| 3348 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3349 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3350 | /* convert it to uint32_t */ |
| 3351 | errno = 0; |
| 3352 | endptr = NULL; |
| 3353 | val = strtoul(value, &endptr, 10); |
| 3354 | if (*endptr || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3355 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3356 | goto error; |
| 3357 | } |
| 3358 | llist->min = (uint32_t) val; |
| 3359 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3360 | if (f_max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3361 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3362 | goto error; |
| 3363 | } |
| 3364 | f_max = 1; |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3365 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3366 | GETVAL(value, sub, "value"); |
| 3367 | while (isspace(value[0])) { |
| 3368 | value++; |
| 3369 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3370 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3371 | /* convert it to uint32_t */ |
| 3372 | errno = 0; |
| 3373 | endptr = NULL; |
| 3374 | val = strtoul(value, &endptr, 10); |
| 3375 | if (*endptr || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3376 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3377 | goto error; |
| 3378 | } |
| 3379 | llist->max = (uint32_t) val; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3380 | } else if (!strcmp(sub->name, "when")) { |
| 3381 | if (llist->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3382 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3383 | goto error; |
| 3384 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3385 | |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3386 | llist->when = read_yin_when(module, sub); |
| 3387 | if (!llist->when) { |
| 3388 | goto error; |
| 3389 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 3390 | if (lyxp_syntax_check(llist->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3391 | goto error; |
| 3392 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3393 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3394 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3395 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3396 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3397 | |
Michal Vasko | 88c2954 | 2015-11-27 14:57:53 +0100 | [diff] [blame] | 3398 | /* 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] | 3399 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3400 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3401 | /* check constraints */ |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 3402 | if (!has_type) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3403 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "type", yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3404 | goto error; |
| 3405 | } |
| 3406 | if (llist->max && llist->min > llist->max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3407 | LOGVAL(LYE_SPEC, LOGLINE(yin), "\"min-elements\" is bigger than \"max-elements\"."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3408 | goto error; |
| 3409 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3410 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3411 | /* middle part - process nodes with cardinality of 0..n */ |
| 3412 | if (c_must) { |
| 3413 | llist->must = calloc(c_must, sizeof *llist->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3414 | if (!llist->must) { |
| 3415 | LOGMEM; |
| 3416 | goto error; |
| 3417 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3418 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3419 | if (c_ftrs) { |
| 3420 | llist->features = calloc(c_ftrs, sizeof *llist->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3421 | if (!llist->features) { |
| 3422 | LOGMEM; |
| 3423 | goto error; |
| 3424 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3425 | } |
Radek Krejci | 8b4f23c | 2015-06-02 16:09:25 +0200 | [diff] [blame] | 3426 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3427 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3428 | if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3429 | r = fill_yin_must(module, sub, &llist->must[llist->must_size]); |
| 3430 | llist->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3431 | if (r) { |
| 3432 | goto error; |
| 3433 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 3434 | 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] | 3435 | goto error; |
| 3436 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3437 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3438 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 3439 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3440 | goto error; |
| 3441 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3442 | /* hack - store pointer to the parent node for later status check */ |
| 3443 | llist->features[llist->features_size] = (struct lys_feature *)llist; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3444 | 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] | 3445 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3446 | llist->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3447 | lydict_remove(module->ctx, value); |
| 3448 | if (r == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3449 | goto error; |
| 3450 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3451 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3452 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3453 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3454 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3455 | |
| 3456 | error: |
| 3457 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 3458 | lys_node_free(retval, NULL); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3459 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3460 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3461 | } |
| 3462 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3463 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3464 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3465 | read_yin_list(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 3466 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3467 | { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3468 | struct lys_node *retval, *node; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3469 | struct lys_node_list *list; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3470 | struct lyxml_elem *sub, *next, root, uniq; |
Michal Vasko | e38af6e | 2015-08-03 14:39:27 +0200 | [diff] [blame] | 3471 | int r, key_line; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3472 | 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] | 3473 | int f_ordr = 0, f_max = 0, f_min = 0; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 3474 | const char *key_str = NULL, *value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3475 | char *auxs; |
| 3476 | unsigned long val; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3477 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3478 | /* init */ |
| 3479 | memset(&root, 0, sizeof root); |
| 3480 | memset(&uniq, 0, sizeof uniq); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3481 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3482 | list = calloc(1, sizeof *list); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3483 | if (!list) { |
| 3484 | LOGMEM; |
| 3485 | return NULL; |
| 3486 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3487 | list->nodetype = LYS_LIST; |
| 3488 | list->prev = (struct lys_node *)list; |
| 3489 | retval = (struct lys_node *)list; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3490 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3491 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3492 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3493 | goto error; |
| 3494 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3495 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3496 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3497 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3498 | /* process list's specific children */ |
| 3499 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3500 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 3501 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3502 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3503 | continue; |
| 3504 | } |
| 3505 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3506 | /* data statements */ |
| 3507 | if (!strcmp(sub->name, "container") || |
| 3508 | !strcmp(sub->name, "leaf-list") || |
| 3509 | !strcmp(sub->name, "leaf") || |
| 3510 | !strcmp(sub->name, "list") || |
| 3511 | !strcmp(sub->name, "choice") || |
| 3512 | !strcmp(sub->name, "uses") || |
| 3513 | !strcmp(sub->name, "grouping") || |
| 3514 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 3515 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3516 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3517 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3518 | /* array counters */ |
| 3519 | } else if (!strcmp(sub->name, "key")) { |
| 3520 | /* check cardinality 0..1 */ |
| 3521 | if (list->keys_size) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3522 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, list->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3523 | goto error; |
| 3524 | } |
Radek Krejci | d7f0d01 | 2015-05-25 15:04:52 +0200 | [diff] [blame] | 3525 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3526 | /* count the number of keys */ |
| 3527 | GETVAL(value, sub, "value"); |
| 3528 | key_str = value; |
Michal Vasko | e38af6e | 2015-08-03 14:39:27 +0200 | [diff] [blame] | 3529 | key_line = LOGLINE(sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3530 | while ((value = strpbrk(value, " \t\n"))) { |
| 3531 | list->keys_size++; |
| 3532 | while (isspace(*value)) { |
| 3533 | value++; |
| 3534 | } |
| 3535 | } |
| 3536 | list->keys_size++; |
| 3537 | list->keys = calloc(list->keys_size, sizeof *list->keys); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3538 | if (!list->keys) { |
| 3539 | LOGMEM; |
| 3540 | goto error; |
| 3541 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3542 | } else if (!strcmp(sub->name, "unique")) { |
| 3543 | c_uniq++; |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 3544 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3545 | lyxml_add_child(module->ctx, &uniq, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3546 | } else if (!strcmp(sub->name, "typedef")) { |
| 3547 | c_tpdf++; |
| 3548 | } else if (!strcmp(sub->name, "must")) { |
| 3549 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3550 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3551 | c_ftrs++; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3552 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3553 | /* optional stetments */ |
| 3554 | } else if (!strcmp(sub->name, "ordered-by")) { |
| 3555 | if (f_ordr) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3556 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3557 | goto error; |
| 3558 | } |
| 3559 | /* just checking the flags in llist is not sufficient, we would |
| 3560 | * allow multiple ordered-by statements with the "system" value |
| 3561 | */ |
| 3562 | f_ordr = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3563 | |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3564 | if (list->flags & LYS_CONFIG_R) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3565 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents |
| 3566 | * state data |
| 3567 | */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3568 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3569 | continue; |
| 3570 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3571 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3572 | GETVAL(value, sub, "value"); |
| 3573 | if (!strcmp(value, "user")) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3574 | list->flags |= LYS_USERORDERED; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3575 | } else if (strcmp(value, "system")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3576 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3577 | goto error; |
| 3578 | } |
| 3579 | /* else system is the default value, so we can ignore it */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3580 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3581 | } else if (!strcmp(sub->name, "min-elements")) { |
| 3582 | if (f_min) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3583 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3584 | goto error; |
| 3585 | } |
| 3586 | f_min = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3587 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3588 | GETVAL(value, sub, "value"); |
| 3589 | while (isspace(value[0])) { |
| 3590 | value++; |
| 3591 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3592 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3593 | /* convert it to uint32_t */ |
| 3594 | errno = 0; |
| 3595 | auxs = NULL; |
| 3596 | val = strtoul(value, &auxs, 10); |
| 3597 | if (*auxs || value[0] == '-' || errno || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3598 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3599 | goto error; |
| 3600 | } |
| 3601 | list->min = (uint32_t) val; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3602 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3603 | } else if (!strcmp(sub->name, "max-elements")) { |
| 3604 | if (f_max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3605 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3606 | goto error; |
| 3607 | } |
| 3608 | f_max = 1; |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3609 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3610 | GETVAL(value, sub, "value"); |
| 3611 | while (isspace(value[0])) { |
| 3612 | value++; |
| 3613 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3614 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3615 | /* convert it to uint32_t */ |
| 3616 | errno = 0; |
| 3617 | auxs = NULL; |
| 3618 | val = strtoul(value, &auxs, 10); |
| 3619 | if (*auxs || value[0] == '-' || errno || val == 0 || val > UINT32_MAX) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3620 | LOGVAL(LYE_INARG, LOGLINE(sub), value, sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3621 | goto error; |
| 3622 | } |
| 3623 | list->max = (uint32_t) val; |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3624 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3625 | } else if (!strcmp(sub->name, "when")) { |
| 3626 | if (list->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3627 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3628 | goto error; |
| 3629 | } |
| 3630 | |
| 3631 | list->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3632 | if (!list->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3633 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3634 | goto error; |
| 3635 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 3636 | if (lyxp_syntax_check(list->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3637 | goto error; |
| 3638 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3639 | lyxml_free(module->ctx, sub); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3640 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3641 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3642 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3643 | } |
| 3644 | } |
Radek Krejci | 345ad74 | 2015-06-03 11:04:18 +0200 | [diff] [blame] | 3645 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3646 | /* check - if list is configuration, key statement is mandatory */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 3647 | if ((list->flags & LYS_CONFIG_W) && !key_str) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3648 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "key", "list"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3649 | goto error; |
| 3650 | } |
| 3651 | if (list->max && list->min > list->max) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3652 | LOGVAL(LYE_SPEC, LOGLINE(yin), "\"min-elements\" is bigger than \"max-elements\"."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3653 | goto error; |
| 3654 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3655 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3656 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3657 | if (c_tpdf) { |
| 3658 | list->tpdf = calloc(c_tpdf, sizeof *list->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3659 | if (!list->tpdf) { |
| 3660 | LOGMEM; |
| 3661 | goto error; |
| 3662 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3663 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3664 | if (c_must) { |
| 3665 | list->must = calloc(c_must, sizeof *list->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3666 | if (!list->must) { |
| 3667 | LOGMEM; |
| 3668 | goto error; |
| 3669 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3670 | } |
| 3671 | if (c_ftrs) { |
| 3672 | list->features = calloc(c_ftrs, sizeof *list->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3673 | if (!list->features) { |
| 3674 | LOGMEM; |
| 3675 | goto error; |
| 3676 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3677 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3678 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3679 | if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3680 | r = fill_yin_typedef(module, retval, sub, &list->tpdf[list->tpdf_size], unres); |
| 3681 | list->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3682 | if (r) { |
| 3683 | goto error; |
| 3684 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3685 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3686 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 3687 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3688 | goto error; |
| 3689 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3690 | /* hack - store pointer to the parent node for later status check */ |
| 3691 | list->features[list->features_size] = (struct lys_feature *)list; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3692 | 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] | 3693 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3694 | list->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3695 | lydict_remove(module->ctx, value); |
| 3696 | if (r == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3697 | goto error; |
| 3698 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3699 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3700 | r = fill_yin_must(module, sub, &list->must[list->must_size]); |
| 3701 | list->must_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3702 | if (r) { |
| 3703 | goto error; |
| 3704 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 3705 | 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] | 3706 | goto error; |
| 3707 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3708 | } |
| 3709 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 3710 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 3711 | 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] | 3712 | goto error; |
| 3713 | } |
| 3714 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3715 | /* last part - process data nodes */ |
| 3716 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3717 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3718 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3719 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3720 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3721 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3722 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3723 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3724 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3725 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3726 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3727 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3728 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3729 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3730 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3731 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3732 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Michal Vasko | c07187d | 2015-08-13 15:20:57 +0200 | [diff] [blame] | 3733 | } else { |
| 3734 | LOGINT; |
| 3735 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3736 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3737 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3738 | goto error; |
| 3739 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3740 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3741 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3742 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3743 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3744 | if (!key_str) { |
| 3745 | /* config false list without a key */ |
| 3746 | return retval; |
| 3747 | } |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 3748 | 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] | 3749 | goto error; |
| 3750 | } |
Radek Krejci | 812b10a | 2015-05-28 16:48:25 +0200 | [diff] [blame] | 3751 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3752 | /* process unique statements */ |
| 3753 | if (c_uniq) { |
| 3754 | list->unique = calloc(c_uniq, sizeof *list->unique); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3755 | if (!list->unique) { |
| 3756 | LOGMEM; |
| 3757 | goto error; |
| 3758 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3759 | } |
| 3760 | LY_TREE_FOR_SAFE(uniq.child, next, sub) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3761 | r = fill_yin_unique(module, retval, sub, &list->unique[list->unique_size], unres); |
| 3762 | list->unique_size++; |
| 3763 | if (r) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3764 | goto error; |
| 3765 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 3766 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3767 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3768 | } |
Radek Krejci | 1e9b999 | 2015-06-04 17:57:04 +0200 | [diff] [blame] | 3769 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3770 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3771 | |
| 3772 | error: |
| 3773 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 3774 | lys_node_free(retval, NULL); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3775 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3776 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3777 | } |
| 3778 | while (uniq.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3779 | lyxml_free(module->ctx, uniq.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3780 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3781 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3782 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3783 | } |
| 3784 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3785 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3786 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 3787 | read_yin_container(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 3788 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3789 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3790 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3791 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3792 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3793 | struct lys_node_container *cont; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3794 | const char *value; |
| 3795 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3796 | int c_tpdf = 0, c_must = 0, c_ftrs = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3797 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3798 | /* init */ |
| 3799 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3800 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3801 | cont = calloc(1, sizeof *cont); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3802 | if (!cont) { |
| 3803 | LOGMEM; |
| 3804 | return NULL; |
| 3805 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3806 | cont->nodetype = LYS_CONTAINER; |
| 3807 | cont->prev = (struct lys_node *)cont; |
| 3808 | retval = (struct lys_node *)cont; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3809 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 3810 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE | OPT_CONFIG |
| 3811 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3812 | goto error; |
| 3813 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3814 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 3815 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 3816 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3817 | /* process container's specific children */ |
| 3818 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 3819 | if (!sub->ns) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3820 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3821 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 3822 | continue; |
| 3823 | } |
| 3824 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3825 | if (!strcmp(sub->name, "presence")) { |
| 3826 | if (cont->presence) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3827 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3828 | goto error; |
| 3829 | } |
| 3830 | GETVAL(value, sub, "value"); |
| 3831 | cont->presence = lydict_insert(module->ctx, value, strlen(value)); |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 3832 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3833 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3834 | } else if (!strcmp(sub->name, "when")) { |
| 3835 | if (cont->when) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3836 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3837 | goto error; |
| 3838 | } |
| 3839 | |
| 3840 | cont->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3841 | if (!cont->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3842 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 3843 | goto error; |
| 3844 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 3845 | if (lyxp_syntax_check(cont->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3846 | goto error; |
| 3847 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3848 | lyxml_free(module->ctx, sub); |
Radek Krejci | 4c31f12 | 2015-06-02 14:51:22 +0200 | [diff] [blame] | 3849 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3850 | /* data statements */ |
| 3851 | } else if (!strcmp(sub->name, "container") || |
| 3852 | !strcmp(sub->name, "leaf-list") || |
| 3853 | !strcmp(sub->name, "leaf") || |
| 3854 | !strcmp(sub->name, "list") || |
| 3855 | !strcmp(sub->name, "choice") || |
| 3856 | !strcmp(sub->name, "uses") || |
| 3857 | !strcmp(sub->name, "grouping") || |
| 3858 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 3859 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 3860 | lyxml_add_child(module->ctx, &root, sub); |
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 | /* array counters */ |
| 3863 | } else if (!strcmp(sub->name, "typedef")) { |
| 3864 | c_tpdf++; |
| 3865 | } else if (!strcmp(sub->name, "must")) { |
| 3866 | c_must++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3867 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3868 | c_ftrs++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3869 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 3870 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3871 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3872 | } |
| 3873 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3874 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3875 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 3876 | if (c_tpdf) { |
| 3877 | cont->tpdf = calloc(c_tpdf, sizeof *cont->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3878 | if (!cont->tpdf) { |
| 3879 | LOGMEM; |
| 3880 | goto error; |
| 3881 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3882 | } |
| 3883 | if (c_must) { |
| 3884 | cont->must = calloc(c_must, sizeof *cont->must); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3885 | if (!cont->must) { |
| 3886 | LOGMEM; |
| 3887 | goto error; |
| 3888 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3889 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3890 | if (c_ftrs) { |
| 3891 | cont->features = calloc(c_ftrs, sizeof *cont->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3892 | if (!cont->features) { |
| 3893 | LOGMEM; |
| 3894 | goto error; |
| 3895 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3896 | } |
Radek Krejci | 800af70 | 2015-06-02 13:46:01 +0200 | [diff] [blame] | 3897 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3898 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3899 | if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3900 | r = fill_yin_typedef(module, retval, sub, &cont->tpdf[cont->tpdf_size], unres); |
| 3901 | cont->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3902 | if (r) { |
| 3903 | goto error; |
| 3904 | } |
| 3905 | } else if (!strcmp(sub->name, "must")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3906 | r = fill_yin_must(module, sub, &cont->must[cont->must_size]); |
| 3907 | cont->must_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3908 | if (r) { |
| 3909 | goto error; |
| 3910 | } |
Michal Vasko | 0d20459 | 2015-10-07 09:50:04 +0200 | [diff] [blame] | 3911 | 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] | 3912 | goto error; |
| 3913 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 3914 | } else if (!strcmp(sub->name, "if-feature")) { |
| 3915 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 3916 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3917 | goto error; |
| 3918 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 3919 | /* hack - store pointer to the parent node for later status check */ |
| 3920 | cont->features[cont->features_size] = (struct lys_feature *)cont; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3921 | 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] | 3922 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 3923 | cont->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 3924 | lydict_remove(module->ctx, value); |
| 3925 | if (r == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 3926 | goto error; |
| 3927 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3928 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3929 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3930 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 3931 | 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] | 3932 | goto error; |
| 3933 | } |
| 3934 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3935 | /* last part - process data nodes */ |
| 3936 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 3937 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3938 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3939 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3940 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3941 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3942 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3943 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3944 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3945 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3946 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3947 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3948 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3949 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3950 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3951 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3952 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3953 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3954 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3955 | goto error; |
| 3956 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 3957 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3958 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3959 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3960 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3961 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3962 | |
| 3963 | error: |
| 3964 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 3965 | lys_node_free(retval, NULL); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3966 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 3967 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3968 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3969 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3970 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3971 | } |
| 3972 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 3973 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3974 | static struct lys_node * |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3975 | 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] | 3976 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3977 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3978 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 3979 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3980 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 3981 | struct lys_node_grp *grp; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3982 | int r; |
| 3983 | int c_tpdf = 0; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3984 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3985 | /* init */ |
| 3986 | memset(&root, 0, sizeof root); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 3987 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3988 | grp = calloc(1, sizeof *grp); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 3989 | if (!grp) { |
| 3990 | LOGMEM; |
| 3991 | return NULL; |
| 3992 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 3993 | grp->nodetype = LYS_GROUPING; |
| 3994 | grp->prev = (struct lys_node *)grp; |
| 3995 | retval = (struct lys_node *)grp; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 3996 | |
Michal Vasko | 71e1aa8 | 2015-08-12 12:17:51 +0200 | [diff] [blame] | 3997 | if (read_yin_common(module, parent, retval, yin, OPT_IDENT | OPT_MODULE)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 3998 | goto error; |
| 3999 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4000 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4001 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4002 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4003 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4004 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4005 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4006 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4007 | continue; |
| 4008 | } |
| 4009 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4010 | /* data statements */ |
| 4011 | if (!strcmp(sub->name, "container") || |
| 4012 | !strcmp(sub->name, "leaf-list") || |
| 4013 | !strcmp(sub->name, "leaf") || |
| 4014 | !strcmp(sub->name, "list") || |
| 4015 | !strcmp(sub->name, "choice") || |
| 4016 | !strcmp(sub->name, "uses") || |
| 4017 | !strcmp(sub->name, "grouping") || |
| 4018 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4019 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4020 | lyxml_add_child(module->ctx, &root, sub); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4021 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4022 | /* array counters */ |
| 4023 | } else if (!strcmp(sub->name, "typedef")) { |
| 4024 | c_tpdf++; |
| 4025 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4026 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4027 | goto error; |
| 4028 | } |
| 4029 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4030 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4031 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4032 | if (c_tpdf) { |
| 4033 | grp->tpdf = calloc(c_tpdf, sizeof *grp->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4034 | if (!grp->tpdf) { |
| 4035 | LOGMEM; |
| 4036 | goto error; |
| 4037 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4038 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4039 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4040 | r = fill_yin_typedef(module, retval, sub, &grp->tpdf[grp->tpdf_size], unres); |
| 4041 | grp->tpdf_size++; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4042 | if (r) { |
| 4043 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4044 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4045 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4046 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4047 | 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] | 4048 | goto error; |
| 4049 | } |
| 4050 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4051 | /* last part - process data nodes */ |
| 4052 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4053 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4054 | node = read_yin_container(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4055 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4056 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4057 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4058 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4059 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4060 | node = read_yin_list(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4061 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4062 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4063 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4064 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4065 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4066 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4067 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4068 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4069 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4070 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4071 | goto error; |
| 4072 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4073 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4074 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4075 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4076 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4077 | return retval; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4078 | |
| 4079 | error: |
| 4080 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 4081 | lys_node_free(retval, NULL); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4082 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4083 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4084 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4085 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4086 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4087 | } |
| 4088 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4089 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4090 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4091 | read_yin_input_output(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 4092 | struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4093 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4094 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4095 | struct lys_node *node = NULL; |
Radek Krejci | 31fc30d | 2015-08-13 08:27:38 +0200 | [diff] [blame] | 4096 | struct lys_node *retval = NULL; |
Radek Krejci | 4608ada | 2015-08-05 16:04:37 +0200 | [diff] [blame] | 4097 | struct lys_node_rpc_inout *inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4098 | int r; |
| 4099 | int c_tpdf = 0; |
| 4100 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4101 | /* init */ |
| 4102 | memset(&root, 0, sizeof root); |
| 4103 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4104 | inout = calloc(1, sizeof *inout); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4105 | if (!inout) { |
| 4106 | LOGMEM; |
| 4107 | return NULL; |
| 4108 | } |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 4109 | inout->prev = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4110 | |
| 4111 | if (!strcmp(yin->name, "input")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4112 | inout->nodetype = LYS_INPUT; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4113 | } else if (!strcmp(yin->name, "output")) { |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4114 | inout->nodetype = LYS_OUTPUT; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4115 | } else { |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 4116 | LOGINT; |
Radek Krejci | 6acc801 | 2015-08-13 09:07:04 +0200 | [diff] [blame] | 4117 | free(inout); |
Michal Vasko | 0c888fd | 2015-08-11 15:54:08 +0200 | [diff] [blame] | 4118 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4119 | } |
| 4120 | |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4121 | retval = (struct lys_node *)inout; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4122 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4123 | if (read_yin_common(module, parent, retval, yin, OPT_MODULE | OPT_NACMEXT)) { |
Michal Vasko | ebeac94 | 2015-06-15 12:11:50 +0200 | [diff] [blame] | 4124 | goto error; |
| 4125 | } |
| 4126 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4127 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4128 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4129 | /* data statements */ |
| 4130 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4131 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4132 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4133 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4134 | continue; |
| 4135 | } |
| 4136 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4137 | if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4138 | !strcmp(sub->name, "leaf-list") || |
| 4139 | !strcmp(sub->name, "leaf") || |
| 4140 | !strcmp(sub->name, "list") || |
| 4141 | !strcmp(sub->name, "choice") || |
| 4142 | !strcmp(sub->name, "uses") || |
| 4143 | !strcmp(sub->name, "grouping") || |
| 4144 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4145 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4146 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4147 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4148 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4149 | } else if (!strcmp(sub->name, "typedef")) { |
| 4150 | c_tpdf++; |
Radek Krejci | d2bfa79 | 2015-07-02 16:45:29 +0200 | [diff] [blame] | 4151 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4152 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4153 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4154 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4155 | } |
| 4156 | } |
| 4157 | |
| 4158 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4159 | if (c_tpdf) { |
| 4160 | inout->tpdf = calloc(c_tpdf, sizeof *inout->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4161 | if (!inout->tpdf) { |
| 4162 | LOGMEM; |
| 4163 | goto error; |
| 4164 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4165 | } |
| 4166 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4167 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4168 | r = fill_yin_typedef(module, retval, sub, &inout->tpdf[inout->tpdf_size], unres); |
| 4169 | inout->tpdf_size++; |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4170 | if (r) { |
| 4171 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4172 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4173 | } |
| 4174 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4175 | 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] | 4176 | goto error; |
| 4177 | } |
| 4178 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4179 | /* last part - process data nodes */ |
| 4180 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4181 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4182 | node = read_yin_container(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4183 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4184 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4185 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4186 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4187 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4188 | node = read_yin_list(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4189 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4190 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4191 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4192 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4193 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4194 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4195 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4196 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4197 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4198 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4199 | goto error; |
| 4200 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4201 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4202 | lyxml_free(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4203 | } |
| 4204 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4205 | return retval; |
| 4206 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4207 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4208 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 4209 | lys_node_free(retval, NULL); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 4210 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4211 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4212 | } |
| 4213 | |
| 4214 | return NULL; |
| 4215 | } |
| 4216 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4217 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4218 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4219 | read_yin_notif(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 4220 | struct unres_schema *unres) |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4221 | { |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 4222 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4223 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4224 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4225 | struct lys_node_notif *notif; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4226 | const char *value; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4227 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4228 | int c_tpdf = 0, c_ftrs = 0; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4229 | |
Michal Vasko | c6551b3 | 2015-06-16 10:51:43 +0200 | [diff] [blame] | 4230 | memset(&root, 0, sizeof root); |
| 4231 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4232 | notif = calloc(1, sizeof *notif); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4233 | if (!notif) { |
| 4234 | LOGMEM; |
| 4235 | return NULL; |
| 4236 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4237 | notif->nodetype = LYS_NOTIF; |
| 4238 | notif->prev = (struct lys_node *)notif; |
| 4239 | retval = (struct lys_node *)notif; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4240 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4241 | 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] | 4242 | goto error; |
| 4243 | } |
| 4244 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4245 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4246 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4247 | /* process rpc's specific children */ |
| 4248 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4249 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4250 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4251 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4252 | continue; |
| 4253 | } |
| 4254 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4255 | /* data statements */ |
| 4256 | if (!strcmp(sub->name, "container") || |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4257 | !strcmp(sub->name, "leaf-list") || |
| 4258 | !strcmp(sub->name, "leaf") || |
| 4259 | !strcmp(sub->name, "list") || |
| 4260 | !strcmp(sub->name, "choice") || |
| 4261 | !strcmp(sub->name, "uses") || |
| 4262 | !strcmp(sub->name, "grouping") || |
| 4263 | !strcmp(sub->name, "anyxml")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4264 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4265 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4266 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4267 | /* array counters */ |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4268 | } else if (!strcmp(sub->name, "typedef")) { |
| 4269 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4270 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4271 | c_ftrs++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4272 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4273 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4274 | goto error; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4275 | } |
| 4276 | } |
| 4277 | |
| 4278 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4279 | if (c_tpdf) { |
| 4280 | notif->tpdf = calloc(c_tpdf, sizeof *notif->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4281 | if (!notif->tpdf) { |
| 4282 | LOGMEM; |
| 4283 | goto error; |
| 4284 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4285 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4286 | if (c_ftrs) { |
| 4287 | notif->features = calloc(c_ftrs, sizeof *notif->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4288 | if (!notif->features) { |
| 4289 | LOGMEM; |
| 4290 | goto error; |
| 4291 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4292 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4293 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4294 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4295 | if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4296 | r = fill_yin_typedef(module, retval, sub, ¬if->tpdf[notif->tpdf_size], unres); |
| 4297 | notif->tpdf_size++; |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4298 | if (r) { |
| 4299 | goto error; |
| 4300 | } |
Radek Krejci | 0b24d75 | 2015-07-02 15:02:27 +0200 | [diff] [blame] | 4301 | } else if (!strcmp(sub->name, "if-features")) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4302 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 4303 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 4304 | goto error; |
| 4305 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 4306 | /* hack - store pointer to the parent node for later status check */ |
| 4307 | notif->features[notif->features_size] = (struct lys_feature *)notif; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4308 | 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] | 4309 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4310 | notif->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 4311 | lydict_remove(module->ctx, value); |
| 4312 | if (r == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4313 | goto error; |
| 4314 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4315 | } |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4316 | } |
| 4317 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4318 | 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] | 4319 | goto error; |
| 4320 | } |
| 4321 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4322 | /* last part - process data nodes */ |
| 4323 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4324 | if (!strcmp(sub->name, "container")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4325 | node = read_yin_container(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4326 | } else if (!strcmp(sub->name, "leaf-list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4327 | node = read_yin_leaflist(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4328 | } else if (!strcmp(sub->name, "leaf")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4329 | node = read_yin_leaf(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4330 | } else if (!strcmp(sub->name, "list")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4331 | node = read_yin_list(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4332 | } else if (!strcmp(sub->name, "choice")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4333 | node = read_yin_choice(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4334 | } else if (!strcmp(sub->name, "uses")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4335 | node = read_yin_uses(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4336 | } else if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4337 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4338 | } else if (!strcmp(sub->name, "anyxml")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4339 | node = read_yin_anyxml(module, retval, sub, resolve, unres); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4340 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4341 | if (!node) { |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4342 | goto error; |
| 4343 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4344 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4345 | lyxml_free(module->ctx, sub); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4346 | } |
| 4347 | |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4348 | return retval; |
| 4349 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4350 | error: |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4351 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 4352 | lys_node_free(retval, NULL); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4353 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4354 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 0ea4103 | 2015-06-16 08:53:55 +0200 | [diff] [blame] | 4355 | } |
| 4356 | |
| 4357 | return NULL; |
| 4358 | } |
| 4359 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4360 | /* logs directly */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4361 | static struct lys_node * |
Michal Vasko | f02e374 | 2015-08-05 16:27:02 +0200 | [diff] [blame] | 4362 | read_yin_rpc(struct lys_module *module, struct lys_node *parent, struct lyxml_elem *yin, int resolve, |
| 4363 | struct unres_schema *unres) |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4364 | { |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4365 | struct lyxml_elem *sub, *next, root; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4366 | struct lys_node *node = NULL; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4367 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4368 | struct lys_node_rpc *rpc; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4369 | const char *value; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4370 | int r; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4371 | int c_tpdf = 0, c_ftrs = 0; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4372 | |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4373 | /* init */ |
| 4374 | memset(&root, 0, sizeof root); |
| 4375 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4376 | rpc = calloc(1, sizeof *rpc); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4377 | if (!rpc) { |
| 4378 | LOGMEM; |
| 4379 | return NULL; |
| 4380 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4381 | rpc->nodetype = LYS_RPC; |
| 4382 | rpc->prev = (struct lys_node *)rpc; |
| 4383 | retval = (struct lys_node *)rpc; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4384 | |
Radek Krejci | 6a11385 | 2015-07-03 16:04:20 +0200 | [diff] [blame] | 4385 | 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] | 4386 | goto error; |
| 4387 | } |
| 4388 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4389 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4390 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4391 | /* process rpc's specific children */ |
| 4392 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4393 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4394 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4395 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4396 | continue; |
| 4397 | } |
| 4398 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4399 | if (!strcmp(sub->name, "input")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4400 | if (rpc->child |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4401 | && (rpc->child->nodetype == LYS_INPUT |
| 4402 | || (rpc->child->next && rpc->child->next->nodetype == LYS_INPUT))) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4403 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4404 | goto error; |
| 4405 | } |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4406 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4407 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4408 | } else if (!strcmp(sub->name, "output")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4409 | if (rpc->child |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4410 | && (rpc->child->nodetype == LYS_INPUT |
| 4411 | || (rpc->child->next && rpc->child->next->nodetype == LYS_INPUT))) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4412 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4413 | goto error; |
| 4414 | } |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4415 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4416 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4417 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4418 | /* data statements */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4419 | } else if (!strcmp(sub->name, "grouping")) { |
Michal Vasko | f3930de | 2015-10-22 12:03:59 +0200 | [diff] [blame] | 4420 | lyxml_unlink_elem(module->ctx, sub, 2); |
Michal Vasko | f8879c2 | 2015-08-21 09:07:36 +0200 | [diff] [blame] | 4421 | lyxml_add_child(module->ctx, &root, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4422 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4423 | /* array counters */ |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4424 | } else if (!strcmp(sub->name, "typedef")) { |
| 4425 | c_tpdf++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4426 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4427 | c_ftrs++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4428 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4429 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4430 | goto error; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4431 | } |
| 4432 | } |
| 4433 | |
| 4434 | /* middle part - process nodes with cardinality of 0..n except the data nodes */ |
| 4435 | if (c_tpdf) { |
| 4436 | rpc->tpdf = calloc(c_tpdf, sizeof *rpc->tpdf); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4437 | if (!rpc->tpdf) { |
| 4438 | LOGMEM; |
| 4439 | goto error; |
| 4440 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4441 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4442 | if (c_ftrs) { |
| 4443 | rpc->features = calloc(c_ftrs, sizeof *rpc->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4444 | if (!rpc->features) { |
| 4445 | LOGMEM; |
| 4446 | goto error; |
| 4447 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4448 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4449 | |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4450 | LY_TREE_FOR(yin->child, sub) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4451 | if (!strcmp(sub->name, "typedef")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4452 | r = fill_yin_typedef(module, retval, sub, &rpc->tpdf[rpc->tpdf_size], unres); |
| 4453 | rpc->tpdf_size++; |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4454 | if (r) { |
| 4455 | goto error; |
| 4456 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4457 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4458 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 4459 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 4460 | goto error; |
| 4461 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 4462 | /* hack - store pointer to the parent node for later status check */ |
| 4463 | rpc->features[rpc->features_size] = (struct lys_feature *)rpc; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4464 | 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] | 4465 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4466 | rpc->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 4467 | lydict_remove(module->ctx, value); |
| 4468 | if (r == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4469 | goto error; |
| 4470 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4471 | } |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4472 | } |
| 4473 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4474 | 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] | 4475 | goto error; |
| 4476 | } |
| 4477 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4478 | /* last part - process data nodes */ |
| 4479 | LY_TREE_FOR_SAFE(root.child, next, sub) { |
| 4480 | if (!strcmp(sub->name, "grouping")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4481 | node = read_yin_grouping(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4482 | } else if (!strcmp(sub->name, "input")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4483 | node = read_yin_input_output(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4484 | } else if (!strcmp(sub->name, "output")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4485 | node = read_yin_input_output(module, retval, sub, resolve, unres); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4486 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4487 | if (!node) { |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4488 | goto error; |
| 4489 | } |
Radek Krejci | 73adb60 | 2015-07-02 18:07:40 +0200 | [diff] [blame] | 4490 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4491 | lyxml_free(module->ctx, sub); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4492 | } |
| 4493 | |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4494 | return retval; |
| 4495 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4496 | error: |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4497 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 4498 | lys_node_free(retval, NULL); |
Michal Vasko | 3a9abf8 | 2015-06-17 10:18:26 +0200 | [diff] [blame] | 4499 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4500 | lyxml_free(module->ctx, root.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4501 | } |
| 4502 | |
| 4503 | return NULL; |
| 4504 | } |
| 4505 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4506 | /* logs directly |
| 4507 | * |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4508 | * resolve - referenced grouping should be bounded to the namespace (resolved) |
| 4509 | * only when uses does not appear in grouping. In a case of grouping's uses, |
| 4510 | * we just get information but we do not apply augment or refine to it. |
| 4511 | */ |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4512 | static struct lys_node * |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4513 | 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] | 4514 | struct unres_schema *unres) |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4515 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4516 | struct lyxml_elem *sub, *next; |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4517 | struct lys_node *retval; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 4518 | struct lys_node_uses *uses; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4519 | const char *value; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4520 | int c_ref = 0, c_aug = 0, c_ftrs = 0; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4521 | int r; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4522 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4523 | uses = calloc(1, sizeof *uses); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4524 | if (!uses) { |
| 4525 | LOGMEM; |
| 4526 | return NULL; |
| 4527 | } |
Radek Krejci | 7651257 | 2015-08-04 09:47:08 +0200 | [diff] [blame] | 4528 | uses->nodetype = LYS_USES; |
| 4529 | uses->prev = (struct lys_node *)uses; |
| 4530 | retval = (struct lys_node *)uses; |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4531 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4532 | GETVAL(value, yin, "name"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4533 | uses->name = lydict_insert(module->ctx, value, 0); |
Radek Krejci | 106efc0 | 2015-06-10 14:36:27 +0200 | [diff] [blame] | 4534 | |
Michal Vasko | e0c5984 | 2015-09-24 13:52:20 +0200 | [diff] [blame] | 4535 | if (read_yin_common(module, parent, retval, yin, OPT_MODULE |
| 4536 | | (parent && (parent->nodetype == LYS_GROUPING) ? 0 : OPT_NACMEXT) | (resolve ? OPT_INHERIT : 0))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4537 | goto error; |
| 4538 | } |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4539 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4540 | LOGDBG("YIN: parsing %s statement \"%s\"", yin->name, retval->name); |
| 4541 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4542 | /* get other properties of uses */ |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4543 | LY_TREE_FOR_SAFE(yin->child, next, sub) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4544 | if (!sub->ns || strcmp(sub->ns->value, LY_NSYIN)) { |
| 4545 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4546 | lyxml_free(module->ctx, sub); |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4547 | continue; |
| 4548 | } |
| 4549 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4550 | if (!strcmp(sub->name, "refine")) { |
| 4551 | c_ref++; |
| 4552 | } else if (!strcmp(sub->name, "augment")) { |
| 4553 | c_aug++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4554 | } else if (!strcmp(sub->name, "if-feature")) { |
Radek Krejci | 56e8977 | 2015-06-19 10:00:54 +0200 | [diff] [blame] | 4555 | c_ftrs++; |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4556 | } else if (!strcmp(sub->name, "when")) { |
| 4557 | if (uses->when) { |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4558 | LOGVAL(LYE_TOOMANY, LOGLINE(sub), sub->name, yin->name); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4559 | goto error; |
| 4560 | } |
| 4561 | |
| 4562 | uses->when = read_yin_when(module, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4563 | if (!uses->when) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4564 | lyxml_free(module->ctx, sub); |
Radek Krejci | b0af6ba | 2015-06-18 15:01:03 +0200 | [diff] [blame] | 4565 | goto error; |
| 4566 | } |
Michal Vasko | fcdac17 | 2015-10-07 09:35:05 +0200 | [diff] [blame] | 4567 | if (lyxp_syntax_check(uses->when->cond, LOGLINE(sub))) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4568 | goto error; |
| 4569 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4570 | lyxml_free(module->ctx, sub); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4571 | } else { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4572 | LOGVAL(LYE_INSTMT, LOGLINE(sub), sub->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4573 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4574 | } |
| 4575 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4576 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4577 | /* process properties with cardinality 0..n */ |
| 4578 | if (c_ref) { |
| 4579 | uses->refine = calloc(c_ref, sizeof *uses->refine); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4580 | if (!uses->refine) { |
| 4581 | LOGMEM; |
| 4582 | goto error; |
| 4583 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4584 | } |
| 4585 | if (c_aug) { |
| 4586 | uses->augment = calloc(c_aug, sizeof *uses->augment); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4587 | if (!uses->augment) { |
| 4588 | LOGMEM; |
| 4589 | goto error; |
| 4590 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4591 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4592 | if (c_ftrs) { |
| 4593 | uses->features = calloc(c_ftrs, sizeof *uses->features); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4594 | if (!uses->features) { |
| 4595 | LOGMEM; |
| 4596 | goto error; |
| 4597 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4598 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4599 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4600 | 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] | 4601 | goto error; |
| 4602 | } |
| 4603 | |
Radek Krejci | a954450 | 2015-08-14 08:24:29 +0200 | [diff] [blame] | 4604 | LY_TREE_FOR(yin->child, sub) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4605 | if (!strcmp(sub->name, "refine")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4606 | r = fill_yin_refine(module, sub, &uses->refine[uses->refine_size]); |
| 4607 | uses->refine_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4608 | if (r) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4609 | goto error; |
| 4610 | } |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4611 | } else if (!strcmp(sub->name, "augment")) { |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4612 | r = fill_yin_augment(module, retval, sub, &uses->augment[uses->augment_size], unres); |
| 4613 | uses->augment_size++; |
Michal Vasko | c3d9f8c | 2015-07-31 14:37:24 +0200 | [diff] [blame] | 4614 | if (r) { |
| 4615 | goto error; |
| 4616 | } |
| 4617 | } else if (!strcmp(sub->name, "if-feature")) { |
| 4618 | GETVAL(value, sub, "name"); |
Michal Vasko | fba1526 | 2015-10-21 12:10:28 +0200 | [diff] [blame] | 4619 | if (!(value = transform_schema2json(module, value, LOGLINE(sub)))) { |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 4620 | goto error; |
| 4621 | } |
Radek Krejci | cf50998 | 2015-12-15 09:22:44 +0100 | [diff] [blame] | 4622 | /* hack - store pointer to the parent node for later status check */ |
| 4623 | uses->features[uses->features_size] = (struct lys_feature *)uses; |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4624 | 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] | 4625 | LOGLINE(sub)); |
Radek Krejci | 7d74ebc | 2015-12-10 16:05:02 +0100 | [diff] [blame] | 4626 | uses->features_size++; |
Michal Vasko | 2d851a9 | 2015-10-20 16:16:36 +0200 | [diff] [blame] | 4627 | lydict_remove(module->ctx, value); |
| 4628 | if (r == -1) { |
Michal Vasko | 3ab70fc | 2015-08-17 14:06:23 +0200 | [diff] [blame] | 4629 | goto error; |
| 4630 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4631 | } |
| 4632 | } |
Radek Krejci | 3bde87f | 2015-06-05 16:51:58 +0200 | [diff] [blame] | 4633 | |
Michal Vasko | 0bd29d1 | 2015-08-19 11:45:49 +0200 | [diff] [blame] | 4634 | 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] | 4635 | goto error; |
| 4636 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 4637 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4638 | if (resolve) { |
| 4639 | /* inherit config flag */ |
| 4640 | if (parent) { |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4641 | retval->flags |= parent->flags & LYS_CONFIG_MASK; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4642 | } else { |
| 4643 | /* default config is true */ |
Radek Krejci | 1574a8d | 2015-08-03 14:16:52 +0200 | [diff] [blame] | 4644 | retval->flags |= LYS_CONFIG_W; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4645 | } |
| 4646 | } |
Radek Krejci | b388c15 | 2015-06-04 17:03:03 +0200 | [diff] [blame] | 4647 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4648 | return retval; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4649 | |
| 4650 | error: |
| 4651 | |
Radek Krejci | fa0b5e0 | 2016-02-04 13:57:03 +0100 | [diff] [blame] | 4652 | lys_node_free(retval, NULL); |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4653 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4654 | return NULL; |
Radek Krejci | c7c9a6c | 2015-05-25 16:35:06 +0200 | [diff] [blame] | 4655 | } |
| 4656 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 4657 | /* logs directly |
| 4658 | * |
| 4659 | * common code for yin_read_module() and yin_read_submodule() |
| 4660 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4661 | static int |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4662 | read_sub_module(struct lys_module *module, struct lys_submodule *submodule, struct lyxml_elem *yin, |
| 4663 | struct unres_schema *unres) |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4664 | { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4665 | struct ly_ctx *ctx = module->ctx; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4666 | struct lyxml_elem *next, *child, *child2, root, grps, augs; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4667 | struct lys_node *node = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4668 | struct lys_module *trg; |
| 4669 | struct lys_import *aux_imp; |
| 4670 | struct lys_include *aux_inc, inc; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4671 | const char *value; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4672 | int i, j, r; |
| 4673 | int inc_size_aux = 0; |
| 4674 | int version_flag = 0; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4675 | /* counters */ |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4676 | 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] | 4677 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4678 | /* to simplify code, store the module/submodule being processed as trg */ |
| 4679 | trg = submodule ? (struct lys_module*)submodule : module; |
| 4680 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4681 | /* init */ |
| 4682 | memset(&root, 0, sizeof root); |
| 4683 | memset(&grps, 0, sizeof grps); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4684 | memset(&augs, 0, sizeof augs); |
Radek Krejci | e0674f8 | 2015-06-15 13:58:51 +0200 | [diff] [blame] | 4685 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4686 | /* |
| 4687 | * in the first run, we process elements with cardinality of 1 or 0..1 and |
| 4688 | * count elements with cardinality 0..n. Data elements (choices, containers, |
| 4689 | * leafs, lists, leaf-lists) are moved aside to be processed last, since we |
| 4690 | * need have all top-level and groupings already prepared at that time. In |
| 4691 | * the middle loop, we process other elements with carinality of 0..n since |
| 4692 | * we need to allocate arrays to store them. |
| 4693 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4694 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
| 4695 | if (!child->ns || strcmp(child->ns->value, LY_NSYIN)) { |
Radek Krejci | 0d70c37 | 2015-07-02 16:23:10 +0200 | [diff] [blame] | 4696 | /* garbage */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4697 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4698 | continue; |
| 4699 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4700 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4701 | if (!submodule && !strcmp(child->name, "namespace")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4702 | if (module->ns) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4703 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4704 | goto error; |
| 4705 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4706 | GETVAL(value, child, "uri"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4707 | module->ns = lydict_insert(ctx, value, strlen(value)); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4708 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4709 | } else if (!submodule && !strcmp(child->name, "prefix")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4710 | if (module->prefix) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4711 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4712 | goto error; |
| 4713 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4714 | GETVAL(value, child, "value"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 4715 | if (lyp_check_identifier(value, LY_IDENT_PREFIX, LOGLINE(child), module, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4716 | goto error; |
| 4717 | } |
| 4718 | module->prefix = lydict_insert(ctx, value, strlen(value)); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4719 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4720 | } else if (submodule && !strcmp(child->name, "belongs-to")) { |
| 4721 | if (submodule->prefix) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4722 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4723 | goto error; |
| 4724 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4725 | GETVAL(value, child, "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4726 | if (value != submodule->belongsto->name) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4727 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4728 | goto error; |
| 4729 | } |
Radek Krejci | f388693 | 2015-06-04 17:36:06 +0200 | [diff] [blame] | 4730 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4731 | /* get the prefix substatement, start with checks */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4732 | if (!child->child) { |
| 4733 | LOGVAL(LYE_MISSSTMT2, LOGLINE(child), "prefix", child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4734 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4735 | } else if (strcmp(child->child->name, "prefix")) { |
| 4736 | LOGVAL(LYE_INSTMT, LOGLINE(child->child), child->child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4737 | goto error; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4738 | } else if (child->child->next) { |
| 4739 | LOGVAL(LYE_INSTMT, LOGLINE(child->child->next), child->child->next->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4740 | goto error; |
| 4741 | } |
| 4742 | /* and now finally get the value */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4743 | GETVAL(value, child->child, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4744 | /* check here differs from a generic prefix check, since this prefix |
| 4745 | * don't have to be unique |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4746 | */ |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 4747 | 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] | 4748 | goto error; |
| 4749 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4750 | submodule->prefix = lydict_insert(ctx, value, strlen(value)); |
Radek Krejci | 0af1387 | 2015-05-30 11:50:52 +0200 | [diff] [blame] | 4751 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4752 | /* we are done with belongs-to */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4753 | lyxml_free(ctx, child); |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4754 | |
| 4755 | /* counters (statements with n..1 cardinality) */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4756 | } else if (!strcmp(child->name, "import")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4757 | c_imp++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4758 | } else if (!strcmp(child->name, "revision")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4759 | c_rev++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4760 | } else if (!strcmp(child->name, "typedef")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4761 | c_tpdf++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4762 | } else if (!strcmp(child->name, "identity")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4763 | c_ident++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4764 | } else if (!strcmp(child->name, "include")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4765 | c_inc++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4766 | } else if (!strcmp(child->name, "augment")) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4767 | c_aug++; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4768 | /* keep augments separated, processed last */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4769 | lyxml_unlink_elem(ctx, child, 2); |
| 4770 | lyxml_add_child(ctx, &augs, child); |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4771 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4772 | } else if (!strcmp(child->name, "feature")) { |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4773 | c_ftrs++; |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4774 | } else if (!strcmp(child->name, "deviation")) { |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4775 | c_dev++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4776 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4777 | /* data statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4778 | } else if (!strcmp(child->name, "container") || |
| 4779 | !strcmp(child->name, "leaf-list") || |
| 4780 | !strcmp(child->name, "leaf") || |
| 4781 | !strcmp(child->name, "list") || |
| 4782 | !strcmp(child->name, "choice") || |
| 4783 | !strcmp(child->name, "uses") || |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 4784 | !strcmp(child->name, "anyxml") || |
| 4785 | !strcmp(child->name, "rpc") || |
| 4786 | !strcmp(child->name, "notification")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4787 | lyxml_unlink_elem(ctx, child, 2); |
| 4788 | lyxml_add_child(ctx, &root, child); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 4789 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4790 | } else if (!strcmp(child->name, "grouping")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4791 | /* keep groupings separated and process them before other data statements */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4792 | lyxml_unlink_elem(ctx, child, 2); |
| 4793 | lyxml_add_child(ctx, &grps, child); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4794 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4795 | /* optional statements */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4796 | } else if (!strcmp(child->name, "description")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4797 | if (trg->dsc) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4798 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4799 | goto error; |
| 4800 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4801 | trg->dsc = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4802 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4803 | if (!trg->dsc) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4804 | goto error; |
| 4805 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4806 | } else if (!strcmp(child->name, "reference")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4807 | if (trg->ref) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4808 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4809 | goto error; |
| 4810 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4811 | trg->ref = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4812 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4813 | if (!trg->ref) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4814 | goto error; |
| 4815 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4816 | } else if (!strcmp(child->name, "organization")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4817 | if (trg->org) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4818 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4819 | goto error; |
| 4820 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4821 | trg->org = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4822 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4823 | if (!trg->org) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4824 | goto error; |
| 4825 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4826 | } else if (!strcmp(child->name, "contact")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4827 | if (trg->contact) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4828 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4829 | goto error; |
| 4830 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4831 | trg->contact = read_yin_subnode(ctx, child, "text"); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4832 | lyxml_free(ctx, child); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4833 | if (!trg->contact) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4834 | goto error; |
| 4835 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4836 | } else if (!strcmp(child->name, "yang-version")) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4837 | /* TODO: support YANG 1.1 ? */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4838 | if (version_flag) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4839 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child->name, yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4840 | goto error; |
| 4841 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4842 | GETVAL(value, child, "value"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4843 | if (strcmp(value, "1")) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4844 | LOGVAL(LYE_INARG, LOGLINE(child), value, "yang-version"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4845 | goto error; |
| 4846 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4847 | version_flag = 1; |
| 4848 | if (!submodule) { |
| 4849 | module->version = 1; |
| 4850 | } /* 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] | 4851 | lyxml_free(ctx, child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 4852 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4853 | } else if (!strcmp(child->name, "extension")) { |
| 4854 | GETVAL(value, child, "name"); |
Radek Krejci | 5166a89 | 2015-07-02 16:44:24 +0200 | [diff] [blame] | 4855 | |
Radek Krejci | 3d46812 | 2015-10-02 13:36:12 +0200 | [diff] [blame] | 4856 | /* we have the following supported (hardcoded) extensions: */ |
| 4857 | /* ietf-netconf's get-filter-element-attributes */ |
| 4858 | if (!strcmp(module->ns, LY_NSNC) && |
| 4859 | !strcmp(value, "get-filter-element-attributes")) { |
| 4860 | LOGDBG("NETCONF filter extension found"); |
| 4861 | /* NACM's default-deny-write and default-deny-all */ |
| 4862 | } else if (!strcmp(module->ns, LY_NSNACM) && |
| 4863 | (!strcmp(value, "default-deny-write") || !strcmp(value, "default-deny-all"))) { |
| 4864 | LOGDBG("NACM extension found"); |
| 4865 | /* other extensions are not supported, so inform about such an extension */ |
| 4866 | } else { |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 4867 | LOGWRN("Not supported \"%s\" extension statement found, ignoring.", value); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 4868 | lyxml_free(ctx, child); |
Radek Krejci | 6764bb3 | 2015-07-03 15:16:04 +0200 | [diff] [blame] | 4869 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4870 | } else { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4871 | LOGVAL(LYE_INSTMT, LOGLINE(child), child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4872 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4873 | } |
| 4874 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4875 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4876 | /* check for mandatory statements */ |
| 4877 | if (submodule && !submodule->prefix) { |
Michal Vasko | bdf51ef | 2015-12-10 12:11:21 +0100 | [diff] [blame] | 4878 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "belongs-to", "submodule"); |
| 4879 | goto error; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4880 | } else if (!submodule) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4881 | if (!module->ns) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4882 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "namespace", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4883 | goto error; |
| 4884 | } |
| 4885 | if (!module->prefix) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 4886 | LOGVAL(LYE_MISSSTMT2, LOGLINE(yin), "prefix", "module"); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4887 | goto error; |
| 4888 | } |
| 4889 | } |
Radek Krejci | bb3257d | 2015-05-21 23:03:51 +0200 | [diff] [blame] | 4890 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4891 | /* allocate arrays for elements with cardinality of 0..n */ |
| 4892 | if (c_imp) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4893 | trg->imp = calloc(c_imp, sizeof *trg->imp); |
| 4894 | if (!trg->imp) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4895 | LOGMEM; |
| 4896 | goto error; |
| 4897 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4898 | } |
| 4899 | if (c_rev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4900 | trg->rev = calloc(c_rev, sizeof *trg->rev); |
| 4901 | if (!trg->rev) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4902 | LOGMEM; |
| 4903 | goto error; |
| 4904 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4905 | } |
| 4906 | if (c_tpdf) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4907 | trg->tpdf = calloc(c_tpdf, sizeof *trg->tpdf); |
| 4908 | if (!trg->tpdf) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4909 | LOGMEM; |
| 4910 | goto error; |
| 4911 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4912 | } |
| 4913 | if (c_ident) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4914 | trg->ident = calloc(c_ident, sizeof *trg->ident); |
| 4915 | if (!trg->ident) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4916 | LOGMEM; |
| 4917 | goto error; |
| 4918 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4919 | } |
| 4920 | if (c_inc) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4921 | trg->inc = calloc(c_inc, sizeof *trg->inc); |
| 4922 | if (!trg->inc) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4923 | LOGMEM; |
| 4924 | goto error; |
| 4925 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4926 | trg->inc_size = c_inc; |
| 4927 | /* trg->inc_size can be updated by the included submodules, |
| 4928 | * so we will use inc_size_aux here, trg->inc_size stores the |
| 4929 | * target size of the array |
| 4930 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4931 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4932 | if (c_aug) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4933 | trg->augment = calloc(c_aug, sizeof *trg->augment); |
| 4934 | if (!trg->augment) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4935 | LOGMEM; |
| 4936 | goto error; |
| 4937 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 4938 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4939 | if (c_ftrs) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4940 | trg->features = calloc(c_ftrs, sizeof *trg->features); |
| 4941 | if (!trg->features) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4942 | LOGMEM; |
| 4943 | goto error; |
| 4944 | } |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 4945 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4946 | if (c_dev) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4947 | trg->deviation = calloc(c_dev, sizeof *trg->deviation); |
| 4948 | if (!trg->deviation) { |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 4949 | LOGMEM; |
| 4950 | goto error; |
| 4951 | } |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 4952 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 4953 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4954 | /* middle part - process nodes with cardinality of 0..n except the data nodes and augments */ |
| 4955 | LY_TREE_FOR_SAFE(yin->child, next, child) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4956 | if (!strcmp(child->name, "import")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4957 | r = fill_yin_import(trg, child, &trg->imp[trg->imp_size]); |
| 4958 | trg->imp_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4959 | if (r) { |
| 4960 | goto error; |
| 4961 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4962 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4963 | /* check duplicities in imported modules */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4964 | for (i = 0; i < trg->imp_size - 1; i++) { |
| 4965 | if (!strcmp(trg->imp[i].module->name, trg->imp[trg->imp_size - 1].module->name)) { |
| 4966 | 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] | 4967 | goto error; |
| 4968 | } |
| 4969 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4970 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4971 | } else if (!strcmp(child->name, "include")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4972 | memset(&inc, 0, sizeof inc); |
| 4973 | /* 1) pass module, not trg, since we want to pass the main module |
| 4974 | * 2) we cannot pass directly the structure in the array since |
| 4975 | * submodule parser can realloc our array of includes */ |
Michal Vasko | 5ff7882 | 2016-02-12 09:33:31 +0100 | [diff] [blame] | 4976 | r = fill_yin_include(module, submodule, child, &inc, unres); |
Michal Vasko | 9c4c99d | 2016-02-11 15:47:08 +0100 | [diff] [blame] | 4977 | memcpy(&trg->inc[inc_size_aux], &inc, sizeof inc); |
| 4978 | inc_size_aux++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4979 | if (r) { |
| 4980 | goto error; |
| 4981 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 4982 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4983 | /* check duplications in include submodules */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4984 | for (i = 0; i < inc_size_aux - 1; i++) { |
Michal Vasko | 27ab822 | 2016-02-12 09:33:52 +0100 | [diff] [blame] | 4985 | if (trg->inc[i].submodule && !strcmp(trg->inc[i].submodule->name, trg->inc[inc_size_aux - 1].submodule->name)) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4986 | LOGVAL(LYE_SPEC, LOGLINE(child), "Including submodule \"%s\" repeatedly.", |
Michal Vasko | 27ab822 | 2016-02-12 09:33:52 +0100 | [diff] [blame] | 4987 | trg->inc[i].submodule->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4988 | goto error; |
| 4989 | } |
| 4990 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 4991 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 4992 | } else if (!strcmp(child->name, "revision")) { |
| 4993 | GETVAL(value, child, "date"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 4994 | if (lyp_check_date(value, LOGLINE(child))) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4995 | goto error; |
| 4996 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4997 | memcpy(trg->rev[trg->rev_size].date, value, LY_REV_SIZE - 1); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 4998 | /* check uniqueness of the revision date - not required by RFC */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 4999 | for (i = 0; i < trg->rev_size; i++) { |
| 5000 | if (!strcmp(value, trg->rev[i].date)) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5001 | LOGVAL(LYE_INARG, LOGLINE(child), value, child->name); |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 5002 | LOGVAL(LYE_SPEC, 0, "Revision is not unique."); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5003 | } |
| 5004 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 5005 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5006 | LY_TREE_FOR(child->child, child2) { |
| 5007 | if (!strcmp(child2->name, "description")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5008 | if (trg->rev[trg->rev_size].dsc) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5009 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child2->name, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5010 | goto error; |
| 5011 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5012 | trg->rev[trg->rev_size].dsc = read_yin_subnode(ctx, child2, "text"); |
| 5013 | if (!trg->rev[trg->rev_size].dsc) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5014 | goto error; |
| 5015 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5016 | } else if (!strcmp(child2->name, "reference")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5017 | if (trg->rev[trg->rev_size].ref) { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5018 | LOGVAL(LYE_TOOMANY, LOGLINE(child), child2->name, child->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5019 | goto error; |
| 5020 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5021 | trg->rev[trg->rev_size].ref = read_yin_subnode(ctx, child2, "text"); |
| 5022 | if (!trg->rev[trg->rev_size].ref) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5023 | goto error; |
| 5024 | } |
| 5025 | } else { |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5026 | LOGVAL(LYE_INSTMT, LOGLINE(child2), child2->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5027 | goto error; |
| 5028 | } |
| 5029 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 5030 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5031 | /* keep the latest revision at position 0 */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5032 | 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] | 5033 | /* switch their position */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5034 | value = strdup(trg->rev[0].date); |
Michal Vasko | 253035f | 2015-12-17 16:58:13 +0100 | [diff] [blame] | 5035 | if (!value) { |
| 5036 | LOGMEM; |
| 5037 | goto error; |
| 5038 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5039 | memcpy(trg->rev[0].date, trg->rev[trg->rev_size].date, LY_REV_SIZE - 1); |
| 5040 | memcpy(trg->rev[trg->rev_size].date, value, LY_REV_SIZE - 1); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5041 | free((char *)value); |
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 | if (trg->rev[0].dsc != trg->rev[trg->rev_size].dsc) { |
| 5044 | value = trg->rev[0].dsc; |
| 5045 | trg->rev[0].dsc = trg->rev[trg->rev_size].dsc; |
| 5046 | trg->rev[trg->rev_size].dsc = value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5047 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 5048 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5049 | if (trg->rev[0].ref != trg->rev[trg->rev_size].ref) { |
| 5050 | value = trg->rev[0].ref; |
| 5051 | trg->rev[0].ref = trg->rev[trg->rev_size].ref; |
| 5052 | trg->rev[trg->rev_size].ref = value; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5053 | } |
| 5054 | } |
Radek Krejci | ce7fb78 | 2015-05-29 16:52:34 +0200 | [diff] [blame] | 5055 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5056 | trg->rev_size++; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5057 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5058 | } else if (!strcmp(child->name, "typedef")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5059 | r = fill_yin_typedef(trg, NULL, child, &trg->tpdf[trg->tpdf_size], unres); |
| 5060 | trg->tpdf_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5061 | if (r) { |
| 5062 | goto error; |
| 5063 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5064 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5065 | } else if (!strcmp(child->name, "identity")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5066 | r = fill_yin_identity(trg, child, &trg->ident[trg->ident_size], unres); |
| 5067 | trg->ident_size++; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5068 | if (r) { |
| 5069 | goto error; |
| 5070 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5071 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5072 | } else if (!strcmp(child->name, "feature")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5073 | r = fill_yin_feature(trg, child, &trg->features[trg->features_size], unres); |
| 5074 | trg->features_size++; |
Radek Krejci | 3cf9e22 | 2015-06-18 11:37:50 +0200 | [diff] [blame] | 5075 | if (r) { |
| 5076 | goto error; |
| 5077 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5078 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5079 | } else if (!strcmp(child->name, "deviation")) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5080 | r = fill_yin_deviation(trg, child, &trg->deviation[trg->deviation_size], unres); |
| 5081 | trg->deviation_size++; |
Radek Krejci | eb00f51 | 2015-07-01 16:44:58 +0200 | [diff] [blame] | 5082 | if (r) { |
| 5083 | goto error; |
| 5084 | } |
Michal Vasko | 53a42af | 2016-02-12 11:05:02 +0100 | [diff] [blame] | 5085 | /* module with deviation - must be implemented (description of /ietf-yang-library:modules-state/module/deviation) */ |
| 5086 | module->implemented = 1; |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5087 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5088 | } |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5089 | } |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5090 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5091 | if (submodule) { |
| 5092 | /* propagate imports into the main module */ |
| 5093 | for (i = r = 0; i < submodule->imp_size; i++) { |
| 5094 | for (j = 0; j < module->imp_size; j++) { |
| 5095 | if (submodule->imp[i].module == module->imp[j].module && |
| 5096 | !strcmp(submodule->imp[i].rev, module->imp[j].rev)) { |
| 5097 | /* check prefix match */ |
| 5098 | if (submodule->imp[i].prefix != module->imp[j].prefix) { |
| 5099 | LOGVAL(LYE_INID, LOGLINE(yin), submodule->imp[i].prefix, |
| 5100 | "non-matching prefixes of imported module in main module and submodule"); |
| 5101 | goto error; |
| 5102 | } |
| 5103 | break; |
| 5104 | } |
| 5105 | } |
| 5106 | if (j == module->imp_size) { |
| 5107 | /* new import */ |
| 5108 | r++; |
| 5109 | } |
| 5110 | } |
| 5111 | if (r) { |
| 5112 | aux_imp = realloc(module->imp, (module->imp_size + r) * sizeof *module->imp); |
| 5113 | if (!aux_imp) { |
| 5114 | LOGMEM; |
| 5115 | goto error; |
| 5116 | } |
| 5117 | module->imp = aux_imp; |
| 5118 | for (i = r = 0; i < submodule->imp_size; i++) { |
| 5119 | for (j = 0; j < module->imp_size; j++) { |
| 5120 | if (submodule->imp[i].module == module->imp[j].module) { |
| 5121 | break; |
| 5122 | } |
| 5123 | } |
| 5124 | if (j == module->imp_size) { |
| 5125 | /* new import */ |
| 5126 | /* check prefix uniqueness */ |
| 5127 | if (dup_prefix_check(submodule->imp[i].prefix, module)) { |
| 5128 | LOGVAL(LYE_DUPID, LOGLINE(yin), "prefix", submodule->imp[i].prefix); |
| 5129 | goto error; |
| 5130 | } |
| 5131 | memcpy(&module->imp[module->imp_size + r], &submodule->imp[i], sizeof *submodule->imp); |
| 5132 | module->imp[module->imp_size + r].external = 1; |
| 5133 | r++; |
| 5134 | } |
| 5135 | } |
| 5136 | module->imp_size += r; |
| 5137 | } |
| 5138 | |
Michal Vasko | e290563 | 2016-02-11 15:42:24 +0100 | [diff] [blame] | 5139 | /* propagate includes into the main module */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5140 | for (i = r = 0; i < submodule->inc_size; i++) { |
| 5141 | for (j = 0; j < module->inc_size; j++) { |
| 5142 | if (submodule->inc[i].submodule == module->inc[j].submodule) { |
| 5143 | break; |
| 5144 | } |
| 5145 | } |
| 5146 | if (j == module->inc_size) { |
| 5147 | /* new include */ |
| 5148 | r++; |
| 5149 | } |
| 5150 | } |
| 5151 | |
| 5152 | if (r) { |
| 5153 | aux_inc = realloc(module->inc, (module->inc_size + r) * sizeof *module->inc); |
| 5154 | if (!aux_inc) { |
| 5155 | LOGMEM; |
| 5156 | goto error; |
| 5157 | } |
| 5158 | module->inc = aux_inc; |
| 5159 | for (i = r = 0; i < submodule->inc_size; i++) { |
| 5160 | for (j = 0; j < module->inc_size; j++) { |
| 5161 | if (submodule->inc[i].submodule == module->inc[j].submodule) { |
| 5162 | break; |
| 5163 | } |
| 5164 | } |
| 5165 | if (j == module->inc_size) { |
| 5166 | /* new include */ |
| 5167 | memcpy(&module->inc[module->inc_size + r], &submodule->inc[i], sizeof *submodule->inc); |
| 5168 | module->inc[module->inc_size + r].external = 1; |
| 5169 | r++; |
| 5170 | } |
| 5171 | } |
| 5172 | module->inc_size += r; |
| 5173 | } |
| 5174 | } |
| 5175 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5176 | /* process data nodes. Start with groupings to allow uses |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5177 | * refer to them. Submodule's data nodes are stored in the |
| 5178 | * main module data tree. |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5179 | */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5180 | LY_TREE_FOR_SAFE(grps.child, next, child) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5181 | node = read_yin_grouping(trg, NULL, child, 0, unres); |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5182 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5183 | goto error; |
| 5184 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 5185 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5186 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5187 | } |
Radek Krejci | 7470511 | 2015-06-05 10:25:44 +0200 | [diff] [blame] | 5188 | |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5189 | /* parse data nodes, ... */ |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5190 | LY_TREE_FOR_SAFE(root.child, next, child) { |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5191 | |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5192 | if (!strcmp(child->name, "container")) { |
| 5193 | node = read_yin_container(module, NULL, child, 1, unres); |
| 5194 | } else if (!strcmp(child->name, "leaf-list")) { |
| 5195 | node = read_yin_leaflist(module, NULL, child, 1, unres); |
| 5196 | } else if (!strcmp(child->name, "leaf")) { |
| 5197 | node = read_yin_leaf(module, NULL, child, 1, unres); |
| 5198 | } else if (!strcmp(child->name, "list")) { |
| 5199 | node = read_yin_list(module, NULL, child, 1, unres); |
| 5200 | } else if (!strcmp(child->name, "choice")) { |
| 5201 | node = read_yin_choice(module, NULL, child, 1, unres); |
| 5202 | } else if (!strcmp(child->name, "uses")) { |
| 5203 | node = read_yin_uses(module, NULL, child, 1, unres); |
| 5204 | } else if (!strcmp(child->name, "anyxml")) { |
| 5205 | node = read_yin_anyxml(module, NULL, child, 1, unres); |
Michal Vasko | 7ffc305 | 2015-10-21 15:05:56 +0200 | [diff] [blame] | 5206 | } else if (!strcmp(child->name, "rpc")) { |
| 5207 | node = read_yin_rpc(module, NULL, child, 0, unres); |
| 5208 | } else if (!strcmp(child->name, "notification")) { |
| 5209 | node = read_yin_notif(module, NULL, child, 0, unres); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5210 | } |
Radek Krejci | 1d82ef6 | 2015-08-07 14:44:40 +0200 | [diff] [blame] | 5211 | if (!node) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5212 | goto error; |
| 5213 | } |
Radek Krejci | 25d782a | 2015-05-22 15:03:23 +0200 | [diff] [blame] | 5214 | |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5215 | lyxml_free(ctx, child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5216 | } |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5217 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5218 | /* ... and finally augments (last, so we can augment our data, for instance) */ |
| 5219 | LY_TREE_FOR_SAFE(augs.child, next, child) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5220 | r = fill_yin_augment(trg, NULL, child, &trg->augment[trg->augment_size], unres); |
| 5221 | trg->augment_size++; |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5222 | |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5223 | if (r) { |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5224 | goto error; |
| 5225 | } |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5226 | lyxml_free(ctx, child); |
Radek Krejci | f5be10f | 2015-06-16 13:29:36 +0200 | [diff] [blame] | 5227 | } |
| 5228 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5229 | return EXIT_SUCCESS; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5230 | |
| 5231 | error: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5232 | /* cleanup */ |
| 5233 | while (root.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5234 | lyxml_free(module->ctx, root.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5235 | } |
| 5236 | while (grps.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5237 | lyxml_free(module->ctx, grps.child); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5238 | } |
Michal Vasko | 2f7925f | 2015-10-21 15:06:56 +0200 | [diff] [blame] | 5239 | while (augs.child) { |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5240 | lyxml_free(module->ctx, augs.child); |
Michal Vasko | 38d01f7 | 2015-06-15 09:41:06 +0200 | [diff] [blame] | 5241 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5242 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5243 | return EXIT_FAILURE; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5244 | } |
| 5245 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5246 | /* logs directly */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5247 | struct lys_submodule * |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5248 | 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] | 5249 | { |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5250 | struct lys_node *next, *elem; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5251 | struct lyxml_elem *yin; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5252 | struct lys_submodule *submodule = NULL; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5253 | const char *value; |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5254 | uint8_t i; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5255 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5256 | assert(module->ctx); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5257 | |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 5258 | yin = lyxml_parse_mem(module->ctx, data, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5259 | if (!yin) { |
| 5260 | return NULL; |
| 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 | /* check root element */ |
| 5264 | if (!yin->name || strcmp(yin->name, "submodule")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 5265 | LOGVAL(LYE_INSTMT, LOGLINE(yin), yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5266 | goto error; |
| 5267 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5268 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5269 | GETVAL(value, yin, "name"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 5270 | if (lyp_check_identifier(value, LY_IDENT_NAME, LOGLINE(yin), NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5271 | goto error; |
| 5272 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5273 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5274 | submodule = calloc(1, sizeof *submodule); |
| 5275 | if (!submodule) { |
| 5276 | LOGMEM; |
| 5277 | goto error; |
| 5278 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5279 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5280 | submodule->ctx = module->ctx; |
| 5281 | submodule->name = lydict_insert(submodule->ctx, value, strlen(value)); |
| 5282 | submodule->type = 1; |
| 5283 | submodule->belongsto = module; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5284 | |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5285 | LOGVRB("Reading submodule \"%s\".", submodule->name); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5286 | if (read_sub_module(module, submodule, yin, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5287 | goto error; |
| 5288 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5289 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5290 | /* cleanup */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5291 | lyxml_free(module->ctx, yin); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5292 | |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5293 | LOGVRB("Submodule \"%s\" successfully parsed.", submodule->name); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5294 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5295 | return submodule; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5296 | |
| 5297 | error: |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5298 | LOGERR(ly_errno, "Submodule \"%s\" parsing failed.", submodule->name); |
| 5299 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5300 | /* cleanup */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5301 | unres_schema_free((struct lys_module *)submodule, &unres); |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5302 | lyxml_free(module->ctx, yin); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5303 | |
| 5304 | /* warn about applied deviations */ |
| 5305 | for (i = 0; i < submodule->deviation_size; ++i) { |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 5306 | if (submodule->deviation[i].target_module) { |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5307 | LOGERR(ly_errno, "Submodule parsing failed, but successfully deviated %smodule \"%s\".", |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 5308 | (submodule->deviation[i].target_module->type ? "sub" : ""), |
| 5309 | submodule->deviation[i].target_module->name); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5310 | } |
| 5311 | } |
| 5312 | |
| 5313 | /* remove applied augments */ |
| 5314 | for (i = 0; i < submodule->augment_size; ++i) { |
| 5315 | if (submodule->augment[i].target) { |
| 5316 | LY_TREE_FOR_SAFE(submodule->augment[i].target->child, next, elem) { |
| 5317 | if (elem->parent == (struct lys_node *)&submodule->augment[i]) { |
| 5318 | lys_node_free(elem, NULL); |
| 5319 | } |
| 5320 | } |
| 5321 | } |
| 5322 | } |
| 5323 | |
| 5324 | lys_submodule_free(submodule, NULL); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5325 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5326 | return NULL; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5327 | } |
| 5328 | |
Michal Vasko | 0d343d1 | 2015-08-24 14:57:36 +0200 | [diff] [blame] | 5329 | /* logs directly */ |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5330 | struct lys_module * |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5331 | yin_read_module(struct ly_ctx *ctx, const char *data, int implement) |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5332 | { |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5333 | struct lys_node *next, *elem; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5334 | struct lyxml_elem *yin; |
Radek Krejci | b804869 | 2015-08-05 13:36:34 +0200 | [diff] [blame] | 5335 | struct lys_module *module = NULL, **newlist = NULL; |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5336 | struct unres_schema *unres; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5337 | const char *value; |
| 5338 | int i; |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5339 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5340 | unres = calloc(1, sizeof *unres); |
| 5341 | if (!unres) { |
| 5342 | LOGMEM; |
| 5343 | return NULL; |
| 5344 | } |
| 5345 | |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 5346 | yin = lyxml_parse_mem(ctx, data, 0); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5347 | if (!yin) { |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5348 | goto error; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5349 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5350 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5351 | /* check root element */ |
| 5352 | if (!yin->name || strcmp(yin->name, "module")) { |
Michal Vasko | e7fc19c | 2015-08-05 16:24:39 +0200 | [diff] [blame] | 5353 | LOGVAL(LYE_INSTMT, LOGLINE(yin), yin->name); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5354 | goto error; |
| 5355 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5356 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5357 | GETVAL(value, yin, "name"); |
Radek Krejci | c655602 | 2016-01-27 15:16:45 +0100 | [diff] [blame] | 5358 | if (lyp_check_identifier(value, LY_IDENT_NAME, LOGLINE(yin), NULL, NULL)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5359 | goto error; |
| 5360 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5361 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5362 | module = calloc(1, sizeof *module); |
| 5363 | if (!module) { |
| 5364 | LOGMEM; |
| 5365 | goto error; |
| 5366 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5367 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5368 | module->ctx = ctx; |
| 5369 | module->name = lydict_insert(ctx, value, strlen(value)); |
| 5370 | module->type = 0; |
Michal Vasko | d8aa32d | 2015-07-24 11:50:01 +0200 | [diff] [blame] | 5371 | module->implemented = (implement ? 1 : 0); |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5372 | |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5373 | LOGVRB("Reading module \"%s\".", module->name); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5374 | if (read_sub_module(module, NULL, yin, unres)) { |
| 5375 | goto error; |
| 5376 | } |
| 5377 | |
| 5378 | /* resolve rest of unres items */ |
| 5379 | if (unres->count && resolve_unres_schema(module, unres)) { |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5380 | goto error; |
| 5381 | } |
Radek Krejci | efaeba3 | 2015-05-27 14:30:57 +0200 | [diff] [blame] | 5382 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5383 | /* add to the context's list of modules */ |
| 5384 | if (ctx->models.used == ctx->models.size) { |
Michal Vasko | f2e1a99 | 2015-11-09 09:54:47 +0100 | [diff] [blame] | 5385 | newlist = realloc(ctx->models.list, (2 * ctx->models.size) * sizeof *newlist); |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5386 | if (!newlist) { |
| 5387 | LOGMEM; |
| 5388 | goto error; |
| 5389 | } |
| 5390 | for (i = ctx->models.size; i < ctx->models.size * 2; i++) { |
| 5391 | newlist[i] = NULL; |
| 5392 | } |
| 5393 | ctx->models.size *= 2; |
| 5394 | ctx->models.list = newlist; |
| 5395 | } |
| 5396 | for (i = 0; ctx->models.list[i]; i++) { |
| 5397 | /* check name (name/revision) and namespace uniqueness */ |
| 5398 | if (!strcmp(ctx->models.list[i]->name, module->name)) { |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 5399 | if (ctx->models.list[i]->rev_size == module->rev_size) { |
| 5400 | /* both have the same number of revisions */ |
| 5401 | if (!module->rev_size || !strcmp(ctx->models.list[i]->rev[0].date, module->rev[0].date)) { |
| 5402 | /* both have the same revision -> we already have the same module */ |
| 5403 | /* so free the new one and update the old one's implement flag if needed */ |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5404 | LOGVRB("Module \"%s\" already in context.", ctx->models.list[i]->name); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 5405 | |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5406 | lys_free(module, NULL, 1); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5407 | module = ctx->models.list[i]; |
| 5408 | if (implement && !module->implemented) { |
| 5409 | lyp_set_implemented(module); |
Radek Krejci | 63a91a9 | 2015-07-29 13:31:04 +0200 | [diff] [blame] | 5410 | } |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5411 | |
| 5412 | goto success; |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5413 | } |
| 5414 | } |
Radek Krejci | f647e61 | 2015-07-30 11:36:07 +0200 | [diff] [blame] | 5415 | /* else (both elses) keep searching, for now the caller is just adding |
| 5416 | * another revision of an already present schema |
| 5417 | */ |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5418 | } else if (!strcmp(ctx->models.list[i]->ns, module->ns)) { |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5419 | LOGERR(LY_EINVAL, "Two different modules (\"%s\" and \"%s\") have the same namespace \"%s\".", |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5420 | ctx->models.list[i]->name, module->name, module->ns); |
| 5421 | goto error; |
| 5422 | } |
| 5423 | } |
| 5424 | ctx->models.list[i] = module; |
| 5425 | ctx->models.used++; |
Michal Vasko | 68cffd7 | 2015-08-03 12:50:11 +0200 | [diff] [blame] | 5426 | ctx->models.module_set_id++; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5427 | |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5428 | success: |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5429 | /* cleanup */ |
Michal Vasko | 345da0a | 2015-12-02 10:35:55 +0100 | [diff] [blame] | 5430 | lyxml_free(ctx, yin); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5431 | unres_schema_free(NULL, &unres); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5432 | |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5433 | LOGVRB("Module \"%s\" successfully parsed.", module->name); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5434 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5435 | return module; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5436 | |
| 5437 | error: |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5438 | LOGERR(ly_errno, "Module \"%s\" parsing failed.", module->name); |
| 5439 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5440 | /* cleanup */ |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5441 | unres_schema_free(module, &unres); |
Radek Krejci | c071c54 | 2016-01-27 14:57:51 +0100 | [diff] [blame] | 5442 | lyxml_free(ctx, yin); |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5443 | |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5444 | /* warn about applied deviations */ |
| 5445 | for (i = 0; i < module->deviation_size; ++i) { |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 5446 | if (module->deviation[i].target_module) { |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5447 | LOGERR(ly_errno, "Module parsing failed, but successfully deviated %smodule \"%s\".", |
Michal Vasko | 60f4b45 | 2016-02-12 11:02:55 +0100 | [diff] [blame] | 5448 | (module->deviation[i].target_module->type ? "sub" : ""), |
| 5449 | module->deviation[i].target_module->name); |
Michal Vasko | 9f258e4 | 2016-02-11 11:36:27 +0100 | [diff] [blame] | 5450 | } |
| 5451 | } |
| 5452 | |
| 5453 | /* remove applied augments */ |
| 5454 | for (i = 0; i < module->augment_size; ++i) { |
| 5455 | if (module->augment[i].target) { |
| 5456 | LY_TREE_FOR_SAFE(module->augment[i].target->child, next, elem) { |
| 5457 | if (elem->parent == (struct lys_node *)&module->augment[i]) { |
| 5458 | lys_node_free(elem, NULL); |
| 5459 | } |
| 5460 | } |
| 5461 | } |
| 5462 | } |
| 5463 | |
| 5464 | lys_free(module, NULL, 1); |
| 5465 | |
Radek Krejci | 6e4ffbb | 2015-06-16 10:34:41 +0200 | [diff] [blame] | 5466 | return NULL; |
Radek Krejci | da04f4a | 2015-05-21 12:54:09 +0200 | [diff] [blame] | 5467 | } |