Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 1 | /** |
| 2 | * @file parser_yang.c |
| 3 | * @author Pavol Vican |
| 4 | * @brief YANG parser for libyang |
| 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
Pavol Vican | 9a3a721 | 2016-03-23 10:04:00 +0100 | [diff] [blame] | 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 13 | */ |
| 14 | |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 15 | #include <ctype.h> |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 16 | #include <assert.h> |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 17 | #include "parser_yang.h" |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 18 | #include "parser_yang_lex.h" |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 19 | #include "parser.h" |
Pavol Vican | f37eeaa | 2016-02-09 20:54:06 +0100 | [diff] [blame] | 20 | #include "xpath.h" |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 21 | |
Pavol Vican | 082afd0 | 2016-10-25 12:39:15 +0200 | [diff] [blame] | 22 | static void yang_free_import(struct ly_ctx *ctx, struct lys_import *imp, uint8_t start, uint8_t size); |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 23 | static int yang_check_must(struct lys_module *module, struct lys_restr *must, uint size, struct unres_schema *unres); |
Pavol Vican | 082afd0 | 2016-10-25 12:39:15 +0200 | [diff] [blame] | 24 | static void yang_free_include(struct ly_ctx *ctx, struct lys_include *inc, uint8_t start, uint8_t size); |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 25 | static int yang_check_sub_module(struct lys_module *module, struct unres_schema *unres, struct lys_node *node); |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 26 | static void free_yang_common(struct lys_module *module, struct lys_node *node); |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 27 | static int yang_check_nodes(struct lys_module *module, struct lys_node *parent, struct lys_node *nodes, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 28 | int options, struct unres_schema *unres); |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 29 | static int yang_fill_ext_substm_index(struct lys_ext_instance_complex *ext, LY_STMT stmt, enum yytokentype keyword); |
PavolVican | f3091bf | 2017-02-19 18:27:01 +0100 | [diff] [blame] | 30 | static void yang_free_nodes(struct ly_ctx *ctx, struct lys_node *node); |
Frank Rimpler | c4db1c7 | 2017-09-12 12:56:39 +0000 | [diff] [blame] | 31 | void lys_iffeature_free(struct ly_ctx *ctx, struct lys_iffeature *iffeature, uint8_t iffeature_size, int shallow, |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 32 | void (*private_destructor)(const struct lys_node *node, void *priv)); |
Pavol Vican | 082afd0 | 2016-10-25 12:39:15 +0200 | [diff] [blame] | 33 | |
Michal Vasko | fe7e5a7 | 2016-05-02 14:49:23 +0200 | [diff] [blame] | 34 | static int |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 35 | yang_check_string(struct lys_module *module, const char **target, char *what, |
| 36 | char *where, char *value, struct lys_node *node) |
Pavol Vican | 2a06465 | 2016-02-02 22:54:34 +0100 | [diff] [blame] | 37 | { |
Pavol Vican | bf80547 | 2016-01-26 14:24:56 +0100 | [diff] [blame] | 38 | if (*target) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 39 | LOGVAL(module->ctx, LYE_TOOMANY, (node) ? LY_VLOG_LYS : LY_VLOG_NONE, node, what, where); |
Pavol Vican | bf80547 | 2016-01-26 14:24:56 +0100 | [diff] [blame] | 40 | free(value); |
| 41 | return 1; |
| 42 | } else { |
Pavol Vican | 2a06465 | 2016-02-02 22:54:34 +0100 | [diff] [blame] | 43 | *target = lydict_insert_zc(module->ctx, value); |
Pavol Vican | bf80547 | 2016-01-26 14:24:56 +0100 | [diff] [blame] | 44 | return 0; |
| 45 | } |
| 46 | } |
| 47 | |
Michal Vasko | fe7e5a7 | 2016-05-02 14:49:23 +0200 | [diff] [blame] | 48 | int |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 49 | yang_read_common(struct lys_module *module, char *value, enum yytokentype type) |
Pavol Vican | 2a06465 | 2016-02-02 22:54:34 +0100 | [diff] [blame] | 50 | { |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 51 | int ret = 0; |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 52 | |
| 53 | switch (type) { |
Pavol Vican | 2a06465 | 2016-02-02 22:54:34 +0100 | [diff] [blame] | 54 | case MODULE_KEYWORD: |
| 55 | module->name = lydict_insert_zc(module->ctx, value); |
| 56 | break; |
| 57 | case NAMESPACE_KEYWORD: |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 58 | ret = yang_check_string(module, &module->ns, "namespace", "module", value, NULL); |
Pavol Vican | 2a06465 | 2016-02-02 22:54:34 +0100 | [diff] [blame] | 59 | break; |
Pavol Vican | 1ca072c | 2016-02-03 13:03:56 +0100 | [diff] [blame] | 60 | case ORGANIZATION_KEYWORD: |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 61 | ret = yang_check_string(module, &module->org, "organization", "module", value, NULL); |
Pavol Vican | 1ca072c | 2016-02-03 13:03:56 +0100 | [diff] [blame] | 62 | break; |
| 63 | case CONTACT_KEYWORD: |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 64 | ret = yang_check_string(module, &module->contact, "contact", "module", value, NULL); |
Pavol Vican | 1ca072c | 2016-02-03 13:03:56 +0100 | [diff] [blame] | 65 | break; |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 66 | default: |
| 67 | free(value); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 68 | LOGINT(module->ctx); |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 69 | ret = EXIT_FAILURE; |
| 70 | break; |
Pavol Vican | 2a06465 | 2016-02-02 22:54:34 +0100 | [diff] [blame] | 71 | } |
| 72 | |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 73 | return ret; |
Pavol Vican | bf80547 | 2016-01-26 14:24:56 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Michal Vasko | fe7e5a7 | 2016-05-02 14:49:23 +0200 | [diff] [blame] | 76 | int |
Pavol Vican | d0b64c1 | 2016-07-15 09:56:19 +0200 | [diff] [blame] | 77 | yang_check_version(struct lys_module *module, struct lys_submodule *submodule, char *value, int repeat) |
| 78 | { |
| 79 | int ret = EXIT_SUCCESS; |
| 80 | |
| 81 | if (repeat) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 82 | LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "yang version", "module"); |
Michal Vasko | 3767fb2 | 2016-07-21 12:10:57 +0200 | [diff] [blame] | 83 | ret = EXIT_FAILURE; |
Pavol Vican | d0b64c1 | 2016-07-15 09:56:19 +0200 | [diff] [blame] | 84 | } else { |
| 85 | if (!strcmp(value, "1")) { |
| 86 | if (submodule) { |
| 87 | if (module->version > 1) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 88 | LOGVAL(module->ctx, LYE_INVER, LY_VLOG_NONE, NULL); |
Pavol Vican | d0b64c1 | 2016-07-15 09:56:19 +0200 | [diff] [blame] | 89 | ret = EXIT_FAILURE; |
| 90 | } |
Radek Krejci | 29eac3d | 2017-06-01 16:50:02 +0200 | [diff] [blame] | 91 | submodule->version = 1; |
Pavol Vican | d0b64c1 | 2016-07-15 09:56:19 +0200 | [diff] [blame] | 92 | } else { |
| 93 | module->version = 1; |
| 94 | } |
| 95 | } else if (!strcmp(value, "1.1")) { |
| 96 | if (submodule) { |
| 97 | if (module->version != 2) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 98 | LOGVAL(module->ctx, LYE_INVER, LY_VLOG_NONE, NULL); |
Pavol Vican | d0b64c1 | 2016-07-15 09:56:19 +0200 | [diff] [blame] | 99 | ret = EXIT_FAILURE; |
| 100 | } |
Radek Krejci | 29eac3d | 2017-06-01 16:50:02 +0200 | [diff] [blame] | 101 | submodule->version = 2; |
Pavol Vican | d0b64c1 | 2016-07-15 09:56:19 +0200 | [diff] [blame] | 102 | } else { |
| 103 | module->version = 2; |
| 104 | } |
| 105 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 106 | LOGVAL(module->ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "yang-version"); |
Pavol Vican | d0b64c1 | 2016-07-15 09:56:19 +0200 | [diff] [blame] | 107 | ret = EXIT_FAILURE; |
Michal Vasko | 3767fb2 | 2016-07-21 12:10:57 +0200 | [diff] [blame] | 108 | } |
Pavol Vican | d0b64c1 | 2016-07-15 09:56:19 +0200 | [diff] [blame] | 109 | } |
| 110 | free(value); |
| 111 | return ret; |
| 112 | } |
| 113 | |
| 114 | int |
Pavol Vican | e024ab7 | 2016-07-27 14:27:43 +0200 | [diff] [blame] | 115 | yang_read_prefix(struct lys_module *module, struct lys_import *imp, char *value) |
Pavol Vican | 2a06465 | 2016-02-02 22:54:34 +0100 | [diff] [blame] | 116 | { |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 117 | int ret = 0; |
Pavol Vican | bf80547 | 2016-01-26 14:24:56 +0100 | [diff] [blame] | 118 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 119 | if (!imp && lyp_check_identifier(module->ctx, value, LY_IDENT_PREFIX, module, NULL)) { |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 120 | free(value); |
| 121 | return EXIT_FAILURE; |
| 122 | } |
Pavol Vican | e024ab7 | 2016-07-27 14:27:43 +0200 | [diff] [blame] | 123 | |
| 124 | if (imp) { |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 125 | ret = yang_check_string(module, &imp->prefix, "prefix", "import", value, NULL); |
Pavol Vican | e024ab7 | 2016-07-27 14:27:43 +0200 | [diff] [blame] | 126 | } else { |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 127 | ret = yang_check_string(module, &module->prefix, "prefix", "module", value, NULL); |
Pavol Vican | 2a06465 | 2016-02-02 22:54:34 +0100 | [diff] [blame] | 128 | } |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 129 | |
Pavol Vican | bf80547 | 2016-01-26 14:24:56 +0100 | [diff] [blame] | 130 | return ret; |
| 131 | } |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 132 | |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 133 | static int |
PavolVican | 7d0b5ab | 2017-02-01 13:06:53 +0100 | [diff] [blame] | 134 | yang_fill_import(struct lys_module *module, struct lys_import *imp_old, struct lys_import *imp_new, |
| 135 | char *value, struct unres_schema *unres) |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 136 | { |
Pavol Vican | 0da132e | 2016-03-21 12:03:03 +0100 | [diff] [blame] | 137 | const char *exp; |
Radek Krejci | 4dcd339 | 2016-06-22 10:28:40 +0200 | [diff] [blame] | 138 | int rc; |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 139 | |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 140 | if (!imp_old->prefix) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 141 | LOGVAL(module->ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "prefix", "import"); |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 142 | goto error; |
| 143 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 144 | if (lyp_check_identifier(module->ctx, imp_old->prefix, LY_IDENT_PREFIX, module, NULL)) { |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 145 | goto error; |
| 146 | } |
Pavol Vican | e024ab7 | 2016-07-27 14:27:43 +0200 | [diff] [blame] | 147 | } |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 148 | memcpy(imp_new, imp_old, sizeof *imp_old); |
Pavol Vican | 0da132e | 2016-03-21 12:03:03 +0100 | [diff] [blame] | 149 | exp = lydict_insert_zc(module->ctx, value); |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 150 | rc = lyp_check_import(module, exp, imp_new); |
Pavol Vican | 0da132e | 2016-03-21 12:03:03 +0100 | [diff] [blame] | 151 | lydict_remove(module->ctx, exp); |
Radek Krejci | 4dcd339 | 2016-06-22 10:28:40 +0200 | [diff] [blame] | 152 | module->imp_size++; |
PavolVican | 7d0b5ab | 2017-02-01 13:06:53 +0100 | [diff] [blame] | 153 | if (rc || yang_check_ext_instance(module, &imp_new->ext, imp_new->ext_size, imp_new, unres)) { |
Radek Krejci | 4dcd339 | 2016-06-22 10:28:40 +0200 | [diff] [blame] | 154 | return EXIT_FAILURE; |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 155 | } |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 156 | |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 157 | return EXIT_SUCCESS; |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 158 | |
| 159 | error: |
| 160 | free(value); |
| 161 | lydict_remove(module->ctx, imp_old->dsc); |
| 162 | lydict_remove(module->ctx, imp_old->ref); |
David Sedlák | b53e670 | 2018-08-13 09:02:42 +0200 | [diff] [blame] | 163 | lydict_remove(module->ctx, imp_old->prefix); |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 164 | lys_extension_instances_free(module->ctx, imp_old->ext, imp_old->ext_size, NULL); |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 165 | return EXIT_FAILURE; |
Pavol Vican | 6eb14e8 | 2016-02-03 12:27:13 +0100 | [diff] [blame] | 166 | } |
Pavol Vican | 1ca072c | 2016-02-03 13:03:56 +0100 | [diff] [blame] | 167 | |
| 168 | int |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 169 | yang_read_description(struct lys_module *module, void *node, char *value, char *where, enum yytokentype type) |
Pavol Vican | 1ca072c | 2016-02-03 13:03:56 +0100 | [diff] [blame] | 170 | { |
| 171 | int ret; |
Pavol Vican | 9bcd7c6 | 2016-03-17 19:36:35 +0100 | [diff] [blame] | 172 | char *dsc = "description"; |
Pavol Vican | 1ca072c | 2016-02-03 13:03:56 +0100 | [diff] [blame] | 173 | |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 174 | switch (type) { |
| 175 | case MODULE_KEYWORD: |
| 176 | ret = yang_check_string(module, &module->dsc, dsc, "module", value, NULL); |
| 177 | break; |
| 178 | case REVISION_KEYWORD: |
| 179 | ret = yang_check_string(module, &((struct lys_revision *)node)->dsc, dsc, where, value, NULL); |
| 180 | break; |
| 181 | case IMPORT_KEYWORD: |
| 182 | ret = yang_check_string(module, &((struct lys_import *)node)->dsc, dsc, where, value, NULL); |
| 183 | break; |
| 184 | case INCLUDE_KEYWORD: |
| 185 | ret = yang_check_string(module, &((struct lys_include *)node)->dsc, dsc, where, value, NULL); |
| 186 | break; |
| 187 | case NODE_PRINT: |
| 188 | ret = yang_check_string(module, &((struct lys_node *)node)->dsc, dsc, where, value, node); |
| 189 | break; |
| 190 | default: |
| 191 | ret = yang_check_string(module, &((struct lys_node *)node)->dsc, dsc, where, value, NULL); |
| 192 | break; |
Pavol Vican | 1ca072c | 2016-02-03 13:03:56 +0100 | [diff] [blame] | 193 | } |
| 194 | return ret; |
| 195 | } |
| 196 | |
| 197 | int |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 198 | yang_read_reference(struct lys_module *module, void *node, char *value, char *where, enum yytokentype type) |
Pavol Vican | 1ca072c | 2016-02-03 13:03:56 +0100 | [diff] [blame] | 199 | { |
| 200 | int ret; |
Pavol Vican | f5fe966 | 2016-03-17 20:00:16 +0100 | [diff] [blame] | 201 | char *ref = "reference"; |
Pavol Vican | 1ca072c | 2016-02-03 13:03:56 +0100 | [diff] [blame] | 202 | |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 203 | switch (type) { |
| 204 | case MODULE_KEYWORD: |
| 205 | ret = yang_check_string(module, &module->ref, ref, "module", value, NULL); |
| 206 | break; |
| 207 | case REVISION_KEYWORD: |
| 208 | ret = yang_check_string(module, &((struct lys_revision *)node)->ref, ref, where, value, NULL); |
| 209 | break; |
| 210 | case IMPORT_KEYWORD: |
| 211 | ret = yang_check_string(module, &((struct lys_import *)node)->ref, ref, where, value, NULL); |
| 212 | break; |
| 213 | case INCLUDE_KEYWORD: |
| 214 | ret = yang_check_string(module, &((struct lys_include *)node)->ref, ref, where, value, NULL); |
| 215 | break; |
| 216 | case NODE_PRINT: |
| 217 | ret = yang_check_string(module, &((struct lys_node *)node)->ref, ref, where, value, node); |
| 218 | break; |
| 219 | default: |
| 220 | ret = yang_check_string(module, &((struct lys_node *)node)->ref, ref, where, value, NULL); |
| 221 | break; |
Pavol Vican | 1ca072c | 2016-02-03 13:03:56 +0100 | [diff] [blame] | 222 | } |
| 223 | return ret; |
| 224 | } |
Pavol Vican | bedff69 | 2016-02-03 14:29:17 +0100 | [diff] [blame] | 225 | |
Pavol Vican | 1eeb199 | 2016-02-09 11:10:45 +0100 | [diff] [blame] | 226 | int |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 227 | yang_fill_iffeature(struct lys_module *module, struct lys_iffeature *iffeature, void *parent, |
| 228 | char *value, struct unres_schema *unres, int parent_is_feature) |
Pavol Vican | e1354e9 | 2016-02-09 14:02:09 +0100 | [diff] [blame] | 229 | { |
| 230 | const char *exp; |
| 231 | int ret; |
| 232 | |
Michal Vasko | 97b32be | 2016-07-25 10:59:53 +0200 | [diff] [blame] | 233 | if ((module->version != 2) && ((value[0] == '(') || strchr(value, ' '))) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 234 | LOGVAL(module->ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "if-feature"); |
Michal Vasko | 97b32be | 2016-07-25 10:59:53 +0200 | [diff] [blame] | 235 | free(value); |
| 236 | return EXIT_FAILURE; |
| 237 | } |
Pavol Vican | e1354e9 | 2016-02-09 14:02:09 +0100 | [diff] [blame] | 238 | |
Michal Vasko | 56d082c | 2016-10-25 14:00:42 +0200 | [diff] [blame] | 239 | if (!(exp = transform_iffeat_schema2json(module, value))) { |
Pavol Vican | e1354e9 | 2016-02-09 14:02:09 +0100 | [diff] [blame] | 240 | free(value); |
| 241 | return EXIT_FAILURE; |
| 242 | } |
| 243 | free(value); |
| 244 | |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 245 | ret = resolve_iffeature_compile(iffeature, exp, (struct lys_node *)parent, parent_is_feature, unres); |
Pavol Vican | e1354e9 | 2016-02-09 14:02:09 +0100 | [diff] [blame] | 246 | lydict_remove(module->ctx, exp); |
Pavol Vican | e1354e9 | 2016-02-09 14:02:09 +0100 | [diff] [blame] | 247 | |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 248 | return (ret) ? EXIT_FAILURE : EXIT_SUCCESS; |
Pavol Vican | e1354e9 | 2016-02-09 14:02:09 +0100 | [diff] [blame] | 249 | } |
| 250 | |
Pavol Vican | 4fb66c9 | 2016-03-17 10:32:27 +0100 | [diff] [blame] | 251 | int |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 252 | yang_read_base(struct lys_module *module, struct lys_ident *ident, char *value, struct unres_schema *unres) |
Pavol Vican | bbdef53 | 2016-02-09 14:52:12 +0100 | [diff] [blame] | 253 | { |
| 254 | const char *exp; |
| 255 | |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 256 | exp = transform_schema2json(module, value); |
Pavol Vican | bbdef53 | 2016-02-09 14:52:12 +0100 | [diff] [blame] | 257 | free(value); |
| 258 | if (!exp) { |
| 259 | return EXIT_FAILURE; |
| 260 | } |
Pavol Vican | 4ffd0ab | 2016-08-27 16:35:04 +0200 | [diff] [blame] | 261 | |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 262 | if (unres_schema_add_str(module, unres, ident, UNRES_IDENT, exp) == -1) { |
Pavol Vican | bbdef53 | 2016-02-09 14:52:12 +0100 | [diff] [blame] | 263 | lydict_remove(module->ctx, exp); |
| 264 | return EXIT_FAILURE; |
| 265 | } |
Pavol Vican | 44dde2c | 2016-02-10 11:18:14 +0100 | [diff] [blame] | 266 | |
Pavol Vican | bbdef53 | 2016-02-09 14:52:12 +0100 | [diff] [blame] | 267 | lydict_remove(module->ctx, exp); |
| 268 | return EXIT_SUCCESS; |
| 269 | } |
Pavol Vican | f37eeaa | 2016-02-09 20:54:06 +0100 | [diff] [blame] | 270 | |
Pavol Vican | f37eeaa | 2016-02-09 20:54:06 +0100 | [diff] [blame] | 271 | int |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 272 | yang_read_message(struct lys_module *module,struct lys_restr *save,char *value, char *what, int message) |
Pavol Vican | f37eeaa | 2016-02-09 20:54:06 +0100 | [diff] [blame] | 273 | { |
| 274 | int ret; |
Pavol Vican | f37eeaa | 2016-02-09 20:54:06 +0100 | [diff] [blame] | 275 | |
Pavol Vican | dde090a | 2016-08-30 15:12:14 +0200 | [diff] [blame] | 276 | if (message == ERROR_APP_TAG_KEYWORD) { |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 277 | ret = yang_check_string(module, &save->eapptag, "error_app_tag", what, value, NULL); |
Pavol Vican | f37eeaa | 2016-02-09 20:54:06 +0100 | [diff] [blame] | 278 | } else { |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 279 | ret = yang_check_string(module, &save->emsg, "error_message", what, value, NULL); |
Pavol Vican | f37eeaa | 2016-02-09 20:54:06 +0100 | [diff] [blame] | 280 | } |
| 281 | return ret; |
| 282 | } |
Pavol Vican | b568711 | 2016-02-09 22:35:59 +0100 | [diff] [blame] | 283 | |
| 284 | int |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 285 | yang_read_presence(struct lys_module *module, struct lys_node_container *cont, char *value) |
Pavol Vican | b568711 | 2016-02-09 22:35:59 +0100 | [diff] [blame] | 286 | { |
| 287 | if (cont->presence) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 288 | LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, cont, "presence", "container"); |
Pavol Vican | b568711 | 2016-02-09 22:35:59 +0100 | [diff] [blame] | 289 | free(value); |
| 290 | return EXIT_FAILURE; |
| 291 | } else { |
| 292 | cont->presence = lydict_insert_zc(module->ctx, value); |
| 293 | return EXIT_SUCCESS; |
| 294 | } |
| 295 | } |
| 296 | |
Pavol Vican | 235dbd4 | 2016-02-10 10:34:19 +0100 | [diff] [blame] | 297 | void * |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 298 | yang_read_when(struct lys_module *module, struct lys_node *node, enum yytokentype type, char *value) |
Pavol Vican | 235dbd4 | 2016-02-10 10:34:19 +0100 | [diff] [blame] | 299 | { |
| 300 | struct lys_when *retval; |
| 301 | |
| 302 | retval = calloc(1, sizeof *retval); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 303 | LY_CHECK_ERR_RETURN(!retval, LOGMEM(module->ctx); free(value), NULL); |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 304 | retval->cond = transform_schema2json(module, value); |
Michal Vasko | 508a50d | 2016-09-07 14:50:33 +0200 | [diff] [blame] | 305 | if (!retval->cond) { |
Pavol Vican | 235dbd4 | 2016-02-10 10:34:19 +0100 | [diff] [blame] | 306 | goto error; |
| 307 | } |
| 308 | switch (type) { |
| 309 | case CONTAINER_KEYWORD: |
| 310 | if (((struct lys_node_container *)node)->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 311 | LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", "container"); |
Pavol Vican | 235dbd4 | 2016-02-10 10:34:19 +0100 | [diff] [blame] | 312 | goto error; |
| 313 | } |
| 314 | ((struct lys_node_container *)node)->when = retval; |
| 315 | break; |
Pavol Vican | db7489e | 2016-08-23 17:23:39 +0200 | [diff] [blame] | 316 | case ANYDATA_KEYWORD: |
Pavol Vican | 1f06ba8 | 2016-02-10 17:39:50 +0100 | [diff] [blame] | 317 | case ANYXML_KEYWORD: |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 318 | if (((struct lys_node_anydata *)node)->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 319 | LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", (type == ANYXML_KEYWORD) ? "anyxml" : "anydata"); |
Pavol Vican | 8c82fa8 | 2016-02-10 13:13:24 +0100 | [diff] [blame] | 320 | goto error; |
| 321 | } |
Radek Krejci | bf2abff | 2016-08-23 15:51:52 +0200 | [diff] [blame] | 322 | ((struct lys_node_anydata *)node)->when = retval; |
Pavol Vican | 8c82fa8 | 2016-02-10 13:13:24 +0100 | [diff] [blame] | 323 | break; |
Pavol Vican | 1f06ba8 | 2016-02-10 17:39:50 +0100 | [diff] [blame] | 324 | case CHOICE_KEYWORD: |
| 325 | if (((struct lys_node_choice *)node)->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 326 | LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", "choice"); |
Pavol Vican | 1f06ba8 | 2016-02-10 17:39:50 +0100 | [diff] [blame] | 327 | goto error; |
| 328 | } |
| 329 | ((struct lys_node_choice *)node)->when = retval; |
| 330 | break; |
Pavol Vican | bd09813 | 2016-02-11 10:56:49 +0100 | [diff] [blame] | 331 | case CASE_KEYWORD: |
| 332 | if (((struct lys_node_case *)node)->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 333 | LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", "case"); |
Pavol Vican | bd09813 | 2016-02-11 10:56:49 +0100 | [diff] [blame] | 334 | goto error; |
| 335 | } |
| 336 | ((struct lys_node_case *)node)->when = retval; |
| 337 | break; |
Pavol Vican | 096c6db | 2016-02-11 15:08:10 +0100 | [diff] [blame] | 338 | case LEAF_KEYWORD: |
| 339 | if (((struct lys_node_leaf *)node)->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 340 | LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", "leaf"); |
Pavol Vican | 096c6db | 2016-02-11 15:08:10 +0100 | [diff] [blame] | 341 | goto error; |
| 342 | } |
| 343 | ((struct lys_node_leaf *)node)->when = retval; |
| 344 | break; |
Pavol Vican | 339d4ad | 2016-02-12 12:49:22 +0100 | [diff] [blame] | 345 | case LEAF_LIST_KEYWORD: |
| 346 | if (((struct lys_node_leaflist *)node)->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 347 | LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", "leaflist"); |
Pavol Vican | 339d4ad | 2016-02-12 12:49:22 +0100 | [diff] [blame] | 348 | goto error; |
| 349 | } |
| 350 | ((struct lys_node_leaflist *)node)->when = retval; |
| 351 | break; |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 352 | case LIST_KEYWORD: |
| 353 | if (((struct lys_node_list *)node)->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 354 | LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", "list"); |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 355 | goto error; |
| 356 | } |
| 357 | ((struct lys_node_list *)node)->when = retval; |
| 358 | break; |
Pavol Vican | 14b1856 | 2016-03-01 16:04:29 +0100 | [diff] [blame] | 359 | case USES_KEYWORD: |
| 360 | if (((struct lys_node_uses *)node)->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 361 | LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", "uses"); |
Pavol Vican | 14b1856 | 2016-03-01 16:04:29 +0100 | [diff] [blame] | 362 | goto error; |
| 363 | } |
| 364 | ((struct lys_node_uses *)node)->when = retval; |
| 365 | break; |
Pavol Vican | 92fa0dc | 2016-03-02 14:20:39 +0100 | [diff] [blame] | 366 | case AUGMENT_KEYWORD: |
| 367 | if (((struct lys_node_augment *)node)->when) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 368 | LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_LYS, node, "when", "augment"); |
Pavol Vican | 92fa0dc | 2016-03-02 14:20:39 +0100 | [diff] [blame] | 369 | goto error; |
| 370 | } |
| 371 | ((struct lys_node_augment *)node)->when = retval; |
| 372 | break; |
PavolVican | b031708 | 2017-02-19 01:29:22 +0100 | [diff] [blame] | 373 | case EXTENSION_INSTANCE: |
| 374 | *(struct lys_when **)node = retval; |
| 375 | break; |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 376 | default: |
| 377 | goto error; |
| 378 | break; |
Pavol Vican | 235dbd4 | 2016-02-10 10:34:19 +0100 | [diff] [blame] | 379 | } |
| 380 | free(value); |
| 381 | return retval; |
| 382 | |
| 383 | error: |
| 384 | free(value); |
PavolVican | b031708 | 2017-02-19 01:29:22 +0100 | [diff] [blame] | 385 | lydict_remove(module->ctx, retval->cond); |
| 386 | free(retval); |
Pavol Vican | 235dbd4 | 2016-02-10 10:34:19 +0100 | [diff] [blame] | 387 | return NULL; |
| 388 | } |
Pavol Vican | 8c82fa8 | 2016-02-10 13:13:24 +0100 | [diff] [blame] | 389 | |
| 390 | void * |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 391 | yang_read_node(struct lys_module *module, struct lys_node *parent, struct lys_node **root, |
| 392 | char *value, int nodetype, int sizeof_struct) |
Pavol Vican | 8c82fa8 | 2016-02-10 13:13:24 +0100 | [diff] [blame] | 393 | { |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 394 | struct lys_node *node, **child; |
Pavol Vican | 8c82fa8 | 2016-02-10 13:13:24 +0100 | [diff] [blame] | 395 | |
Pavol Vican | 7cadfe7 | 2016-02-11 12:33:34 +0100 | [diff] [blame] | 396 | node = calloc(1, sizeof_struct); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 397 | LY_CHECK_ERR_RETURN(!node, LOGMEM(module->ctx); free(value), NULL); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 398 | |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 399 | LOGDBG(LY_LDGYANG, "parsing %s statement \"%s\"", strnodetype(nodetype), value); |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 400 | node->name = lydict_insert_zc(module->ctx, value); |
Pavol Vican | 7cadfe7 | 2016-02-11 12:33:34 +0100 | [diff] [blame] | 401 | node->module = module; |
Pavol Vican | 7cadfe7 | 2016-02-11 12:33:34 +0100 | [diff] [blame] | 402 | node->nodetype = nodetype; |
PavolVican | bd1d1ae | 2017-07-20 00:06:00 +0200 | [diff] [blame] | 403 | node->parent = parent; |
Pavol Vican | 7cadfe7 | 2016-02-11 12:33:34 +0100 | [diff] [blame] | 404 | |
| 405 | /* insert the node into the schema tree */ |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 406 | child = (parent) ? &parent->child : root; |
| 407 | if (*child) { |
| 408 | (*child)->prev->next = node; |
| 409 | (*child)->prev = node; |
| 410 | } else { |
| 411 | *child = node; |
| 412 | node->prev = node; |
Pavol Vican | 8c82fa8 | 2016-02-10 13:13:24 +0100 | [diff] [blame] | 413 | } |
Pavol Vican | 7cadfe7 | 2016-02-11 12:33:34 +0100 | [diff] [blame] | 414 | return node; |
Pavol Vican | 8c82fa8 | 2016-02-10 13:13:24 +0100 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | int |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 418 | yang_read_default(struct lys_module *module, void *node, char *value, enum yytokentype type) |
Pavol Vican | 096c6db | 2016-02-11 15:08:10 +0100 | [diff] [blame] | 419 | { |
| 420 | int ret; |
| 421 | |
| 422 | switch (type) { |
Pavol Vican | 339d4ad | 2016-02-12 12:49:22 +0100 | [diff] [blame] | 423 | case LEAF_KEYWORD: |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 424 | ret = yang_check_string(module, &((struct lys_node_leaf *) node)->dflt, "default", "leaf", value, node); |
Pavol Vican | 339d4ad | 2016-02-12 12:49:22 +0100 | [diff] [blame] | 425 | break; |
Pavol Vican | 0df02b0 | 2016-03-01 10:28:50 +0100 | [diff] [blame] | 426 | case TYPEDEF_KEYWORD: |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 427 | ret = yang_check_string(module, &((struct lys_tpdf *) node)->dflt, "default", "typedef", value, NULL); |
Pavol Vican | 0df02b0 | 2016-03-01 10:28:50 +0100 | [diff] [blame] | 428 | break; |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 429 | default: |
| 430 | free(value); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 431 | LOGINT(module->ctx); |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 432 | ret = EXIT_FAILURE; |
| 433 | break; |
Pavol Vican | 096c6db | 2016-02-11 15:08:10 +0100 | [diff] [blame] | 434 | } |
| 435 | return ret; |
| 436 | } |
| 437 | |
| 438 | int |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 439 | yang_read_units(struct lys_module *module, void *node, char *value, enum yytokentype type) |
Pavol Vican | 096c6db | 2016-02-11 15:08:10 +0100 | [diff] [blame] | 440 | { |
| 441 | int ret; |
| 442 | |
| 443 | switch (type) { |
Pavol Vican | 339d4ad | 2016-02-12 12:49:22 +0100 | [diff] [blame] | 444 | case LEAF_KEYWORD: |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 445 | ret = yang_check_string(module, &((struct lys_node_leaf *) node)->units, "units", "leaf", value, node); |
Pavol Vican | 339d4ad | 2016-02-12 12:49:22 +0100 | [diff] [blame] | 446 | break; |
| 447 | case LEAF_LIST_KEYWORD: |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 448 | ret = yang_check_string(module, &((struct lys_node_leaflist *) node)->units, "units", "leaflist", value, node); |
Pavol Vican | 339d4ad | 2016-02-12 12:49:22 +0100 | [diff] [blame] | 449 | break; |
Pavol Vican | 0df02b0 | 2016-03-01 10:28:50 +0100 | [diff] [blame] | 450 | case TYPEDEF_KEYWORD: |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 451 | ret = yang_check_string(module, &((struct lys_tpdf *) node)->units, "units", "typedef", value, NULL); |
Pavol Vican | 0df02b0 | 2016-03-01 10:28:50 +0100 | [diff] [blame] | 452 | break; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 453 | case ADD_KEYWORD: |
| 454 | case REPLACE_KEYWORD: |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 455 | case DELETE_KEYWORD: |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 456 | ret = yang_check_string(module, &((struct lys_deviate *) node)->units, "units", "deviate", value, NULL); |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 457 | break; |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 458 | default: |
| 459 | free(value); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 460 | LOGINT(module->ctx); |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 461 | ret = EXIT_FAILURE; |
| 462 | break; |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 463 | } |
| 464 | return ret; |
| 465 | } |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 466 | |
| 467 | int |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 468 | yang_read_key(struct lys_module *module, struct lys_node_list *list, struct unres_schema *unres) |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 469 | { |
| 470 | char *exp, *value; |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 471 | struct lys_node *node; |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 472 | |
| 473 | exp = value = (char *) list->keys; |
| 474 | while ((value = strpbrk(value, " \t\n"))) { |
| 475 | list->keys_size++; |
| 476 | while (isspace(*value)) { |
| 477 | value++; |
| 478 | } |
| 479 | } |
| 480 | list->keys_size++; |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 481 | |
| 482 | list->keys_str = lydict_insert_zc(module->ctx, exp); |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 483 | list->keys = calloc(list->keys_size, sizeof *list->keys); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 484 | LY_CHECK_ERR_RETURN(!list->keys, LOGMEM(module->ctx), EXIT_FAILURE); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 485 | |
Radek Krejci | 5c08a99 | 2016-11-02 13:30:04 +0100 | [diff] [blame] | 486 | for (node = list->parent; node && node->nodetype != LYS_GROUPING; node = lys_parent(node)); |
| 487 | if (!node && unres_schema_add_node(module, unres, list, UNRES_LIST_KEYS, NULL) == -1) { |
| 488 | return EXIT_FAILURE; |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 489 | } |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 490 | return EXIT_SUCCESS; |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | int |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 494 | yang_fill_unique(struct lys_module *module, struct lys_node_list *list, struct lys_unique *unique, char *value, struct unres_schema *unres) |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 495 | { |
| 496 | int i, j; |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 497 | char *vaux, c; |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 498 | struct unres_list_uniq *unique_info; |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 499 | |
| 500 | /* count the number of unique leafs in the value */ |
| 501 | vaux = value; |
| 502 | while ((vaux = strpbrk(vaux, " \t\n"))) { |
| 503 | unique->expr_size++; |
| 504 | while (isspace(*vaux)) { |
| 505 | vaux++; |
| 506 | } |
| 507 | } |
| 508 | unique->expr_size++; |
| 509 | unique->expr = calloc(unique->expr_size, sizeof *unique->expr); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 510 | LY_CHECK_ERR_GOTO(!unique->expr, LOGMEM(module->ctx), error); |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 511 | |
| 512 | for (i = 0; i < unique->expr_size; i++) { |
| 513 | vaux = strpbrk(value, " \t\n"); |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 514 | if (vaux) { |
| 515 | c = *vaux; |
| 516 | *vaux = '\0'; |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 517 | } |
| 518 | |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 519 | /* store token into unique structure (includes converting prefix to the module name) */ |
| 520 | unique->expr[i] = transform_schema2json(module, value); |
| 521 | if (vaux) { |
| 522 | *vaux = c; |
| 523 | } |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 524 | |
| 525 | /* check that the expression does not repeat */ |
| 526 | for (j = 0; j < i; j++) { |
| 527 | if (ly_strequal(unique->expr[j], unique->expr[i], 1)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 528 | LOGVAL(module->ctx, LYE_INARG, LY_VLOG_LYS, list, unique->expr[i], "unique"); |
| 529 | LOGVAL(module->ctx, LYE_SPEC, LY_VLOG_LYS, list, "The identifier is not unique"); |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 530 | goto error; |
| 531 | } |
| 532 | } |
| 533 | /* try to resolve leaf */ |
| 534 | if (unres) { |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 535 | unique_info = malloc(sizeof *unique_info); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 536 | LY_CHECK_ERR_GOTO(!unique_info, LOGMEM(module->ctx), error); |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 537 | unique_info->list = (struct lys_node *)list; |
| 538 | unique_info->expr = unique->expr[i]; |
| 539 | unique_info->trg_type = &unique->trg_type; |
| 540 | if (unres_schema_add_node(module, unres, unique_info, UNRES_LIST_UNIQ, NULL) == -1) { |
Pavol Vican | 18b1021 | 2016-04-11 15:41:52 +0200 | [diff] [blame] | 541 | goto error; |
| 542 | } |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 543 | } else { |
Radek Krejci | d09d1a5 | 2016-08-11 14:05:45 +0200 | [diff] [blame] | 544 | if (resolve_unique((struct lys_node *)list, unique->expr[i], &unique->trg_type)) { |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 545 | goto error; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | /* move to next token */ |
| 550 | value = vaux; |
Radek Krejci | 1a9c361 | 2017-04-24 14:49:43 +0200 | [diff] [blame] | 551 | while(value && isspace(*value)) { |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 552 | value++; |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | return EXIT_SUCCESS; |
| 557 | |
| 558 | error: |
| 559 | return EXIT_FAILURE; |
| 560 | } |
| 561 | |
| 562 | int |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 563 | yang_read_unique(struct lys_module *module, struct lys_node_list *list, struct unres_schema *unres) |
| 564 | { |
| 565 | uint8_t k; |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 566 | char *str; |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 567 | |
Michal Vasko | e59ada9 | 2018-02-22 14:05:34 +0100 | [diff] [blame] | 568 | for (k = 0; k < list->unique_size; k++) { |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 569 | str = (char *)list->unique[k].expr; |
| 570 | if (yang_fill_unique(module, list, &list->unique[k], str, unres)) { |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 571 | goto error; |
| 572 | } |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 573 | free(str); |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 574 | } |
| 575 | return EXIT_SUCCESS; |
| 576 | |
| 577 | error: |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 578 | free(str); |
Pavol Vican | 5de3349 | 2016-02-22 14:03:24 +0100 | [diff] [blame] | 579 | return EXIT_FAILURE; |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 580 | } |
| 581 | |
Pavol Vican | 07f220f | 2016-09-02 13:04:37 +0200 | [diff] [blame] | 582 | int |
Pavol Vican | 81344ac | 2016-09-02 14:23:06 +0200 | [diff] [blame] | 583 | yang_read_leafref_path(struct lys_module *module, struct yang_type *stype, char *value) |
Pavol Vican | 1ff0e22 | 2016-02-26 12:27:01 +0100 | [diff] [blame] | 584 | { |
Pavol Vican | 81344ac | 2016-09-02 14:23:06 +0200 | [diff] [blame] | 585 | if (stype->base && (stype->base != LY_TYPE_LEAFREF)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 586 | LOGVAL(module->ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "require-instance"); |
Pavol Vican | 81344ac | 2016-09-02 14:23:06 +0200 | [diff] [blame] | 587 | goto error; |
Pavol Vican | 1ff0e22 | 2016-02-26 12:27:01 +0100 | [diff] [blame] | 588 | } |
Pavol Vican | 81344ac | 2016-09-02 14:23:06 +0200 | [diff] [blame] | 589 | if (stype->type->info.lref.path) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 590 | LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "path", "type"); |
Pavol Vican | 81344ac | 2016-09-02 14:23:06 +0200 | [diff] [blame] | 591 | goto error; |
| 592 | } |
| 593 | stype->type->info.lref.path = lydict_insert_zc(module->ctx, value); |
| 594 | stype->base = LY_TYPE_LEAFREF; |
| 595 | return EXIT_SUCCESS; |
| 596 | |
| 597 | error: |
| 598 | free(value); |
| 599 | return EXIT_FAILURE; |
| 600 | } |
| 601 | |
| 602 | int |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 603 | yang_read_require_instance(struct ly_ctx *ctx, struct yang_type *stype, int req) |
Pavol Vican | 81344ac | 2016-09-02 14:23:06 +0200 | [diff] [blame] | 604 | { |
| 605 | if (stype->base && (stype->base != LY_TYPE_LEAFREF)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 606 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "require-instance"); |
Pavol Vican | 81344ac | 2016-09-02 14:23:06 +0200 | [diff] [blame] | 607 | return EXIT_FAILURE; |
| 608 | } |
| 609 | if (stype->type->info.lref.req) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 610 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "require-instance", "type"); |
Pavol Vican | 81344ac | 2016-09-02 14:23:06 +0200 | [diff] [blame] | 611 | return EXIT_FAILURE; |
| 612 | } |
| 613 | stype->type->info.lref.req = req; |
| 614 | stype->base = LY_TYPE_LEAFREF; |
| 615 | return EXIT_SUCCESS; |
| 616 | } |
| 617 | |
| 618 | int |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 619 | yang_check_type(struct lys_module *module, struct lys_node *parent, struct yang_type *typ, struct lys_type *type, int tpdftype, struct unres_schema *unres) |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 620 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 621 | struct ly_ctx *ctx = module->ctx; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 622 | int rc, ret = -1; |
| 623 | unsigned int i, j; |
Pavol Vican | 81344ac | 2016-09-02 14:23:06 +0200 | [diff] [blame] | 624 | int8_t req; |
Michal Vasko | 568b195 | 2018-01-30 15:53:30 +0100 | [diff] [blame] | 625 | const char *name, *value, *module_name = NULL; |
Pavol Vican | cf2af4d | 2016-12-21 14:13:06 +0100 | [diff] [blame] | 626 | LY_DATA_TYPE base = 0, base_tmp; |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 627 | struct lys_node *siter; |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 628 | struct lys_type *dertype; |
| 629 | struct lys_type_enum *enms_sc = NULL; |
| 630 | struct lys_type_bit *bits_sc = NULL; |
| 631 | struct lys_type_bit bit_tmp; |
Pavol Vican | cf2af4d | 2016-12-21 14:13:06 +0100 | [diff] [blame] | 632 | struct yang_type *yang; |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 633 | |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 634 | value = transform_schema2json(module, typ->name); |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 635 | if (!value) { |
| 636 | goto error; |
| 637 | } |
| 638 | |
| 639 | i = parse_identifier(value); |
| 640 | if (i < 1) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 641 | LOGVAL(ctx, LYE_INCHAR, LY_VLOG_NONE, NULL, value[-i], &value[-i]); |
| 642 | lydict_remove(ctx, value); |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 643 | goto error; |
| 644 | } |
Radek Krejci | 408ab2f | 2016-06-06 15:27:10 +0200 | [diff] [blame] | 645 | /* module name */ |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 646 | name = value; |
| 647 | if (value[i]) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 648 | module_name = lydict_insert(ctx, value, i); |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 649 | name += i; |
| 650 | if ((name[0] != ':') || (parse_identifier(name + 1) < 1)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 651 | LOGVAL(ctx, LYE_INCHAR, LY_VLOG_NONE, NULL, name[0], name); |
| 652 | lydict_remove(ctx, module_name); |
| 653 | lydict_remove(ctx, value); |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 654 | goto error; |
| 655 | } |
| 656 | ++name; |
| 657 | } |
| 658 | |
Michal Vasko | 568b195 | 2018-01-30 15:53:30 +0100 | [diff] [blame] | 659 | rc = resolve_superior_type(name, module_name, module, parent, &type->der); |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 660 | if (rc == -1) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 661 | LOGVAL(ctx, LYE_INMOD, LY_VLOG_NONE, NULL, module_name); |
| 662 | lydict_remove(ctx, module_name); |
| 663 | lydict_remove(ctx, value); |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 664 | goto error; |
| 665 | |
Michal Vasko | 01c6fd2 | 2016-05-20 11:43:05 +0200 | [diff] [blame] | 666 | /* the type could not be resolved or it was resolved to an unresolved typedef or leafref */ |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 667 | } else if (rc == EXIT_FAILURE) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 668 | LOGVAL(ctx, LYE_NORESOLV, LY_VLOG_NONE, NULL, "type", name); |
| 669 | lydict_remove(ctx, module_name); |
| 670 | lydict_remove(ctx, value); |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 671 | ret = EXIT_FAILURE; |
| 672 | goto error; |
| 673 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 674 | lydict_remove(ctx, module_name); |
| 675 | lydict_remove(ctx, value); |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 676 | |
Michal Vasko | 101658e | 2018-06-05 15:05:54 +0200 | [diff] [blame] | 677 | if (type->value_flags & LY_VALUE_UNRESGRP) { |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 678 | /* resolved type in grouping, decrease the grouping's nacm number to indicate that one less |
Michal Vasko | 70bf8e5 | 2018-03-26 11:32:33 +0200 | [diff] [blame] | 679 | * unresolved item left inside the grouping, LYTYPE_GRP used as a flag for types inside a grouping. */ |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 680 | for (siter = parent; siter && (siter->nodetype != LYS_GROUPING); siter = lys_parent(siter)); |
| 681 | if (siter) { |
Radek Krejci | 93def38 | 2017-05-24 15:33:48 +0200 | [diff] [blame] | 682 | assert(((struct lys_node_grp *)siter)->unres_count); |
| 683 | ((struct lys_node_grp *)siter)->unres_count--; |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 684 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 685 | LOGINT(ctx); |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 686 | goto error; |
| 687 | } |
Michal Vasko | 101658e | 2018-06-05 15:05:54 +0200 | [diff] [blame] | 688 | type->value_flags &= ~LY_VALUE_UNRESGRP; |
Radek Krejci | c13db38 | 2016-08-16 10:52:42 +0200 | [diff] [blame] | 689 | } |
Pavol Vican | fdab9f9 | 2016-09-07 15:23:27 +0200 | [diff] [blame] | 690 | |
| 691 | /* check status */ |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 692 | if (lyp_check_status(type->parent->flags, type->parent->module, type->parent->name, |
| 693 | type->der->flags, type->der->module, type->der->name, parent)) { |
Pavol Vican | fdab9f9 | 2016-09-07 15:23:27 +0200 | [diff] [blame] | 694 | goto error; |
| 695 | } |
| 696 | |
Pavol Vican | 8bd72e4 | 2016-08-29 09:53:05 +0200 | [diff] [blame] | 697 | base = typ->base; |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 698 | base_tmp = type->base; |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 699 | type->base = type->der->type.base; |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 700 | if (base == 0) { |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 701 | base = type->der->type.base; |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 702 | } |
| 703 | switch (base) { |
| 704 | case LY_TYPE_STRING: |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 705 | if (type->base == LY_TYPE_BINARY) { |
| 706 | if (type->info.str.pat_count) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 707 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Binary type could not include pattern statement."); |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 708 | goto error; |
| 709 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 710 | type->info.binary.length = type->info.str.length; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 711 | if (type->info.binary.length && lyp_check_length_range(ctx, type->info.binary.length->expr, type)) { |
| 712 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, type->info.binary.length->expr, "length"); |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 713 | goto error; |
| 714 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 715 | } else if (type->base == LY_TYPE_STRING) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 716 | if (type->info.str.length && lyp_check_length_range(ctx, type->info.str.length->expr, type)) { |
| 717 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, type->info.str.length->expr, "length"); |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 718 | goto error; |
| 719 | } |
Pavol Vican | aff5c80 | 2016-02-24 15:56:45 +0100 | [diff] [blame] | 720 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 721 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name); |
Pavol Vican | aff5c80 | 2016-02-24 15:56:45 +0100 | [diff] [blame] | 722 | goto error; |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 723 | } |
Pavol Vican | aff5c80 | 2016-02-24 15:56:45 +0100 | [diff] [blame] | 724 | break; |
| 725 | case LY_TYPE_DEC64: |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 726 | if (type->base == LY_TYPE_DEC64) { |
Pavol Vican | 07ea68d | 2016-02-25 12:01:37 +0100 | [diff] [blame] | 727 | /* mandatory sub-statement(s) check */ |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 728 | if (!type->info.dec64.dig && !type->der->type.der) { |
Pavol Vican | 07ea68d | 2016-02-25 12:01:37 +0100 | [diff] [blame] | 729 | /* decimal64 type directly derived from built-in type requires fraction-digits */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 730 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "fraction-digits", "type"); |
Pavol Vican | 07ea68d | 2016-02-25 12:01:37 +0100 | [diff] [blame] | 731 | goto error; |
| 732 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 733 | if (type->info.dec64.dig && type->der->type.der) { |
Pavol Vican | 07ea68d | 2016-02-25 12:01:37 +0100 | [diff] [blame] | 734 | /* type is not directly derived from buit-in type and fraction-digits statement is prohibited */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 735 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "fraction-digits"); |
Pavol Vican | 07ea68d | 2016-02-25 12:01:37 +0100 | [diff] [blame] | 736 | goto error; |
| 737 | } |
Radek Krejci | 4800f65 | 2016-09-08 14:02:52 +0200 | [diff] [blame] | 738 | |
| 739 | /* copy fraction-digits specification from parent type for easier internal use */ |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 740 | if (type->der->type.der) { |
| 741 | type->info.dec64.dig = type->der->type.info.dec64.dig; |
| 742 | type->info.dec64.div = type->der->type.info.dec64.div; |
Radek Krejci | 4800f65 | 2016-09-08 14:02:52 +0200 | [diff] [blame] | 743 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 744 | if (type->info.dec64.range && lyp_check_length_range(ctx, type->info.dec64.range->expr, type)) { |
| 745 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, type->info.dec64.range->expr, "range"); |
Pavol Vican | 3c8ee2b | 2016-09-29 13:18:13 +0200 | [diff] [blame] | 746 | goto error; |
| 747 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 748 | } else if (type->base >= LY_TYPE_INT8 && type->base <=LY_TYPE_UINT64) { |
| 749 | if (type->info.dec64.dig) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 750 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Numerical type could not include fraction statement."); |
Pavol Vican | aff5c80 | 2016-02-24 15:56:45 +0100 | [diff] [blame] | 751 | goto error; |
| 752 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 753 | type->info.num.range = type->info.dec64.range; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 754 | if (type->info.num.range && lyp_check_length_range(ctx, type->info.num.range->expr, type)) { |
| 755 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, type->info.num.range->expr, "range"); |
Pavol Vican | aff5c80 | 2016-02-24 15:56:45 +0100 | [diff] [blame] | 756 | goto error; |
| 757 | } |
| 758 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 759 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name); |
Pavol Vican | aff5c80 | 2016-02-24 15:56:45 +0100 | [diff] [blame] | 760 | goto error; |
| 761 | } |
| 762 | break; |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 763 | case LY_TYPE_ENUM: |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 764 | if (type->base != LY_TYPE_ENUM) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 765 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name); |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 766 | goto error; |
| 767 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 768 | dertype = &type->der->type; |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 769 | |
| 770 | if (!dertype->der) { |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 771 | if (!type->info.enums.count) { |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 772 | /* type is derived directly from buit-in enumeartion type and enum statement is required */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 773 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "enum", "type"); |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 774 | goto error; |
| 775 | } |
| 776 | } else { |
| 777 | for (; !dertype->info.enums.count; dertype = &dertype->der->type); |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 778 | if (module->version < 2 && type->info.enums.count) { |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 779 | /* type is not directly derived from built-in enumeration type and enum statement is prohibited |
| 780 | * in YANG 1.0, since YANG 1.1 enum statements can be used to restrict the base enumeration type */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 781 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "enum"); |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 782 | goto error; |
| 783 | } |
| 784 | |
| 785 | /* restricted enumeration type - the name MUST be used in the base type */ |
| 786 | enms_sc = dertype->info.enums.enm; |
Michal Vasko | e59ada9 | 2018-02-22 14:05:34 +0100 | [diff] [blame] | 787 | for (i = 0; i < type->info.enums.count; i++) { |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 788 | for (j = 0; j < dertype->info.enums.count; j++) { |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 789 | if (ly_strequal(enms_sc[j].name, type->info.enums.enm[i].name, 1)) { |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 790 | break; |
| 791 | } |
| 792 | } |
| 793 | if (j == dertype->info.enums.count) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 794 | LOGVAL(ctx, LYE_ENUM_INNAME, LY_VLOG_NONE, NULL, type->info.enums.enm[i].name); |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 795 | goto error; |
| 796 | } |
| 797 | |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 798 | if (type->info.enums.enm[i].flags & LYS_AUTOASSIGNED) { |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 799 | /* automatically assign value from base type */ |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 800 | type->info.enums.enm[i].value = enms_sc[j].value; |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 801 | } else { |
| 802 | /* check that the assigned value corresponds to the original |
| 803 | * value of the enum in the base type */ |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 804 | if (type->info.enums.enm[i].value != enms_sc[j].value) { |
| 805 | /* type->info.enums.enm[i].value - assigned value in restricted enum |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 806 | * enms_sc[j].value - value assigned to the corresponding enum (detected above) in base type */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 807 | LOGVAL(ctx, LYE_ENUM_INVAL, LY_VLOG_NONE, NULL, type->info.enums.enm[i].value, |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 808 | type->info.enums.enm[i].name, enms_sc[j].value); |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 809 | goto error; |
| 810 | } |
| 811 | } |
| 812 | } |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 813 | } |
Pavol Vican | 1ff0e22 | 2016-02-26 12:27:01 +0100 | [diff] [blame] | 814 | break; |
Pavol Vican | 03a5944 | 2016-03-21 15:23:45 +0100 | [diff] [blame] | 815 | case LY_TYPE_BITS: |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 816 | if (type->base != LY_TYPE_BITS) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 817 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name); |
Pavol Vican | 03a5944 | 2016-03-21 15:23:45 +0100 | [diff] [blame] | 818 | goto error; |
| 819 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 820 | dertype = &type->der->type; |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 821 | |
| 822 | if (!dertype->der) { |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 823 | if (!type->info.bits.count) { |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 824 | /* type is derived directly from buit-in bits type and bit statement is required */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 825 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "bit", "type"); |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 826 | goto error; |
| 827 | } |
| 828 | } else { |
| 829 | for (; !dertype->info.enums.count; dertype = &dertype->der->type); |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 830 | if (module->version < 2 && type->info.bits.count) { |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 831 | /* type is not directly derived from buit-in bits type and bit statement is prohibited, |
| 832 | * since YANG 1.1 the bit statements can be used to restrict the base bits type */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 833 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "bit"); |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 834 | goto error; |
| 835 | } |
| 836 | |
| 837 | bits_sc = dertype->info.bits.bit; |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 838 | for (i = 0; i < type->info.bits.count; i++) { |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 839 | for (j = 0; j < dertype->info.bits.count; j++) { |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 840 | if (ly_strequal(bits_sc[j].name, type->info.bits.bit[i].name, 1)) { |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 841 | break; |
| 842 | } |
| 843 | } |
| 844 | if (j == dertype->info.bits.count) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 845 | LOGVAL(ctx, LYE_BITS_INNAME, LY_VLOG_NONE, NULL, type->info.bits.bit[i].name); |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 846 | goto error; |
| 847 | } |
| 848 | |
| 849 | /* restricted bits type */ |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 850 | if (type->info.bits.bit[i].flags & LYS_AUTOASSIGNED) { |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 851 | /* automatically assign position from base type */ |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 852 | type->info.bits.bit[i].pos = bits_sc[j].pos; |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 853 | } else { |
| 854 | /* check that the assigned position corresponds to the original |
| 855 | * position of the bit in the base type */ |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 856 | if (type->info.bits.bit[i].pos != bits_sc[j].pos) { |
| 857 | /* type->info.bits.bit[i].pos - assigned position in restricted bits |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 858 | * bits_sc[j].pos - position assigned to the corresponding bit (detected above) in base type */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 859 | LOGVAL(ctx, LYE_BITS_INVAL, LY_VLOG_NONE, NULL, type->info.bits.bit[i].pos, |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 860 | type->info.bits.bit[i].name, bits_sc[j].pos); |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 861 | goto error; |
| 862 | } |
| 863 | } |
| 864 | } |
Pavol Vican | 03a5944 | 2016-03-21 15:23:45 +0100 | [diff] [blame] | 865 | } |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 866 | |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 867 | for (i = type->info.bits.count; i > 0; i--) { |
| 868 | j = i - 1; |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 869 | |
| 870 | /* keep them ordered by position */ |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 871 | while (j && type->info.bits.bit[j - 1].pos > type->info.bits.bit[j].pos) { |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 872 | /* switch them */ |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 873 | memcpy(&bit_tmp, &type->info.bits.bit[j], sizeof bit_tmp); |
| 874 | memcpy(&type->info.bits.bit[j], &type->info.bits.bit[j - 1], sizeof bit_tmp); |
| 875 | memcpy(&type->info.bits.bit[j - 1], &bit_tmp, sizeof bit_tmp); |
Pavol Vican | 8ad2e0d | 2016-08-09 12:56:19 +0200 | [diff] [blame] | 876 | j--; |
| 877 | } |
Pavol Vican | 03a5944 | 2016-03-21 15:23:45 +0100 | [diff] [blame] | 878 | } |
| 879 | break; |
Pavol Vican | 1ff0e22 | 2016-02-26 12:27:01 +0100 | [diff] [blame] | 880 | case LY_TYPE_LEAFREF: |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 881 | if (type->base == LY_TYPE_INST) { |
| 882 | if (type->info.lref.path) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 883 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "path"); |
Pavol Vican | 1ff0e22 | 2016-02-26 12:27:01 +0100 | [diff] [blame] | 884 | goto error; |
| 885 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 886 | if ((req = type->info.lref.req)) { |
| 887 | type->info.inst.req = req; |
Pavol Vican | 81344ac | 2016-09-02 14:23:06 +0200 | [diff] [blame] | 888 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 889 | } else if (type->base == LY_TYPE_LEAFREF) { |
Pavol Vican | 92626d7 | 2016-09-21 09:36:09 +0200 | [diff] [blame] | 890 | /* require-instance only YANG 1.1 */ |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 891 | if (type->info.lref.req && (module->version < 2)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 892 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "require-instance"); |
Pavol Vican | 92626d7 | 2016-09-21 09:36:09 +0200 | [diff] [blame] | 893 | goto error; |
| 894 | } |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 895 | /* flag resolving for later use */ |
| 896 | if (!tpdftype) { |
| 897 | for (siter = parent; siter && siter->nodetype != LYS_GROUPING; siter = lys_parent(siter)); |
| 898 | if (siter) { |
| 899 | /* just a flag - do not resolve */ |
| 900 | tpdftype = 1; |
| 901 | } |
| 902 | } |
| 903 | |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 904 | if (type->info.lref.path) { |
| 905 | if (type->der->type.der) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 906 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "path"); |
Pavol Vican | 894ee0f | 2016-08-30 15:29:46 +0200 | [diff] [blame] | 907 | goto error; |
| 908 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 909 | value = type->info.lref.path; |
Pavol Vican | 191613a | 2016-02-26 16:21:32 +0100 | [diff] [blame] | 910 | /* store in the JSON format */ |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 911 | type->info.lref.path = transform_schema2json(module, value); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 912 | lydict_remove(ctx, value); |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 913 | if (!type->info.lref.path) { |
Pavol Vican | 191613a | 2016-02-26 16:21:32 +0100 | [diff] [blame] | 914 | goto error; |
| 915 | } |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 916 | /* try to resolve leafref path only when this is instantiated |
| 917 | * leaf, so it is not: |
| 918 | * - typedef's type, |
| 919 | * - in grouping definition, |
| 920 | * - just instantiated in a grouping definition, |
| 921 | * because in those cases the nodes referenced in path might not be present |
| 922 | * and it is not a bug. */ |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 923 | if (!tpdftype && unres_schema_add_node(module, unres, type, UNRES_TYPE_LEAFREF, parent) == -1) { |
Pavol Vican | 191613a | 2016-02-26 16:21:32 +0100 | [diff] [blame] | 924 | goto error; |
| 925 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 926 | } else if (!type->der->type.der) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 927 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "path", "type"); |
Pavol Vican | 191613a | 2016-02-26 16:21:32 +0100 | [diff] [blame] | 928 | goto error; |
Michal Vasko | 01c6fd2 | 2016-05-20 11:43:05 +0200 | [diff] [blame] | 929 | } else { |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 930 | /* copy leafref definition into the derived type */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 931 | type->info.lref.path = lydict_insert(ctx, type->der->type.info.lref.path, 0); |
Radek Krejci | 3a5501d | 2016-07-18 22:03:34 +0200 | [diff] [blame] | 932 | /* and resolve the path at the place we are (if not in grouping/typedef) */ |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 933 | if (!tpdftype && unres_schema_add_node(module, unres, type, UNRES_TYPE_LEAFREF, parent) == -1) { |
Michal Vasko | 01c6fd2 | 2016-05-20 11:43:05 +0200 | [diff] [blame] | 934 | goto error; |
| 935 | } |
Pavol Vican | 191613a | 2016-02-26 16:21:32 +0100 | [diff] [blame] | 936 | } |
Pavol Vican | 1ff0e22 | 2016-02-26 12:27:01 +0100 | [diff] [blame] | 937 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 938 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name); |
Pavol Vican | 1ff0e22 | 2016-02-26 12:27:01 +0100 | [diff] [blame] | 939 | goto error; |
| 940 | } |
| 941 | break; |
| 942 | case LY_TYPE_IDENT: |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 943 | if (type->base != LY_TYPE_IDENT) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 944 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name); |
Pavol Vican | 1ff0e22 | 2016-02-26 12:27:01 +0100 | [diff] [blame] | 945 | goto error; |
| 946 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 947 | if (type->der->type.der) { |
| 948 | if (type->info.ident.ref) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 949 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "base"); |
Pavol Vican | 07f220f | 2016-09-02 13:04:37 +0200 | [diff] [blame] | 950 | goto error; |
| 951 | } |
| 952 | } else { |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 953 | if (!type->info.ident.ref) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 954 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "base", "type"); |
Pavol Vican | 07f220f | 2016-09-02 13:04:37 +0200 | [diff] [blame] | 955 | goto error; |
| 956 | } |
| 957 | } |
Pavol Vican | 1ff0e22 | 2016-02-26 12:27:01 +0100 | [diff] [blame] | 958 | break; |
Pavol Vican | a4f045a | 2016-02-29 15:01:20 +0100 | [diff] [blame] | 959 | case LY_TYPE_UNION: |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 960 | if (type->base != LY_TYPE_UNION) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 961 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name); |
Pavol Vican | a4f045a | 2016-02-29 15:01:20 +0100 | [diff] [blame] | 962 | goto error; |
| 963 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 964 | if (!type->info.uni.types) { |
| 965 | if (type->der->type.der) { |
Pavol Vican | a4f045a | 2016-02-29 15:01:20 +0100 | [diff] [blame] | 966 | /* this is just a derived type with no additional type specified/required */ |
Michal Vasko | b6ab50c | 2018-03-08 13:46:10 +0100 | [diff] [blame] | 967 | assert(type->der->type.base == LY_TYPE_UNION); |
| 968 | type->info.uni.has_ptr_type = type->der->type.info.uni.has_ptr_type; |
Pavol Vican | a4f045a | 2016-02-29 15:01:20 +0100 | [diff] [blame] | 969 | break; |
| 970 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 971 | LOGVAL(ctx, LYE_MISSCHILDSTMT, LY_VLOG_NONE, NULL, "type", "(union) type"); |
Pavol Vican | a4f045a | 2016-02-29 15:01:20 +0100 | [diff] [blame] | 972 | goto error; |
| 973 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 974 | for (i = 0; i < type->info.uni.count; i++) { |
PavolVican | 811f03b | 2016-12-29 23:03:20 +0100 | [diff] [blame] | 975 | dertype = &type->info.uni.types[i]; |
Michal Vasko | 70bf8e5 | 2018-03-26 11:32:33 +0200 | [diff] [blame] | 976 | if (dertype->base == LY_TYPE_DER) { |
Pavol Vican | cf2af4d | 2016-12-21 14:13:06 +0100 | [diff] [blame] | 977 | yang = (struct yang_type *)dertype->der; |
| 978 | dertype->der = NULL; |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 979 | dertype->parent = type->parent; |
| 980 | if (yang_check_type(module, parent, yang, dertype, tpdftype, unres)) { |
Pavol Vican | cf2af4d | 2016-12-21 14:13:06 +0100 | [diff] [blame] | 981 | dertype->der = (struct lys_tpdf *)yang; |
| 982 | ret = EXIT_FAILURE; |
PavolVican | 811f03b | 2016-12-29 23:03:20 +0100 | [diff] [blame] | 983 | type->base = base_tmp; |
Pavol Vican | cf2af4d | 2016-12-21 14:13:06 +0100 | [diff] [blame] | 984 | base = 0; |
| 985 | goto error; |
| 986 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 987 | lydict_remove(ctx, yang->name); |
Pavol Vican | cf2af4d | 2016-12-21 14:13:06 +0100 | [diff] [blame] | 988 | free(yang); |
| 989 | } |
Pavol Vican | a4f045a | 2016-02-29 15:01:20 +0100 | [diff] [blame] | 990 | } |
Pavol Vican | 8e00e7a | 2016-09-20 11:07:48 +0200 | [diff] [blame] | 991 | if (module->version < 2) { |
Pavol Vican | cf2af4d | 2016-12-21 14:13:06 +0100 | [diff] [blame] | 992 | if (dertype->base == LY_TYPE_EMPTY) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 993 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, "empty", typ->name); |
Pavol Vican | 8e00e7a | 2016-09-20 11:07:48 +0200 | [diff] [blame] | 994 | goto error; |
Pavol Vican | cf2af4d | 2016-12-21 14:13:06 +0100 | [diff] [blame] | 995 | } else if (dertype->base == LY_TYPE_LEAFREF) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 996 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, "leafref", typ->name); |
Pavol Vican | 8e00e7a | 2016-09-20 11:07:48 +0200 | [diff] [blame] | 997 | goto error; |
| 998 | } |
Pavol Vican | a4f045a | 2016-02-29 15:01:20 +0100 | [diff] [blame] | 999 | } |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1000 | if ((dertype->base == LY_TYPE_INST) || (dertype->base == LY_TYPE_LEAFREF) |
| 1001 | || ((dertype->base == LY_TYPE_UNION) && dertype->info.uni.has_ptr_type)) { |
Radek Krejci | a726f9b | 2017-02-28 09:56:44 +0100 | [diff] [blame] | 1002 | type->info.uni.has_ptr_type = 1; |
Michal Vasko | e3886bb | 2017-01-02 11:33:28 +0100 | [diff] [blame] | 1003 | } |
Pavol Vican | a4f045a | 2016-02-29 15:01:20 +0100 | [diff] [blame] | 1004 | } |
| 1005 | break; |
Pavol Vican | a182796 | 2016-02-29 15:39:42 +0100 | [diff] [blame] | 1006 | |
| 1007 | default: |
| 1008 | if (base >= LY_TYPE_BINARY && base <= LY_TYPE_UINT64) { |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 1009 | if (type->base != base) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1010 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid restriction in type \"%s\".", type->parent->name); |
Pavol Vican | a182796 | 2016-02-29 15:39:42 +0100 | [diff] [blame] | 1011 | goto error; |
| 1012 | } |
| 1013 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1014 | LOGINT(ctx); |
Pavol Vican | a182796 | 2016-02-29 15:39:42 +0100 | [diff] [blame] | 1015 | goto error; |
| 1016 | } |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1017 | } |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 1018 | |
| 1019 | /* if derived type has extension, which need validate data */ |
| 1020 | dertype = &type->der->type; |
| 1021 | while (dertype->der) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 1022 | if (dertype->parent->flags & LYS_VALID_EXT) { |
| 1023 | type->parent->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 1024 | } |
| 1025 | dertype = &dertype->der->type; |
| 1026 | } |
| 1027 | |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1028 | return EXIT_SUCCESS; |
| 1029 | |
| 1030 | error: |
Pavol Vican | 8bd72e4 | 2016-08-29 09:53:05 +0200 | [diff] [blame] | 1031 | if (base) { |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 1032 | type->base = base_tmp; |
Pavol Vican | 8bd72e4 | 2016-08-29 09:53:05 +0200 | [diff] [blame] | 1033 | } |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1034 | return ret; |
| 1035 | } |
| 1036 | |
Pavol Vican | cf2af4d | 2016-12-21 14:13:06 +0100 | [diff] [blame] | 1037 | void |
| 1038 | yang_free_type_union(struct ly_ctx *ctx, struct lys_type *type) |
| 1039 | { |
| 1040 | struct lys_type *stype; |
| 1041 | struct yang_type *yang; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 1042 | unsigned int i; |
Pavol Vican | cf2af4d | 2016-12-21 14:13:06 +0100 | [diff] [blame] | 1043 | |
| 1044 | for (i = 0; i < type->info.uni.count; ++i) { |
| 1045 | stype = &type->info.uni.types[i]; |
Michal Vasko | 70bf8e5 | 2018-03-26 11:32:33 +0200 | [diff] [blame] | 1046 | if (stype->base == LY_TYPE_DER) { |
Pavol Vican | cf2af4d | 2016-12-21 14:13:06 +0100 | [diff] [blame] | 1047 | yang = (struct yang_type *)stype->der; |
| 1048 | stype->base = yang->base; |
| 1049 | lydict_remove(ctx, yang->name); |
| 1050 | free(yang); |
| 1051 | } else if (stype->base == LY_TYPE_UNION) { |
| 1052 | yang_free_type_union(ctx, stype); |
| 1053 | } |
| 1054 | } |
| 1055 | } |
| 1056 | |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1057 | void * |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1058 | yang_read_type(struct ly_ctx *ctx, void *parent, char *value, enum yytokentype type) |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1059 | { |
| 1060 | struct yang_type *typ; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1061 | struct lys_deviate *dev; |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1062 | |
Pavol Vican | d01d8ae | 2016-03-01 10:45:59 +0100 | [diff] [blame] | 1063 | typ = calloc(1, sizeof *typ); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1064 | LY_CHECK_ERR_RETURN(!typ, LOGMEM(ctx), NULL); |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1065 | |
| 1066 | typ->flags = LY_YANG_STRUCTURE_FLAG; |
| 1067 | switch (type) { |
| 1068 | case LEAF_KEYWORD: |
Pavol Vican | 85427f0 | 2016-09-26 15:21:05 +0200 | [diff] [blame] | 1069 | if (((struct lys_node_leaf *)parent)->type.der) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1070 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, parent, "type", "leaf"); |
Pavol Vican | 85427f0 | 2016-09-26 15:21:05 +0200 | [diff] [blame] | 1071 | goto error; |
| 1072 | } |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1073 | ((struct lys_node_leaf *)parent)->type.der = (struct lys_tpdf *)typ; |
| 1074 | ((struct lys_node_leaf *)parent)->type.parent = (struct lys_tpdf *)parent; |
| 1075 | typ->type = &((struct lys_node_leaf *)parent)->type; |
| 1076 | break; |
Pavol Vican | a55992a | 2016-03-01 13:37:17 +0100 | [diff] [blame] | 1077 | case LEAF_LIST_KEYWORD: |
Pavol Vican | 85427f0 | 2016-09-26 15:21:05 +0200 | [diff] [blame] | 1078 | if (((struct lys_node_leaflist *)parent)->type.der) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1079 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_LYS, parent, "type", "leaf-list"); |
Pavol Vican | 85427f0 | 2016-09-26 15:21:05 +0200 | [diff] [blame] | 1080 | goto error; |
| 1081 | } |
Pavol Vican | a55992a | 2016-03-01 13:37:17 +0100 | [diff] [blame] | 1082 | ((struct lys_node_leaflist *)parent)->type.der = (struct lys_tpdf *)typ; |
| 1083 | ((struct lys_node_leaflist *)parent)->type.parent = (struct lys_tpdf *)parent; |
| 1084 | typ->type = &((struct lys_node_leaflist *)parent)->type; |
| 1085 | break; |
Pavol Vican | a4f045a | 2016-02-29 15:01:20 +0100 | [diff] [blame] | 1086 | case UNION_KEYWORD: |
| 1087 | ((struct lys_type *)parent)->der = (struct lys_tpdf *)typ; |
| 1088 | typ->type = (struct lys_type *)parent; |
| 1089 | break; |
Pavol Vican | 0df02b0 | 2016-03-01 10:28:50 +0100 | [diff] [blame] | 1090 | case TYPEDEF_KEYWORD: |
Pavol Vican | 85427f0 | 2016-09-26 15:21:05 +0200 | [diff] [blame] | 1091 | if (((struct lys_tpdf *)parent)->type.der) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1092 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "type", "typedef"); |
Pavol Vican | 85427f0 | 2016-09-26 15:21:05 +0200 | [diff] [blame] | 1093 | goto error; |
| 1094 | } |
Pavol Vican | 0df02b0 | 2016-03-01 10:28:50 +0100 | [diff] [blame] | 1095 | ((struct lys_tpdf *)parent)->type.der = (struct lys_tpdf *)typ; |
| 1096 | typ->type = &((struct lys_tpdf *)parent)->type; |
Pavol Vican | 4766aca | 2016-03-07 12:42:36 +0100 | [diff] [blame] | 1097 | break; |
| 1098 | case REPLACE_KEYWORD: |
| 1099 | /* deviation replace type*/ |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1100 | dev = (struct lys_deviate *)parent; |
| 1101 | if (dev->type) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1102 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "type", "deviation"); |
Pavol Vican | 4766aca | 2016-03-07 12:42:36 +0100 | [diff] [blame] | 1103 | goto error; |
| 1104 | } |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1105 | dev->type = calloc(1, sizeof *dev->type); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1106 | LY_CHECK_ERR_GOTO(!dev->type, LOGMEM(ctx), error); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1107 | dev->type->der = (struct lys_tpdf *)typ; |
| 1108 | typ->type = dev->type; |
Pavol Vican | 4766aca | 2016-03-07 12:42:36 +0100 | [diff] [blame] | 1109 | break; |
PavolVican | a0fdbf3 | 2017-02-15 17:59:02 +0100 | [diff] [blame] | 1110 | case EXTENSION_INSTANCE: |
| 1111 | ((struct lys_type *)parent)->der = (struct lys_tpdf *)typ; |
| 1112 | typ->type = parent; |
| 1113 | break; |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 1114 | default: |
| 1115 | goto error; |
| 1116 | break; |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1117 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1118 | typ->name = lydict_insert_zc(ctx, value); |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1119 | return typ; |
Pavol Vican | 4766aca | 2016-03-07 12:42:36 +0100 | [diff] [blame] | 1120 | |
| 1121 | error: |
Pavol Vican | 5f0316a | 2016-04-05 21:21:11 +0200 | [diff] [blame] | 1122 | free(value); |
Pavol Vican | 4766aca | 2016-03-07 12:42:36 +0100 | [diff] [blame] | 1123 | free(typ); |
| 1124 | return NULL; |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1125 | } |
| 1126 | |
| 1127 | void * |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1128 | yang_read_length(struct ly_ctx *ctx, struct yang_type *stype, char *value, int is_ext_instance) |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1129 | { |
PavolVican | eef1d91 | 2017-02-19 00:19:15 +0100 | [diff] [blame] | 1130 | struct lys_restr *length; |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1131 | |
PavolVican | eef1d91 | 2017-02-19 00:19:15 +0100 | [diff] [blame] | 1132 | if (is_ext_instance) { |
| 1133 | length = (struct lys_restr *)stype; |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1134 | } else { |
PavolVican | eef1d91 | 2017-02-19 00:19:15 +0100 | [diff] [blame] | 1135 | if (stype->base == 0 || stype->base == LY_TYPE_STRING) { |
| 1136 | stype->base = LY_TYPE_STRING; |
| 1137 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1138 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Unexpected length statement."); |
PavolVican | eef1d91 | 2017-02-19 00:19:15 +0100 | [diff] [blame] | 1139 | goto error; |
| 1140 | } |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1141 | |
PavolVican | eef1d91 | 2017-02-19 00:19:15 +0100 | [diff] [blame] | 1142 | if (stype->type->info.str.length) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1143 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "length", "type"); |
PavolVican | eef1d91 | 2017-02-19 00:19:15 +0100 | [diff] [blame] | 1144 | goto error; |
| 1145 | } |
| 1146 | length = calloc(1, sizeof *length); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1147 | LY_CHECK_ERR_GOTO(!length, LOGMEM(ctx), error); |
PavolVican | eef1d91 | 2017-02-19 00:19:15 +0100 | [diff] [blame] | 1148 | stype->type->info.str.length = length; |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1149 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1150 | length->expr = lydict_insert_zc(ctx, value); |
PavolVican | eef1d91 | 2017-02-19 00:19:15 +0100 | [diff] [blame] | 1151 | return length; |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1152 | |
| 1153 | error: |
| 1154 | free(value); |
| 1155 | return NULL; |
Pavol Vican | 73e7c99 | 2016-02-24 12:18:05 +0100 | [diff] [blame] | 1156 | } |
Pavol Vican | 1c203db | 2016-02-24 14:05:23 +0100 | [diff] [blame] | 1157 | |
Pavol Vican | 6eecf30 | 2016-08-10 11:09:05 +0200 | [diff] [blame] | 1158 | int |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1159 | yang_read_pattern(struct ly_ctx *ctx, struct lys_restr *pattern, void **precomp, char *value, char modifier) |
Pavol Vican | 1c203db | 2016-02-24 14:05:23 +0100 | [diff] [blame] | 1160 | { |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1161 | char *buf; |
| 1162 | size_t len; |
| 1163 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1164 | if (precomp && lyp_precompile_pattern(ctx, value, (pcre**)&precomp[0], (pcre_extra**)&precomp[1])) { |
Pavol Vican | 1c203db | 2016-02-24 14:05:23 +0100 | [diff] [blame] | 1165 | free(value); |
Pavol Vican | 6eecf30 | 2016-08-10 11:09:05 +0200 | [diff] [blame] | 1166 | return EXIT_FAILURE; |
Pavol Vican | 1c203db | 2016-02-24 14:05:23 +0100 | [diff] [blame] | 1167 | } |
Pavol Vican | 1c203db | 2016-02-24 14:05:23 +0100 | [diff] [blame] | 1168 | |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1169 | len = strlen(value); |
| 1170 | buf = malloc((len + 2) * sizeof *buf); /* modifier byte + value + terminating NULL byte */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1171 | LY_CHECK_ERR_RETURN(!buf, LOGMEM(ctx); free(value), EXIT_FAILURE); |
Pavol Vican | 6eecf30 | 2016-08-10 11:09:05 +0200 | [diff] [blame] | 1172 | |
| 1173 | buf[0] = modifier; |
Radek Krejci | 0d23e7a | 2016-08-04 12:46:17 +0200 | [diff] [blame] | 1174 | strcpy(&buf[1], value); |
| 1175 | free(value); |
| 1176 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1177 | pattern->expr = lydict_insert_zc(ctx, buf); |
Pavol Vican | 6eecf30 | 2016-08-10 11:09:05 +0200 | [diff] [blame] | 1178 | return EXIT_SUCCESS; |
Pavol Vican | 1c203db | 2016-02-24 14:05:23 +0100 | [diff] [blame] | 1179 | } |
Pavol Vican | aff5c80 | 2016-02-24 15:56:45 +0100 | [diff] [blame] | 1180 | |
| 1181 | void * |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1182 | yang_read_range(struct ly_ctx *ctx, struct yang_type *stype, char *value, int is_ext_instance) |
Pavol Vican | aff5c80 | 2016-02-24 15:56:45 +0100 | [diff] [blame] | 1183 | { |
PavolVican | eef1d91 | 2017-02-19 00:19:15 +0100 | [diff] [blame] | 1184 | struct lys_restr * range; |
| 1185 | |
| 1186 | if (is_ext_instance) { |
| 1187 | range = (struct lys_restr *)stype; |
| 1188 | } else { |
| 1189 | if (stype->base != 0 && stype->base != LY_TYPE_DEC64) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1190 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Unexpected range statement."); |
PavolVican | eef1d91 | 2017-02-19 00:19:15 +0100 | [diff] [blame] | 1191 | goto error; |
| 1192 | } |
| 1193 | stype->base = LY_TYPE_DEC64; |
| 1194 | if (stype->type->info.dec64.range) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1195 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "range", "type"); |
PavolVican | eef1d91 | 2017-02-19 00:19:15 +0100 | [diff] [blame] | 1196 | goto error; |
| 1197 | } |
| 1198 | range = calloc(1, sizeof *range); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1199 | LY_CHECK_ERR_GOTO(!range, LOGMEM(ctx), error); |
PavolVican | eef1d91 | 2017-02-19 00:19:15 +0100 | [diff] [blame] | 1200 | stype->type->info.dec64.range = range; |
Pavol Vican | aff5c80 | 2016-02-24 15:56:45 +0100 | [diff] [blame] | 1201 | } |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1202 | range->expr = lydict_insert_zc(ctx, value); |
PavolVican | eef1d91 | 2017-02-19 00:19:15 +0100 | [diff] [blame] | 1203 | return range; |
Pavol Vican | aff5c80 | 2016-02-24 15:56:45 +0100 | [diff] [blame] | 1204 | |
| 1205 | error: |
| 1206 | free(value); |
| 1207 | return NULL; |
| 1208 | } |
Pavol Vican | 07ea68d | 2016-02-25 12:01:37 +0100 | [diff] [blame] | 1209 | |
| 1210 | int |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1211 | yang_read_fraction(struct ly_ctx *ctx, struct yang_type *typ, uint32_t value) |
Pavol Vican | 07ea68d | 2016-02-25 12:01:37 +0100 | [diff] [blame] | 1212 | { |
Michal Vasko | 27e5e68 | 2018-07-23 14:22:57 +0200 | [diff] [blame] | 1213 | uint32_t i; |
| 1214 | |
Pavol Vican | 6b07251 | 2016-04-04 10:50:21 +0200 | [diff] [blame] | 1215 | if (typ->base == 0 || typ->base == LY_TYPE_DEC64) { |
| 1216 | typ->base = LY_TYPE_DEC64; |
Pavol Vican | 07ea68d | 2016-02-25 12:01:37 +0100 | [diff] [blame] | 1217 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1218 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Unexpected fraction-digits statement."); |
Pavol Vican | 07ea68d | 2016-02-25 12:01:37 +0100 | [diff] [blame] | 1219 | goto error; |
| 1220 | } |
| 1221 | if (typ->type->info.dec64.dig) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1222 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "fraction-digits", "type"); |
Pavol Vican | 07ea68d | 2016-02-25 12:01:37 +0100 | [diff] [blame] | 1223 | goto error; |
| 1224 | } |
| 1225 | /* range check */ |
| 1226 | if (value < 1 || value > 18) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1227 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid value \"%d\" of \"%s\".", value, "fraction-digits"); |
Pavol Vican | 07ea68d | 2016-02-25 12:01:37 +0100 | [diff] [blame] | 1228 | goto error; |
| 1229 | } |
| 1230 | typ->type->info.dec64.dig = value; |
Michal Vasko | 27e5e68 | 2018-07-23 14:22:57 +0200 | [diff] [blame] | 1231 | typ->type->info.dec64.div = 10; |
| 1232 | for (i = 1; i < value; i++) { |
| 1233 | typ->type->info.dec64.div *= 10; |
| 1234 | } |
Pavol Vican | 07ea68d | 2016-02-25 12:01:37 +0100 | [diff] [blame] | 1235 | return EXIT_SUCCESS; |
| 1236 | |
| 1237 | error: |
| 1238 | return EXIT_FAILURE; |
| 1239 | } |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 1240 | |
Pavol Vican | 874715f | 2016-10-25 14:52:08 +0200 | [diff] [blame] | 1241 | int |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1242 | yang_read_enum(struct ly_ctx *ctx, struct yang_type *typ, struct lys_type_enum *enm, char *value) |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 1243 | { |
Pavol Vican | 874715f | 2016-10-25 14:52:08 +0200 | [diff] [blame] | 1244 | int i, j; |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 1245 | |
Pavol Vican | 5c8a9ad | 2016-11-22 11:50:54 +0100 | [diff] [blame] | 1246 | typ->base = LY_TYPE_ENUM; |
Pavol Vican | c666241 | 2016-08-30 08:06:28 +0200 | [diff] [blame] | 1247 | if (!value[0]) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1248 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "enum name"); |
| 1249 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Enum name must not be empty."); |
Pavol Vican | c666241 | 2016-08-30 08:06:28 +0200 | [diff] [blame] | 1250 | free(value); |
| 1251 | goto error; |
| 1252 | } |
| 1253 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1254 | enm->name = lydict_insert_zc(ctx, value); |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 1255 | |
| 1256 | /* the assigned name MUST NOT have any leading or trailing whitespace characters */ |
| 1257 | if (isspace(enm->name[0]) || isspace(enm->name[strlen(enm->name) - 1])) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1258 | LOGVAL(ctx, LYE_ENUM_WS, LY_VLOG_NONE, NULL, enm->name); |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 1259 | goto error; |
| 1260 | } |
| 1261 | |
Pavol Vican | 874715f | 2016-10-25 14:52:08 +0200 | [diff] [blame] | 1262 | j = typ->type->info.enums.count - 1; |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 1263 | /* check the name uniqueness */ |
Pavol Vican | 874715f | 2016-10-25 14:52:08 +0200 | [diff] [blame] | 1264 | for (i = 0; i < j; i++) { |
PavolVican | 4b80d04 | 2017-02-23 14:30:27 +0100 | [diff] [blame] | 1265 | if (ly_strequal(typ->type->info.enums.enm[i].name, enm->name, 1)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1266 | LOGVAL(ctx, LYE_ENUM_DUPNAME, LY_VLOG_NONE, NULL, enm->name); |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 1267 | goto error; |
| 1268 | } |
| 1269 | } |
| 1270 | |
Pavol Vican | 874715f | 2016-10-25 14:52:08 +0200 | [diff] [blame] | 1271 | return EXIT_SUCCESS; |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 1272 | |
| 1273 | error: |
Pavol Vican | 874715f | 2016-10-25 14:52:08 +0200 | [diff] [blame] | 1274 | return EXIT_FAILURE; |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | int |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1278 | yang_check_enum(struct ly_ctx *ctx, struct yang_type *typ, struct lys_type_enum *enm, int64_t *value, int assign) |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 1279 | { |
| 1280 | int i, j; |
| 1281 | |
| 1282 | if (!assign) { |
| 1283 | /* assign value automatically */ |
| 1284 | if (*value > INT32_MAX) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1285 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, "2147483648", "enum/value"); |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 1286 | goto error; |
| 1287 | } |
| 1288 | enm->value = *value; |
| 1289 | enm->flags |= LYS_AUTOASSIGNED; |
| 1290 | (*value)++; |
Pavol Vican | 5de389c | 2016-08-30 08:55:15 +0200 | [diff] [blame] | 1291 | } else if (typ->type->info.enums.enm == enm) { |
| 1292 | /* change value, which is assigned automatically, if first enum has value. */ |
| 1293 | *value = typ->type->info.enums.enm[0].value; |
| 1294 | (*value)++; |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | /* check that the value is unique */ |
| 1298 | j = typ->type->info.enums.count-1; |
| 1299 | for (i = 0; i < j; i++) { |
| 1300 | if (typ->type->info.enums.enm[i].value == typ->type->info.enums.enm[j].value) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1301 | LOGVAL(ctx, LYE_ENUM_DUPVAL, LY_VLOG_NONE, NULL, |
Radek Krejci | e663e01 | 2016-08-01 17:12:34 +0200 | [diff] [blame] | 1302 | typ->type->info.enums.enm[j].value, typ->type->info.enums.enm[j].name, |
| 1303 | typ->type->info.enums.enm[i].name); |
Pavol Vican | 79a763d | 2016-02-25 15:41:27 +0100 | [diff] [blame] | 1304 | goto error; |
| 1305 | } |
| 1306 | } |
| 1307 | |
| 1308 | return EXIT_SUCCESS; |
| 1309 | |
| 1310 | error: |
| 1311 | return EXIT_FAILURE; |
| 1312 | } |
Pavol Vican | 9887c68 | 2016-02-29 11:32:01 +0100 | [diff] [blame] | 1313 | |
Pavol Vican | 59e8dee | 2016-10-25 15:29:38 +0200 | [diff] [blame] | 1314 | int |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1315 | yang_read_bit(struct ly_ctx *ctx, struct yang_type *typ, struct lys_type_bit *bit, char *value) |
Pavol Vican | 9887c68 | 2016-02-29 11:32:01 +0100 | [diff] [blame] | 1316 | { |
Pavol Vican | 59e8dee | 2016-10-25 15:29:38 +0200 | [diff] [blame] | 1317 | int i, j; |
Pavol Vican | 9887c68 | 2016-02-29 11:32:01 +0100 | [diff] [blame] | 1318 | |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 1319 | typ->base = LY_TYPE_BITS; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1320 | bit->name = lydict_insert_zc(ctx, value); |
| 1321 | if (lyp_check_identifier(ctx, bit->name, LY_IDENT_SIMPLE, NULL, NULL)) { |
Pavol Vican | 9887c68 | 2016-02-29 11:32:01 +0100 | [diff] [blame] | 1322 | goto error; |
| 1323 | } |
Pavol Vican | 9887c68 | 2016-02-29 11:32:01 +0100 | [diff] [blame] | 1324 | |
Pavol Vican | 59e8dee | 2016-10-25 15:29:38 +0200 | [diff] [blame] | 1325 | j = typ->type->info.bits.count - 1; |
Pavol Vican | 9887c68 | 2016-02-29 11:32:01 +0100 | [diff] [blame] | 1326 | /* check the name uniqueness */ |
Pavol Vican | 59e8dee | 2016-10-25 15:29:38 +0200 | [diff] [blame] | 1327 | for (i = 0; i < j; i++) { |
PavolVican | 4b80d04 | 2017-02-23 14:30:27 +0100 | [diff] [blame] | 1328 | if (ly_strequal(typ->type->info.bits.bit[i].name, bit->name, 1)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1329 | LOGVAL(ctx, LYE_BITS_DUPNAME, LY_VLOG_NONE, NULL, bit->name); |
Pavol Vican | 9887c68 | 2016-02-29 11:32:01 +0100 | [diff] [blame] | 1330 | goto error; |
| 1331 | } |
| 1332 | } |
Pavol Vican | 59e8dee | 2016-10-25 15:29:38 +0200 | [diff] [blame] | 1333 | return EXIT_SUCCESS; |
Pavol Vican | 9887c68 | 2016-02-29 11:32:01 +0100 | [diff] [blame] | 1334 | |
| 1335 | error: |
Pavol Vican | 59e8dee | 2016-10-25 15:29:38 +0200 | [diff] [blame] | 1336 | return EXIT_FAILURE; |
Pavol Vican | 9887c68 | 2016-02-29 11:32:01 +0100 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | int |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1340 | yang_check_bit(struct ly_ctx *ctx, struct yang_type *typ, struct lys_type_bit *bit, int64_t *value, int assign) |
Pavol Vican | 9887c68 | 2016-02-29 11:32:01 +0100 | [diff] [blame] | 1341 | { |
| 1342 | int i,j; |
Pavol Vican | 9887c68 | 2016-02-29 11:32:01 +0100 | [diff] [blame] | 1343 | |
| 1344 | if (!assign) { |
| 1345 | /* assign value automatically */ |
| 1346 | if (*value > UINT32_MAX) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1347 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, "4294967295", "bit/position"); |
Pavol Vican | 9887c68 | 2016-02-29 11:32:01 +0100 | [diff] [blame] | 1348 | goto error; |
| 1349 | } |
| 1350 | bit->pos = (uint32_t)*value; |
| 1351 | bit->flags |= LYS_AUTOASSIGNED; |
| 1352 | (*value)++; |
| 1353 | } |
| 1354 | |
| 1355 | j = typ->type->info.bits.count - 1; |
| 1356 | /* check that the value is unique */ |
| 1357 | for (i = 0; i < j; i++) { |
| 1358 | if (typ->type->info.bits.bit[i].pos == bit->pos) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1359 | LOGVAL(ctx, LYE_BITS_DUPVAL, LY_VLOG_NONE, NULL, bit->pos, bit->name, typ->type->info.bits.bit[i].name); |
Pavol Vican | 9887c68 | 2016-02-29 11:32:01 +0100 | [diff] [blame] | 1360 | goto error; |
| 1361 | } |
| 1362 | } |
| 1363 | |
Pavol Vican | 9887c68 | 2016-02-29 11:32:01 +0100 | [diff] [blame] | 1364 | return EXIT_SUCCESS; |
| 1365 | |
| 1366 | error: |
| 1367 | return EXIT_FAILURE; |
| 1368 | } |
Pavol Vican | 0df02b0 | 2016-03-01 10:28:50 +0100 | [diff] [blame] | 1369 | |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 1370 | int |
| 1371 | yang_read_augment(struct lys_module *module, struct lys_node *parent, struct lys_node_augment *aug, char *value) |
Pavol Vican | 0df02b0 | 2016-03-01 10:28:50 +0100 | [diff] [blame] | 1372 | { |
Pavol Vican | 92fa0dc | 2016-03-02 14:20:39 +0100 | [diff] [blame] | 1373 | aug->nodetype = LYS_AUGMENT; |
Pavol Vican | 0adf01d | 2016-03-22 12:29:33 +0100 | [diff] [blame] | 1374 | aug->target_name = transform_schema2json(module, value); |
Pavol Vican | 92fa0dc | 2016-03-02 14:20:39 +0100 | [diff] [blame] | 1375 | free(value); |
| 1376 | if (!aug->target_name) { |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 1377 | return EXIT_FAILURE; |
Pavol Vican | 92fa0dc | 2016-03-02 14:20:39 +0100 | [diff] [blame] | 1378 | } |
| 1379 | aug->parent = parent; |
| 1380 | aug->module = module; |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 1381 | return EXIT_SUCCESS; |
Pavol Vican | 92fa0dc | 2016-03-02 14:20:39 +0100 | [diff] [blame] | 1382 | } |
Pavol Vican | 220e5a1 | 2016-03-03 14:19:43 +0100 | [diff] [blame] | 1383 | |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 1384 | void * |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1385 | yang_read_deviate_unsupported(struct ly_ctx *ctx, struct lys_deviation *dev) |
Pavol Vican | 4c90c64 | 2016-03-03 15:06:47 +0100 | [diff] [blame] | 1386 | { |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1387 | if (dev->deviate_size) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1388 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "\"not-supported\" deviation cannot be combined with any other deviation."); |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 1389 | return NULL; |
Pavol Vican | 220e5a1 | 2016-03-03 14:19:43 +0100 | [diff] [blame] | 1390 | } |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1391 | dev->deviate = calloc(1, sizeof *dev->deviate); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1392 | LY_CHECK_ERR_RETURN(!dev->deviate, LOGMEM(ctx), NULL); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1393 | dev->deviate[dev->deviate_size].mod = LY_DEVIATE_NO; |
| 1394 | dev->deviate_size = 1; |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 1395 | return dev->deviate; |
Pavol Vican | 220e5a1 | 2016-03-03 14:19:43 +0100 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | void * |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1399 | yang_read_deviate(struct ly_ctx *ctx, struct lys_deviation *dev, LYS_DEVIATE_TYPE mod) |
Pavol Vican | 220e5a1 | 2016-03-03 14:19:43 +0100 | [diff] [blame] | 1400 | { |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1401 | struct lys_deviate *deviate; |
Pavol Vican | 220e5a1 | 2016-03-03 14:19:43 +0100 | [diff] [blame] | 1402 | |
PavolVican | 4b80d04 | 2017-02-23 14:30:27 +0100 | [diff] [blame] | 1403 | if (dev->deviate_size && dev->deviate[0].mod == LY_DEVIATE_NO) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1404 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "not-supported"); |
| 1405 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "\"not-supported\" deviation cannot be combined with any other deviation."); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1406 | return NULL; |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1407 | } |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1408 | if (!(dev->deviate_size % LY_YANG_ARRAY_SIZE)) { |
| 1409 | deviate = realloc(dev->deviate, (LY_YANG_ARRAY_SIZE + dev->deviate_size) * sizeof *deviate); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1410 | LY_CHECK_ERR_RETURN(!deviate, LOGMEM(ctx), NULL); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1411 | memset(deviate + dev->deviate_size, 0, LY_YANG_ARRAY_SIZE * sizeof *deviate); |
| 1412 | dev->deviate = deviate; |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1413 | } |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1414 | dev->deviate[dev->deviate_size].mod = mod; |
| 1415 | return &dev->deviate[dev->deviate_size++]; |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | int |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1419 | yang_read_deviate_units(struct ly_ctx *ctx, struct lys_deviate *deviate, struct lys_node *dev_target) |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1420 | { |
| 1421 | const char **stritem; |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 1422 | int j; |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1423 | |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1424 | /* check target node type */ |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1425 | if (dev_target->nodetype == LYS_LEAFLIST) { |
| 1426 | stritem = &((struct lys_node_leaflist *)dev_target)->units; |
| 1427 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 1428 | stritem = &((struct lys_node_leaf *)dev_target)->units; |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1429 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1430 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "units"); |
| 1431 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"units\" property."); |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1432 | goto error; |
| 1433 | } |
| 1434 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1435 | if (deviate->mod == LY_DEVIATE_DEL) { |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1436 | /* check values */ |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1437 | if (!ly_strequal(*stritem, deviate->units, 1)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1438 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, deviate->units, "units"); |
| 1439 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1440 | goto error; |
| 1441 | } |
| 1442 | /* remove current units value of the target */ |
| 1443 | lydict_remove(ctx, *stritem); |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 1444 | *stritem = NULL; |
| 1445 | /* remove its extensions */ |
| 1446 | j = -1; |
| 1447 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_UNITS)) != -1) { |
| 1448 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 1449 | --j; |
| 1450 | } |
Pavol Vican | 4766aca | 2016-03-07 12:42:36 +0100 | [diff] [blame] | 1451 | } else { |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1452 | if (deviate->mod == LY_DEVIATE_ADD) { |
Pavol Vican | 4766aca | 2016-03-07 12:42:36 +0100 | [diff] [blame] | 1453 | /* check that there is no current value */ |
| 1454 | if (*stritem) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1455 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "units"); |
| 1456 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Pavol Vican | 4766aca | 2016-03-07 12:42:36 +0100 | [diff] [blame] | 1457 | goto error; |
| 1458 | } |
| 1459 | } else { /* replace */ |
| 1460 | if (!*stritem) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1461 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "units"); |
| 1462 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Replacing a property that does not exist."); |
Pavol Vican | 4766aca | 2016-03-07 12:42:36 +0100 | [diff] [blame] | 1463 | goto error; |
| 1464 | } |
| 1465 | } |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1466 | /* remove current units value of the target ... */ |
| 1467 | lydict_remove(ctx, *stritem); |
| 1468 | |
| 1469 | /* ... and replace it with the value specified in deviation */ |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1470 | *stritem = lydict_insert(ctx, deviate->units, 0); |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1471 | } |
| 1472 | |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1473 | return EXIT_SUCCESS; |
| 1474 | |
| 1475 | error: |
| 1476 | return EXIT_FAILURE; |
| 1477 | } |
| 1478 | |
| 1479 | int |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1480 | yang_read_deviate_unique(struct lys_deviate *deviate, struct lys_node *dev_target) |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1481 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1482 | struct ly_ctx *ctx = dev_target->module->ctx; |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1483 | struct lys_node_list *list; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1484 | struct lys_unique *unique; |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1485 | |
| 1486 | /* check target node type */ |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1487 | if (dev_target->nodetype != LYS_LIST) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1488 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "unique"); |
| 1489 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"unique\" property."); |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1490 | goto error; |
| 1491 | } |
| 1492 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1493 | list = (struct lys_node_list *)dev_target; |
| 1494 | if (deviate->mod == LY_DEVIATE_ADD) { |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1495 | /* reallocate the unique array of the target */ |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1496 | unique = ly_realloc(list->unique, (deviate->unique_size + list->unique_size) * sizeof *unique); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1497 | LY_CHECK_ERR_GOTO(!unique, LOGMEM(ctx), error); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1498 | list->unique = unique; |
| 1499 | memset(unique + list->unique_size, 0, deviate->unique_size * sizeof *unique); |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | return EXIT_SUCCESS; |
| 1503 | |
| 1504 | error: |
| 1505 | return EXIT_FAILURE; |
| 1506 | } |
| 1507 | |
| 1508 | int |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1509 | yang_fill_deviate_default(struct ly_ctx *ctx, struct lys_deviate *deviate, struct lys_node *dev_target, |
| 1510 | struct ly_set *dflt_check, const char *value) |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1511 | { |
| 1512 | struct lys_node *node; |
| 1513 | struct lys_node_choice *choice; |
| 1514 | struct lys_node_leaf *leaf; |
| 1515 | struct lys_node_leaflist *llist; |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 1516 | int rc, i, j; |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1517 | unsigned int u; |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1518 | |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1519 | u = strlen(value); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1520 | if (dev_target->nodetype == LYS_CHOICE) { |
| 1521 | choice = (struct lys_node_choice *)dev_target; |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1522 | rc = resolve_choice_default_schema_nodeid(value, choice->child, (const struct lys_node **)&node); |
| 1523 | if (rc || !node) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1524 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1525 | goto error; |
| 1526 | } |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1527 | if (deviate->mod == LY_DEVIATE_DEL) { |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1528 | if (!choice->dflt || (choice->dflt != node)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1529 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 1530 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1531 | goto error; |
| 1532 | } |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 1533 | choice->dflt = NULL; |
| 1534 | /* remove extensions of this default instance from the target node */ |
| 1535 | j = -1; |
| 1536 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_DEFAULT)) != -1) { |
| 1537 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 1538 | --j; |
| 1539 | } |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1540 | } else { /* add or replace */ |
| 1541 | choice->dflt = node; |
| 1542 | if (!choice->dflt) { |
| 1543 | /* default branch not found */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1544 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1545 | goto error; |
| 1546 | } |
| 1547 | } |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1548 | } else if (dev_target->nodetype == LYS_LEAF) { |
| 1549 | leaf = (struct lys_node_leaf *)dev_target; |
| 1550 | if (deviate->mod == LY_DEVIATE_DEL) { |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1551 | if (!leaf->dflt || !ly_strequal(leaf->dflt, value, 1)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1552 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 1553 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1554 | goto error; |
| 1555 | } |
| 1556 | /* remove value */ |
| 1557 | lydict_remove(ctx, leaf->dflt); |
| 1558 | leaf->dflt = NULL; |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 1559 | leaf->flags &= ~LYS_DFLTJSON; |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 1560 | /* remove extensions of this default instance from the target node */ |
| 1561 | j = -1; |
| 1562 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_DEFAULT)) != -1) { |
| 1563 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 1564 | --j; |
| 1565 | } |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1566 | } else { /* add (already checked) and replace */ |
| 1567 | /* remove value */ |
| 1568 | lydict_remove(ctx, leaf->dflt); |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 1569 | leaf->flags &= ~LYS_DFLTJSON; |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1570 | |
| 1571 | /* set new value */ |
| 1572 | leaf->dflt = lydict_insert(ctx, value, u); |
| 1573 | |
| 1574 | /* remember to check it later (it may not fit now, but the type can be deviated too) */ |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1575 | ly_set_add(dflt_check, dev_target, 0); |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1576 | } |
| 1577 | } else { /* LYS_LEAFLIST */ |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1578 | llist = (struct lys_node_leaflist *)dev_target; |
| 1579 | if (deviate->mod == LY_DEVIATE_DEL) { |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1580 | /* find and remove the value in target list */ |
| 1581 | for (i = 0; i < llist->dflt_size; i++) { |
| 1582 | if (llist->dflt[i] && ly_strequal(llist->dflt[i], value, 1)) { |
| 1583 | /* match, remove the value */ |
| 1584 | lydict_remove(llist->module->ctx, llist->dflt[i]); |
| 1585 | llist->dflt[i] = NULL; |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 1586 | /* remove extensions of this default instance from the target node */ |
| 1587 | j = -1; |
| 1588 | while ((j = lys_ext_iter(dev_target->ext, dev_target->ext_size, j + 1, LYEXT_SUBSTMT_DEFAULT)) != -1) { |
| 1589 | if (dev_target->ext[j]->insubstmt_index == i) { |
| 1590 | lyp_ext_instance_rm(ctx, &dev_target->ext, &dev_target->ext_size, j); |
| 1591 | --j; |
| 1592 | } else if (dev_target->ext[j]->insubstmt_index > i) { |
| 1593 | /* decrease the substatement index of the extension because of the changed array of defaults */ |
| 1594 | dev_target->ext[j]->insubstmt_index--; |
| 1595 | } |
| 1596 | } |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1597 | break; |
| 1598 | } |
| 1599 | } |
| 1600 | if (i == llist->dflt_size) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1601 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 1602 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "The default value to delete not found in the target node."); |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1603 | goto error; |
| 1604 | } |
| 1605 | } else { |
| 1606 | /* add or replace, anyway we place items into the deviate's list |
| 1607 | which propagates to the target */ |
| 1608 | /* we just want to check that the value isn't already in the list */ |
| 1609 | for (i = 0; i < llist->dflt_size; i++) { |
| 1610 | if (ly_strequal(llist->dflt[i], value, 1)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1611 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 1612 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Duplicated default value \"%s\".", value); |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1613 | goto error; |
| 1614 | } |
| 1615 | } |
| 1616 | /* store it in target node */ |
| 1617 | llist->dflt[llist->dflt_size++] = lydict_insert(ctx, value, u); |
| 1618 | |
| 1619 | /* remember to check it later (it may not fit now, but the type can be deviated too) */ |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1620 | ly_set_add(dflt_check, dev_target, 0); |
Radek Krejci | bd117f0 | 2016-11-04 16:28:08 +0100 | [diff] [blame] | 1621 | llist->flags &= ~LYS_DFLTJSON; |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1622 | } |
| 1623 | } |
| 1624 | |
| 1625 | return EXIT_SUCCESS; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1626 | |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1627 | error: |
| 1628 | return EXIT_FAILURE; |
| 1629 | } |
| 1630 | |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 1631 | int |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1632 | yang_read_deviate_default(struct lys_module *module, struct lys_deviate *deviate, |
| 1633 | struct lys_node *dev_target, struct ly_set * dflt_check) |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1634 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1635 | struct ly_ctx *ctx = module->ctx; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1636 | int i; |
| 1637 | struct lys_node_leaflist *llist; |
| 1638 | const char **dflt; |
| 1639 | |
| 1640 | /* check target node type */ |
| 1641 | if (module->version < 2 && dev_target->nodetype == LYS_LEAFLIST) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1642 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 1643 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"default\" property."); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1644 | goto error; |
| 1645 | } else if (deviate->dflt_size > 1 && dev_target->nodetype != LYS_LEAFLIST) { /* from YANG 1.1 */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1646 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 1647 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow multiple \"default\" properties."); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1648 | goto error; |
| 1649 | } else if (!(dev_target->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_CHOICE))) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1650 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 1651 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"default\" property."); |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1652 | goto error; |
| 1653 | } |
| 1654 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1655 | if (deviate->mod == LY_DEVIATE_ADD) { |
| 1656 | /* check that there is no current value */ |
| 1657 | if ((dev_target->nodetype == LYS_LEAF && ((struct lys_node_leaf *)dev_target)->dflt) || |
| 1658 | (dev_target->nodetype == LYS_CHOICE && ((struct lys_node_choice *)dev_target)->dflt)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1659 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 1660 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1661 | goto error; |
| 1662 | } |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1663 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1664 | /* check collision with mandatory/min-elements */ |
| 1665 | if ((dev_target->flags & LYS_MAND_TRUE) || |
| 1666 | (dev_target->nodetype == LYS_LEAFLIST && ((struct lys_node_leaflist *)dev_target)->min)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1667 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "default", "deviation"); |
| 1668 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1669 | "Adding the \"default\" statement is forbidden on %s statement.", |
| 1670 | (dev_target->flags & LYS_MAND_TRUE) ? "nodes with the \"mandatory\"" : "leaflists with non-zero \"min-elements\""); |
| 1671 | goto error; |
| 1672 | } |
| 1673 | } else if (deviate->mod == LY_DEVIATE_RPL) { |
| 1674 | /* check that there was a value before */ |
| 1675 | if (((dev_target->nodetype & (LYS_LEAF | LYS_LEAFLIST)) && !((struct lys_node_leaf *)dev_target)->dflt) || |
| 1676 | (dev_target->nodetype == LYS_CHOICE && !((struct lys_node_choice *)dev_target)->dflt)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1677 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "default"); |
| 1678 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Replacing a property that does not exist."); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1679 | goto error; |
| 1680 | } |
| 1681 | } |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1682 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1683 | if (dev_target->nodetype == LYS_LEAFLIST) { |
| 1684 | /* reallocate default list in the target */ |
| 1685 | llist = (struct lys_node_leaflist *)dev_target; |
| 1686 | if (deviate->mod == LY_DEVIATE_ADD) { |
| 1687 | /* reallocate (enlarge) the unique array of the target */ |
| 1688 | dflt = realloc(llist->dflt, (deviate->dflt_size + llist->dflt_size) * sizeof *dflt); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1689 | LY_CHECK_ERR_GOTO(!dflt, LOGMEM(ctx), error); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1690 | llist->dflt = dflt; |
| 1691 | } else if (deviate->mod == LY_DEVIATE_RPL) { |
| 1692 | /* reallocate (replace) the unique array of the target */ |
| 1693 | for (i = 0; i < llist->dflt_size; i++) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1694 | lydict_remove(ctx, llist->dflt[i]); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1695 | } |
| 1696 | dflt = realloc(llist->dflt, deviate->dflt_size * sizeof *dflt); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1697 | LY_CHECK_ERR_GOTO(!dflt, LOGMEM(ctx), error); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1698 | llist->dflt = dflt; |
| 1699 | llist->dflt_size = 0; |
| 1700 | } |
| 1701 | } |
| 1702 | |
| 1703 | for (i = 0; i < deviate->dflt_size; ++i) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1704 | if (yang_fill_deviate_default(ctx, deviate, dev_target, dflt_check, deviate->dflt[i])) { |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1705 | goto error; |
| 1706 | } |
| 1707 | } |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1708 | |
| 1709 | return EXIT_SUCCESS; |
| 1710 | |
| 1711 | error: |
| 1712 | return EXIT_FAILURE; |
| 1713 | } |
| 1714 | |
| 1715 | int |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1716 | yang_check_deviate_mandatory(struct lys_deviate *deviate, struct lys_node *dev_target) |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1717 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1718 | struct ly_ctx *ctx = dev_target->module->ctx; |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 1719 | struct lys_node *parent; |
| 1720 | |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1721 | /* check target node type */ |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1722 | if (!(dev_target->nodetype & (LYS_LEAF | LYS_CHOICE | LYS_ANYDATA))) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1723 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "mandatory"); |
| 1724 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"mandatory\" property."); |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1725 | goto error; |
| 1726 | } |
| 1727 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1728 | if (deviate->mod == LY_DEVIATE_ADD) { |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1729 | /* check that there is no current value */ |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1730 | if (dev_target->flags & LYS_MAND_MASK) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1731 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "mandatory"); |
| 1732 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1733 | goto error; |
Pavol Vican | 321a02e | 2016-04-05 16:11:59 +0200 | [diff] [blame] | 1734 | } else { |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1735 | if (dev_target->nodetype == LYS_LEAF && ((struct lys_node_leaf *)dev_target)->dflt) { |
Pavol Vican | 321a02e | 2016-04-05 16:11:59 +0200 | [diff] [blame] | 1736 | /* RFC 6020, 7.6.4 - default statement must not with mandatory true */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1737 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "mandatory", "leaf"); |
| 1738 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "The \"mandatory\" statement is forbidden on leaf with \"default\"."); |
Pavol Vican | 321a02e | 2016-04-05 16:11:59 +0200 | [diff] [blame] | 1739 | goto error; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1740 | } else if (dev_target->nodetype == LYS_CHOICE && ((struct lys_node_choice *)dev_target)->dflt) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1741 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "mandatory", "choice"); |
| 1742 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "The \"mandatory\" statement is forbidden on choices with \"default\"."); |
Pavol Vican | 321a02e | 2016-04-05 16:11:59 +0200 | [diff] [blame] | 1743 | goto error; |
| 1744 | } |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1745 | } |
Pavol Vican | 4766aca | 2016-03-07 12:42:36 +0100 | [diff] [blame] | 1746 | } else { /* replace */ |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1747 | if (!(dev_target->flags & LYS_MAND_MASK)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1748 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "mandatory"); |
| 1749 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Replacing a property that does not exist."); |
Pavol Vican | 4766aca | 2016-03-07 12:42:36 +0100 | [diff] [blame] | 1750 | goto error; |
| 1751 | } |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1752 | } |
| 1753 | |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1754 | /* remove current mandatory value of the target ... */ |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1755 | dev_target->flags &= ~LYS_MAND_MASK; |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1756 | |
| 1757 | /* ... and replace it with the value specified in deviation */ |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1758 | dev_target->flags |= deviate->flags & LYS_MAND_MASK; |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1759 | |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 1760 | /* check for mandatory node in default case, first find the closest parent choice to the changed node */ |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1761 | for (parent = dev_target->parent; |
Radek Krejci | e00d231 | 2016-08-12 15:27:49 +0200 | [diff] [blame] | 1762 | parent && !(parent->nodetype & (LYS_CHOICE | LYS_GROUPING | LYS_ACTION)); |
| 1763 | parent = parent->parent) { |
| 1764 | if (parent->nodetype == LYS_CONTAINER && ((struct lys_node_container *)parent)->presence) { |
| 1765 | /* stop also on presence containers */ |
| 1766 | break; |
| 1767 | } |
| 1768 | } |
| 1769 | /* and if it is a choice with the default case, check it for presence of a mandatory node in it */ |
| 1770 | if (parent && parent->nodetype == LYS_CHOICE && ((struct lys_node_choice *)parent)->dflt) { |
| 1771 | if (lyp_check_mandatory_choice(parent)) { |
| 1772 | goto error; |
| 1773 | } |
| 1774 | } |
| 1775 | |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1776 | return EXIT_SUCCESS; |
| 1777 | |
| 1778 | error: |
| 1779 | return EXIT_FAILURE; |
| 1780 | } |
| 1781 | |
| 1782 | int |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1783 | yang_read_deviate_minmax(struct lys_deviate *deviate, struct lys_node *dev_target, uint32_t value, int type) |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1784 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1785 | struct ly_ctx *ctx = dev_target->module->ctx; |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1786 | uint32_t *ui32val, *min, *max; |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1787 | |
| 1788 | /* check target node type */ |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1789 | if (dev_target->nodetype == LYS_LEAFLIST) { |
| 1790 | max = &((struct lys_node_leaflist *)dev_target)->max; |
| 1791 | min = &((struct lys_node_leaflist *)dev_target)->min; |
| 1792 | } else if (dev_target->nodetype == LYS_LIST) { |
| 1793 | max = &((struct lys_node_list *)dev_target)->max; |
| 1794 | min = &((struct lys_node_list *)dev_target)->min; |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1795 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1796 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, (type) ? "max-elements" : "min-elements"); |
| 1797 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"%s\" property.", (type) ? "max-elements" : "min-elements"); |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1798 | goto error; |
| 1799 | } |
| 1800 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1801 | ui32val = (type) ? max : min; |
| 1802 | if (deviate->mod == LY_DEVIATE_ADD) { |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1803 | /* check that there is no current value */ |
| 1804 | if (*ui32val) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1805 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, (type) ? "max-elements" : "min-elements"); |
| 1806 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Adding property that already exists."); |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1807 | goto error; |
| 1808 | } |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1809 | } else if (deviate->mod == LY_DEVIATE_RPL) { |
Pavol Vican | 4766aca | 2016-03-07 12:42:36 +0100 | [diff] [blame] | 1810 | /* unfortunately, there is no way to check reliably that there |
| 1811 | * was a value before, it could have been the default */ |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | /* add (already checked) and replace */ |
| 1815 | /* set new value specified in deviation */ |
| 1816 | *ui32val = value; |
| 1817 | |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1818 | /* check min-elements is smaller than max-elements */ |
| 1819 | if (*max && *min > *max) { |
| 1820 | if (type) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1821 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid value \"%d\" of \"max-elements\".", value); |
| 1822 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "\"max-elements\" is smaller than \"min-elements\"."); |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1823 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1824 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Invalid value \"%d\" of \"min-elements\".", value); |
| 1825 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "\"min-elements\" is bigger than \"max-elements\"."); |
Pavol Vican | 09adcc3 | 2016-08-25 10:51:36 +0200 | [diff] [blame] | 1826 | } |
| 1827 | goto error; |
| 1828 | } |
| 1829 | |
Pavol Vican | 85f1202 | 2016-03-05 16:30:35 +0100 | [diff] [blame] | 1830 | return EXIT_SUCCESS; |
| 1831 | |
| 1832 | error: |
| 1833 | return EXIT_FAILURE; |
| 1834 | } |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1835 | |
| 1836 | int |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1837 | yang_check_deviate_must(struct lys_module *module, struct unres_schema *unres, |
| 1838 | struct lys_deviate *deviate, struct lys_node *dev_target) |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1839 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1840 | struct ly_ctx *ctx = module->ctx; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1841 | int i, j, erase_must = 1; |
| 1842 | struct lys_restr **trg_must, *must; |
PavolVican | 214408f | 2017-02-03 11:54:05 +0100 | [diff] [blame] | 1843 | uint8_t *trg_must_size; |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1844 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1845 | /* check target node type */ |
| 1846 | switch (dev_target->nodetype) { |
| 1847 | case LYS_LEAF: |
| 1848 | trg_must = &((struct lys_node_leaf *)dev_target)->must; |
| 1849 | trg_must_size = &((struct lys_node_leaf *)dev_target)->must_size; |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1850 | break; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1851 | case LYS_CONTAINER: |
| 1852 | trg_must = &((struct lys_node_container *)dev_target)->must; |
| 1853 | trg_must_size = &((struct lys_node_container *)dev_target)->must_size; |
| 1854 | break; |
| 1855 | case LYS_LEAFLIST: |
| 1856 | trg_must = &((struct lys_node_leaflist *)dev_target)->must; |
| 1857 | trg_must_size = &((struct lys_node_leaflist *)dev_target)->must_size; |
| 1858 | break; |
| 1859 | case LYS_LIST: |
| 1860 | trg_must = &((struct lys_node_list *)dev_target)->must; |
| 1861 | trg_must_size = &((struct lys_node_list *)dev_target)->must_size; |
| 1862 | break; |
| 1863 | case LYS_ANYXML: |
| 1864 | case LYS_ANYDATA: |
| 1865 | trg_must = &((struct lys_node_anydata *)dev_target)->must; |
| 1866 | trg_must_size = &((struct lys_node_anydata *)dev_target)->must_size; |
| 1867 | break; |
| 1868 | default: |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1869 | LOGVAL(ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "must"); |
| 1870 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"must\" property."); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1871 | goto error; |
| 1872 | } |
| 1873 | |
| 1874 | /* flag will be checked again, clear it for now */ |
Michal Vasko | c04173b | 2018-03-09 10:43:22 +0100 | [diff] [blame] | 1875 | dev_target->flags &= ~(LYS_XPCONF_DEP | LYS_XPSTATE_DEP); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1876 | |
| 1877 | if (deviate->mod == LY_DEVIATE_ADD) { |
| 1878 | /* reallocate the must array of the target */ |
| 1879 | must = ly_realloc(*trg_must, (deviate->must_size + *trg_must_size) * sizeof *must); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1880 | LY_CHECK_ERR_GOTO(!must, LOGMEM(ctx), error); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1881 | *trg_must = must; |
PavolVican | 214408f | 2017-02-03 11:54:05 +0100 | [diff] [blame] | 1882 | memcpy(&(*trg_must)[*trg_must_size], deviate->must, deviate->must_size * sizeof *must); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1883 | free(deviate->must); |
| 1884 | deviate->must = &must[*trg_must_size]; |
PavolVican | 214408f | 2017-02-03 11:54:05 +0100 | [diff] [blame] | 1885 | *trg_must_size = *trg_must_size + deviate->must_size; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1886 | erase_must = 0; |
| 1887 | } else if (deviate->mod == LY_DEVIATE_DEL) { |
| 1888 | /* find must to delete, we are ok with just matching conditions */ |
| 1889 | for (j = 0; j < deviate->must_size; ++j) { |
| 1890 | for (i = 0; i < *trg_must_size; i++) { |
| 1891 | if (ly_strequal(deviate->must[j].expr, (*trg_must)[i].expr, 1)) { |
| 1892 | /* we have a match, free the must structure ... */ |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 1893 | lys_restr_free(module->ctx, &((*trg_must)[i]), NULL); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1894 | /* ... and maintain the array */ |
| 1895 | (*trg_must_size)--; |
| 1896 | if (i != *trg_must_size) { |
PavolVican | 214408f | 2017-02-03 11:54:05 +0100 | [diff] [blame] | 1897 | memcpy(&(*trg_must)[i], &(*trg_must)[*trg_must_size], sizeof *must); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1898 | } |
| 1899 | if (!(*trg_must_size)) { |
| 1900 | free(*trg_must); |
| 1901 | *trg_must = NULL; |
| 1902 | } else { |
PavolVican | 214408f | 2017-02-03 11:54:05 +0100 | [diff] [blame] | 1903 | memset(&(*trg_must)[*trg_must_size], 0, sizeof *must); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1904 | } |
| 1905 | |
| 1906 | i = -1; /* set match flag */ |
| 1907 | break; |
| 1908 | } |
| 1909 | } |
| 1910 | if (i != -1) { |
| 1911 | /* no match found */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1912 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, deviate->must[j].expr, "must"); |
| 1913 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Value does not match any must from the target."); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1914 | goto error; |
| 1915 | } |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1916 | } |
| 1917 | } |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1918 | |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 1919 | if (yang_check_must(module, deviate->must, deviate->must_size, unres)) { |
| 1920 | goto error; |
| 1921 | } |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1922 | /* check XPath dependencies */ |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 1923 | if (!(module->ctx->models.flags & LY_CTX_TRUSTED) && *trg_must_size |
| 1924 | && (unres_schema_add_node(module, unres, dev_target, UNRES_XPATH, NULL) == -1)) { |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1925 | goto error; |
| 1926 | } |
| 1927 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1928 | return EXIT_SUCCESS; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1929 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1930 | error: |
| 1931 | if (deviate->mod == LY_DEVIATE_ADD && erase_must) { |
| 1932 | for (i = 0; i < deviate->must_size; ++i) { |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 1933 | lys_restr_free(module->ctx, &deviate->must[i], NULL); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1934 | } |
| 1935 | free(deviate->must); |
| 1936 | } |
| 1937 | return EXIT_FAILURE; |
| 1938 | } |
| 1939 | |
| 1940 | int |
| 1941 | yang_deviate_delete_unique(struct lys_module *module, struct lys_deviate *deviate, |
| 1942 | struct lys_node_list *list, int index, char * value) |
| 1943 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1944 | struct ly_ctx *ctx = module->ctx; |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 1945 | int i, j, k; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1946 | |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1947 | /* find unique structures to delete */ |
| 1948 | for (i = 0; i < list->unique_size; i++) { |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1949 | if (list->unique[i].expr_size != deviate->unique[index].expr_size) { |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1950 | continue; |
| 1951 | } |
| 1952 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1953 | for (j = 0; j < deviate->unique[index].expr_size; j++) { |
| 1954 | if (!ly_strequal(list->unique[i].expr[j], deviate->unique[index].expr[j], 1)) { |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1955 | break; |
| 1956 | } |
| 1957 | } |
| 1958 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1959 | if (j == deviate->unique[index].expr_size) { |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1960 | /* we have a match, free the unique structure ... */ |
| 1961 | for (j = 0; j < list->unique[i].expr_size; j++) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1962 | lydict_remove(ctx, list->unique[i].expr[j]); |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1963 | } |
| 1964 | free(list->unique[i].expr); |
| 1965 | /* ... and maintain the array */ |
| 1966 | list->unique_size--; |
| 1967 | if (i != list->unique_size) { |
| 1968 | list->unique[i].expr_size = list->unique[list->unique_size].expr_size; |
| 1969 | list->unique[i].expr = list->unique[list->unique_size].expr; |
| 1970 | } |
| 1971 | |
| 1972 | if (!list->unique_size) { |
| 1973 | free(list->unique); |
| 1974 | list->unique = NULL; |
| 1975 | } else { |
| 1976 | list->unique[list->unique_size].expr_size = 0; |
| 1977 | list->unique[list->unique_size].expr = NULL; |
| 1978 | } |
| 1979 | |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 1980 | k = i; /* remember index for removing extensions */ |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1981 | i = -1; /* set match flag */ |
| 1982 | break; |
| 1983 | } |
| 1984 | } |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1985 | |
| 1986 | if (i != -1) { |
| 1987 | /* no match found */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1988 | LOGVAL(ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "unique"); |
| 1989 | LOGVAL(ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Value differs from the target being deleted."); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 1990 | return EXIT_FAILURE; |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 1991 | } |
| 1992 | |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 1993 | /* remove extensions of this unique instance from the target node */ |
| 1994 | j = -1; |
| 1995 | while ((j = lys_ext_iter(list->ext, list->ext_size, j + 1, LYEXT_SUBSTMT_UNIQUE)) != -1) { |
| 1996 | if (list->ext[j]->insubstmt_index == k) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 1997 | lyp_ext_instance_rm(ctx, &list->ext, &list->ext_size, j); |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 1998 | --j; |
| 1999 | } else if (list->ext[j]->insubstmt_index > k) { |
| 2000 | /* decrease the substatement index of the extension because of the changed array of uniques */ |
| 2001 | list->ext[j]->insubstmt_index--; |
| 2002 | } |
| 2003 | } |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 2004 | return EXIT_SUCCESS; |
Pavol Vican | c1f5a50 | 2016-03-06 16:51:26 +0100 | [diff] [blame] | 2005 | } |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 2006 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 2007 | int yang_check_deviate_unique(struct lys_module *module, struct lys_deviate *deviate, struct lys_node *dev_target) |
Pavol Vican | e92421d | 2016-03-08 10:12:33 +0100 | [diff] [blame] | 2008 | { |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 2009 | struct lys_node_list *list; |
| 2010 | char *str; |
PavolVican | 4b80d04 | 2017-02-23 14:30:27 +0100 | [diff] [blame] | 2011 | uint i = 0; |
| 2012 | struct lys_unique *last_unique = NULL; |
Pavol Vican | e92421d | 2016-03-08 10:12:33 +0100 | [diff] [blame] | 2013 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 2014 | if (yang_read_deviate_unique(deviate, dev_target)) { |
| 2015 | goto error; |
| 2016 | } |
| 2017 | list = (struct lys_node_list *)dev_target; |
| 2018 | last_unique = &list->unique[list->unique_size]; |
| 2019 | for (i = 0; i < deviate->unique_size; ++i) { |
| 2020 | str = (char *) deviate->unique[i].expr; |
| 2021 | if (deviate->mod == LY_DEVIATE_ADD) { |
| 2022 | if (yang_fill_unique(module, list, &list->unique[list->unique_size], str, NULL)) { |
| 2023 | free(str); |
| 2024 | goto error; |
| 2025 | } |
| 2026 | list->unique_size++; |
| 2027 | } else if (deviate->mod == LY_DEVIATE_DEL) { |
| 2028 | if (yang_fill_unique(module, list, &deviate->unique[i], str, NULL)) { |
| 2029 | free(str); |
| 2030 | goto error; |
| 2031 | } |
| 2032 | if (yang_deviate_delete_unique(module, deviate, list, i, str)) { |
| 2033 | free(str); |
| 2034 | goto error; |
Pavol Vican | e92421d | 2016-03-08 10:12:33 +0100 | [diff] [blame] | 2035 | } |
| 2036 | } |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 2037 | free(str); |
| 2038 | } |
| 2039 | if (deviate->mod == LY_DEVIATE_ADD) { |
| 2040 | free(deviate->unique); |
| 2041 | deviate->unique = last_unique; |
Pavol Vican | e92421d | 2016-03-08 10:12:33 +0100 | [diff] [blame] | 2042 | } |
Pavol Vican | 38321d0 | 2016-08-16 14:56:02 +0200 | [diff] [blame] | 2043 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 2044 | return EXIT_SUCCESS; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2045 | |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 2046 | error: |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 2047 | if (deviate->mod == LY_DEVIATE_ADD) { |
| 2048 | for (i = i + 1; i < deviate->unique_size; ++i) { |
| 2049 | free(deviate->unique[i].expr); |
| 2050 | } |
| 2051 | free(deviate->unique); |
| 2052 | deviate->unique = last_unique; |
| 2053 | |
| 2054 | } |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 2055 | return EXIT_FAILURE; |
| 2056 | } |
| 2057 | |
Pavol Vican | ec423c9 | 2016-10-24 21:33:43 +0200 | [diff] [blame] | 2058 | static int |
| 2059 | yang_fill_include(struct lys_module *trg, char *value, struct lys_include *inc, |
| 2060 | struct unres_schema *unres) |
Pavol Vican | 021488a | 2016-01-25 23:56:12 +0100 | [diff] [blame] | 2061 | { |
Pavol Vican | 5587041 | 2016-03-10 12:36:21 +0100 | [diff] [blame] | 2062 | const char *str; |
Radek Krejci | 5b2c8a8 | 2016-06-17 15:36:03 +0200 | [diff] [blame] | 2063 | int rc; |
Radek Krejci | 83e3f5b | 2016-06-24 14:55:25 +0200 | [diff] [blame] | 2064 | int ret = 0; |
Pavol Vican | 9b89dda | 2016-03-09 15:36:55 +0100 | [diff] [blame] | 2065 | |
Pavol Vican | ec423c9 | 2016-10-24 21:33:43 +0200 | [diff] [blame] | 2066 | str = lydict_insert_zc(trg->ctx, value); |
Radek Krejci | d4c1d0f | 2017-01-19 16:11:38 +0100 | [diff] [blame] | 2067 | rc = lyp_check_include(trg, str, inc, unres); |
Radek Krejci | 5b2c8a8 | 2016-06-17 15:36:03 +0200 | [diff] [blame] | 2068 | if (!rc) { |
| 2069 | /* success, copy the filled data into the final array */ |
Pavol Vican | e024ab7 | 2016-07-27 14:27:43 +0200 | [diff] [blame] | 2070 | memcpy(&trg->inc[trg->inc_size], inc, sizeof *inc); |
PavolVican | 7d0b5ab | 2017-02-01 13:06:53 +0100 | [diff] [blame] | 2071 | if (yang_check_ext_instance(trg, &trg->inc[trg->inc_size].ext, trg->inc[trg->inc_size].ext_size, |
| 2072 | &trg->inc[trg->inc_size], unres)) { |
| 2073 | ret = -1; |
| 2074 | } |
Radek Krejci | 4dcd339 | 2016-06-22 10:28:40 +0200 | [diff] [blame] | 2075 | trg->inc_size++; |
Radek Krejci | 5b2c8a8 | 2016-06-17 15:36:03 +0200 | [diff] [blame] | 2076 | } else if (rc == -1) { |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 2077 | lys_extension_instances_free(trg->ctx, inc->ext, inc->ext_size, NULL); |
Radek Krejci | 83e3f5b | 2016-06-24 14:55:25 +0200 | [diff] [blame] | 2078 | ret = -1; |
Pavol Vican | 9b89dda | 2016-03-09 15:36:55 +0100 | [diff] [blame] | 2079 | } |
Pavol Vican | 9b89dda | 2016-03-09 15:36:55 +0100 | [diff] [blame] | 2080 | |
Pavol Vican | ec423c9 | 2016-10-24 21:33:43 +0200 | [diff] [blame] | 2081 | lydict_remove(trg->ctx, str); |
Radek Krejci | 5b2c8a8 | 2016-06-17 15:36:03 +0200 | [diff] [blame] | 2082 | return ret; |
Pavol Vican | 9b89dda | 2016-03-09 15:36:55 +0100 | [diff] [blame] | 2083 | } |
Pavol Vican | f4717e6 | 2016-03-16 11:30:01 +0100 | [diff] [blame] | 2084 | |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 2085 | struct lys_ext_instance * |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 2086 | yang_ext_instance(void *node, enum yytokentype type, int is_ext_instance) |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 2087 | { |
| 2088 | struct lys_ext_instance ***ext, **tmp, *instance = NULL; |
| 2089 | LYEXT_PAR parent_type; |
| 2090 | uint8_t *size; |
| 2091 | |
| 2092 | switch (type) { |
| 2093 | case MODULE_KEYWORD: |
PavolVican | e6fa67b | 2017-02-01 11:06:57 +0100 | [diff] [blame] | 2094 | case SUBMODULE_KEYWORD: |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 2095 | ext = &((struct lys_module *)node)->ext; |
| 2096 | size = &((struct lys_module *)node)->ext_size; |
| 2097 | parent_type = LYEXT_PAR_MODULE; |
| 2098 | break; |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 2099 | case BELONGS_TO_KEYWORD: |
| 2100 | if (is_ext_instance) { |
| 2101 | ext = &((struct lys_ext_instance *)node)->ext; |
| 2102 | size = &((struct lys_ext_instance *)node)->ext_size; |
| 2103 | parent_type = LYEXT_PAR_EXTINST; |
| 2104 | } else { |
| 2105 | ext = &((struct lys_module *)node)->ext; |
| 2106 | size = &((struct lys_module *)node)->ext_size; |
| 2107 | parent_type = LYEXT_PAR_MODULE; |
| 2108 | } |
| 2109 | break; |
PavolVican | 7d0b5ab | 2017-02-01 13:06:53 +0100 | [diff] [blame] | 2110 | case IMPORT_KEYWORD: |
| 2111 | ext = &((struct lys_import *)node)->ext; |
| 2112 | size = &((struct lys_import *)node)->ext_size; |
| 2113 | parent_type = LYEXT_PAR_IMPORT; |
| 2114 | break; |
| 2115 | case INCLUDE_KEYWORD: |
| 2116 | ext = &((struct lys_include *)node)->ext; |
| 2117 | size = &((struct lys_include *)node)->ext_size; |
| 2118 | parent_type = LYEXT_PAR_INCLUDE; |
| 2119 | break; |
PavolVican | 171717d | 2017-02-01 14:49:55 +0100 | [diff] [blame] | 2120 | case REVISION_KEYWORD: |
| 2121 | ext = &((struct lys_revision *)node)->ext; |
| 2122 | size = &((struct lys_revision *)node)->ext_size; |
| 2123 | parent_type = LYEXT_PAR_REVISION; |
| 2124 | break; |
PavolVican | 70ce745 | 2017-02-01 15:39:39 +0100 | [diff] [blame] | 2125 | case GROUPING_KEYWORD: |
PavolVican | 59af9be | 2017-02-01 16:04:37 +0100 | [diff] [blame] | 2126 | case CONTAINER_KEYWORD: |
PavolVican | a6c3ac9 | 2017-02-03 13:15:13 +0100 | [diff] [blame] | 2127 | case LEAF_KEYWORD: |
| 2128 | case LEAF_LIST_KEYWORD: |
| 2129 | case LIST_KEYWORD: |
PavolVican | 91eb04a | 2017-02-03 13:45:52 +0100 | [diff] [blame] | 2130 | case CHOICE_KEYWORD: |
| 2131 | case CASE_KEYWORD: |
| 2132 | case ANYXML_KEYWORD: |
| 2133 | case ANYDATA_KEYWORD: |
PavolVican | 0759638 | 2017-02-03 14:05:12 +0100 | [diff] [blame] | 2134 | case USES_KEYWORD: |
| 2135 | case AUGMENT_KEYWORD: |
PavolVican | 97d1e6f | 2017-02-03 14:39:52 +0100 | [diff] [blame] | 2136 | case ACTION_KEYWORD: |
| 2137 | case RPC_KEYWORD: |
| 2138 | case INPUT_KEYWORD: |
| 2139 | case OUTPUT_KEYWORD: |
| 2140 | case NOTIFICATION_KEYWORD: |
PavolVican | 70ce745 | 2017-02-01 15:39:39 +0100 | [diff] [blame] | 2141 | ext = &((struct lys_node *)node)->ext; |
| 2142 | size = &((struct lys_node *)node)->ext_size; |
| 2143 | parent_type = LYEXT_PAR_NODE; |
| 2144 | break; |
PavolVican | 19dc615 | 2017-02-06 12:04:15 +0100 | [diff] [blame] | 2145 | case ARGUMENT_KEYWORD: |
PavolVican | 5080974 | 2017-02-18 21:22:54 +0100 | [diff] [blame] | 2146 | if (is_ext_instance) { |
| 2147 | ext = &((struct lys_ext_instance *)node)->ext; |
| 2148 | size = &((struct lys_ext_instance *)node)->ext_size; |
| 2149 | parent_type = LYEXT_PAR_EXTINST; |
| 2150 | } else { |
| 2151 | ext = &((struct lys_ext *)node)->ext; |
| 2152 | size = &((struct lys_ext *)node)->ext_size; |
| 2153 | parent_type = LYEXT_PAR_EXT; |
| 2154 | } |
| 2155 | break; |
PavolVican | 19dc615 | 2017-02-06 12:04:15 +0100 | [diff] [blame] | 2156 | case EXTENSION_KEYWORD: |
| 2157 | ext = &((struct lys_ext *)node)->ext; |
| 2158 | size = &((struct lys_ext *)node)->ext_size; |
| 2159 | parent_type = LYEXT_PAR_EXT; |
| 2160 | break; |
PavolVican | 5393d3f | 2017-02-06 23:30:55 +0100 | [diff] [blame] | 2161 | case FEATURE_KEYWORD: |
| 2162 | ext = &((struct lys_feature *)node)->ext; |
| 2163 | size = &((struct lys_feature *)node)->ext_size; |
| 2164 | parent_type = LYEXT_PAR_FEATURE; |
| 2165 | break; |
PavolVican | 8fa3124 | 2017-02-07 11:04:26 +0100 | [diff] [blame] | 2166 | case IDENTITY_KEYWORD: |
| 2167 | ext = &((struct lys_ident *)node)->ext; |
| 2168 | size = &((struct lys_ident *)node)->ext_size; |
| 2169 | parent_type = LYEXT_PAR_IDENT; |
| 2170 | break; |
| 2171 | case IF_FEATURE_KEYWORD: |
| 2172 | ext = &((struct lys_iffeature *)node)->ext; |
| 2173 | size = &((struct lys_iffeature *)node)->ext_size; |
| 2174 | parent_type = LYEXT_PAR_IFFEATURE; |
| 2175 | break; |
PavolVican | df9e797 | 2017-02-07 11:41:38 +0100 | [diff] [blame] | 2176 | case TYPEDEF_KEYWORD: |
| 2177 | ext = &((struct lys_tpdf *)node)->ext; |
| 2178 | size = &((struct lys_tpdf *)node)->ext_size; |
| 2179 | parent_type = LYEXT_PAR_TPDF; |
| 2180 | break; |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 2181 | case TYPE_KEYWORD: |
| 2182 | ext = &((struct yang_type *)node)->type->ext; |
| 2183 | size = &((struct yang_type *)node)->type->ext_size; |
| 2184 | parent_type = LYEXT_PAR_TYPE; |
| 2185 | break; |
| 2186 | case LENGTH_KEYWORD: |
| 2187 | case PATTERN_KEYWORD: |
| 2188 | case RANGE_KEYWORD: |
PavolVican | 38104a3 | 2017-02-08 12:25:23 +0100 | [diff] [blame] | 2189 | case MUST_KEYWORD: |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 2190 | ext = &((struct lys_restr *)node)->ext; |
| 2191 | size = &((struct lys_restr *)node)->ext_size; |
| 2192 | parent_type = LYEXT_PAR_RESTR; |
| 2193 | break; |
PavolVican | 59ba460 | 2017-02-08 11:53:32 +0100 | [diff] [blame] | 2194 | case WHEN_KEYWORD: |
| 2195 | ext = &((struct lys_when *)node)->ext; |
| 2196 | size = &((struct lys_when *)node)->ext_size; |
| 2197 | parent_type = LYEXT_PAR_RESTR; |
| 2198 | break; |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 2199 | case ENUM_KEYWORD: |
| 2200 | ext = &((struct lys_type_enum *)node)->ext; |
| 2201 | size = &((struct lys_type_enum *)node)->ext_size; |
| 2202 | parent_type = LYEXT_PAR_TYPE_ENUM; |
| 2203 | break; |
| 2204 | case BIT_KEYWORD: |
| 2205 | ext = &((struct lys_type_bit *)node)->ext; |
| 2206 | size = &((struct lys_type_bit *)node)->ext_size; |
| 2207 | parent_type = LYEXT_PAR_TYPE_BIT; |
| 2208 | break; |
PavolVican | 77374ee | 2017-02-08 15:18:45 +0100 | [diff] [blame] | 2209 | case REFINE_KEYWORD: |
| 2210 | ext = &((struct lys_type_bit *)node)->ext; |
| 2211 | size = &((struct lys_type_bit *)node)->ext_size; |
| 2212 | parent_type = LYEXT_PAR_REFINE; |
| 2213 | break; |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 2214 | case DEVIATION_KEYWORD: |
| 2215 | ext = &((struct lys_deviation *)node)->ext; |
| 2216 | size = &((struct lys_deviation *)node)->ext_size; |
| 2217 | parent_type = LYEXT_PAR_DEVIATION; |
| 2218 | break; |
| 2219 | case NOT_SUPPORTED_KEYWORD: |
| 2220 | case ADD_KEYWORD: |
| 2221 | case DELETE_KEYWORD: |
| 2222 | case REPLACE_KEYWORD: |
| 2223 | ext = &((struct lys_deviate *)node)->ext; |
| 2224 | size = &((struct lys_deviate *)node)->ext_size; |
| 2225 | parent_type = LYEXT_PAR_DEVIATE; |
| 2226 | break; |
PavolVican | defa485 | 2017-02-10 13:13:23 +0100 | [diff] [blame] | 2227 | case EXTENSION_INSTANCE: |
| 2228 | ext = &((struct lys_ext_instance *)node)->ext; |
| 2229 | size = &((struct lys_ext_instance *)node)->ext_size; |
| 2230 | parent_type = LYEXT_PAR_EXTINST; |
| 2231 | break; |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 2232 | default: |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2233 | LOGINT(NULL); |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 2234 | return NULL; |
| 2235 | } |
| 2236 | |
| 2237 | instance = calloc(1, sizeof *instance); |
| 2238 | if (!instance) { |
| 2239 | goto error; |
| 2240 | } |
| 2241 | instance->parent_type = parent_type; |
| 2242 | tmp = realloc(*ext, (*size + 1) * sizeof *tmp); |
| 2243 | if (!tmp) { |
| 2244 | goto error; |
| 2245 | } |
| 2246 | tmp[*size] = instance; |
| 2247 | *ext = tmp; |
| 2248 | (*size)++; |
| 2249 | return instance; |
| 2250 | |
| 2251 | error: |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2252 | LOGMEM(NULL); |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 2253 | free(instance); |
| 2254 | return NULL; |
| 2255 | } |
| 2256 | |
| 2257 | void * |
| 2258 | yang_read_ext(struct lys_module *module, void *actual, char *ext_name, char *ext_arg, |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 2259 | enum yytokentype actual_type, enum yytokentype backup_type, int is_ext_instance) |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 2260 | { |
| 2261 | struct lys_ext_instance *instance; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2262 | LY_STMT stmt = LY_STMT_UNKNOWN; |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 2263 | |
| 2264 | if (backup_type != NODE) { |
PavolVican | 4b80d04 | 2017-02-23 14:30:27 +0100 | [diff] [blame] | 2265 | instance = yang_ext_instance(actual, backup_type, is_ext_instance); |
PavolVican | e6fa67b | 2017-02-01 11:06:57 +0100 | [diff] [blame] | 2266 | if (!instance) { |
| 2267 | return NULL; |
| 2268 | } |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 2269 | switch (actual_type) { |
PavolVican | a4b79bc | 2017-02-08 13:47:00 +0100 | [diff] [blame] | 2270 | case YANG_VERSION_KEYWORD: |
| 2271 | instance->insubstmt = LYEXT_SUBSTMT_VERSION; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2272 | stmt = LY_STMT_VERSION; |
PavolVican | a4b79bc | 2017-02-08 13:47:00 +0100 | [diff] [blame] | 2273 | break; |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 2274 | case NAMESPACE_KEYWORD: |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2275 | instance->insubstmt = LYEXT_SUBSTMT_NAMESPACE; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2276 | stmt = LY_STMT_NAMESPACE; |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 2277 | break; |
PavolVican | e6fa67b | 2017-02-01 11:06:57 +0100 | [diff] [blame] | 2278 | case PREFIX_KEYWORD: |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2279 | instance->insubstmt = LYEXT_SUBSTMT_PREFIX; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2280 | stmt = LY_STMT_PREFIX; |
PavolVican | e6fa67b | 2017-02-01 11:06:57 +0100 | [diff] [blame] | 2281 | break; |
PavolVican | 7d0b5ab | 2017-02-01 13:06:53 +0100 | [diff] [blame] | 2282 | case REVISION_DATE_KEYWORD: |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2283 | instance->insubstmt = LYEXT_SUBSTMT_REVISIONDATE; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2284 | stmt = LY_STMT_REVISIONDATE; |
PavolVican | 7d0b5ab | 2017-02-01 13:06:53 +0100 | [diff] [blame] | 2285 | break; |
| 2286 | case DESCRIPTION_KEYWORD: |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2287 | instance->insubstmt = LYEXT_SUBSTMT_DESCRIPTION; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2288 | stmt = LY_STMT_DESCRIPTION; |
PavolVican | 7d0b5ab | 2017-02-01 13:06:53 +0100 | [diff] [blame] | 2289 | break; |
| 2290 | case REFERENCE_KEYWORD: |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2291 | instance->insubstmt = LYEXT_SUBSTMT_REFERENCE; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2292 | stmt = LY_STMT_REFERENCE; |
PavolVican | 7d0b5ab | 2017-02-01 13:06:53 +0100 | [diff] [blame] | 2293 | break; |
PavolVican | 171717d | 2017-02-01 14:49:55 +0100 | [diff] [blame] | 2294 | case CONTACT_KEYWORD: |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2295 | instance->insubstmt = LYEXT_SUBSTMT_CONTACT; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2296 | stmt = LY_STMT_CONTACT; |
PavolVican | 171717d | 2017-02-01 14:49:55 +0100 | [diff] [blame] | 2297 | break; |
| 2298 | case ORGANIZATION_KEYWORD: |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2299 | instance->insubstmt = LYEXT_SUBSTMT_ORGANIZATION; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2300 | stmt = LY_STMT_ORGANIZATION; |
PavolVican | 171717d | 2017-02-01 14:49:55 +0100 | [diff] [blame] | 2301 | break; |
PavolVican | 19dc615 | 2017-02-06 12:04:15 +0100 | [diff] [blame] | 2302 | case YIN_ELEMENT_KEYWORD: |
| 2303 | instance->insubstmt = LYEXT_SUBSTMT_YINELEM; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2304 | stmt = LY_STMT_YINELEM; |
PavolVican | 19dc615 | 2017-02-06 12:04:15 +0100 | [diff] [blame] | 2305 | break; |
| 2306 | case STATUS_KEYWORD: |
| 2307 | instance->insubstmt = LYEXT_SUBSTMT_STATUS; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2308 | stmt = LY_STMT_STATUS; |
PavolVican | 19dc615 | 2017-02-06 12:04:15 +0100 | [diff] [blame] | 2309 | break; |
PavolVican | 8fa3124 | 2017-02-07 11:04:26 +0100 | [diff] [blame] | 2310 | case BASE_KEYWORD: |
| 2311 | instance->insubstmt = LYEXT_SUBSTMT_BASE; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2312 | stmt = LY_STMT_BASE; |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 2313 | if (backup_type == IDENTITY_KEYWORD) { |
| 2314 | instance->insubstmt_index = ((struct lys_ident *)actual)->base_size; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2315 | } else if (backup_type == TYPE_KEYWORD) { |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 2316 | instance->insubstmt_index = ((struct yang_type *)actual)->type->info.ident.count; |
| 2317 | } |
PavolVican | 8fa3124 | 2017-02-07 11:04:26 +0100 | [diff] [blame] | 2318 | break; |
PavolVican | df9e797 | 2017-02-07 11:41:38 +0100 | [diff] [blame] | 2319 | case DEFAULT_KEYWORD: |
| 2320 | instance->insubstmt = LYEXT_SUBSTMT_DEFAULT; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2321 | stmt = LY_STMT_DEFAULT; |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 2322 | switch (backup_type) { |
| 2323 | case LEAF_LIST_KEYWORD: |
PavolVican | 3feb2f9 | 2017-02-08 13:44:39 +0100 | [diff] [blame] | 2324 | instance->insubstmt_index = ((struct lys_node_leaflist *)actual)->dflt_size; |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 2325 | break; |
| 2326 | case REFINE_KEYWORD: |
PavolVican | 77374ee | 2017-02-08 15:18:45 +0100 | [diff] [blame] | 2327 | instance->insubstmt_index = ((struct lys_refine *)actual)->dflt_size; |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 2328 | break; |
| 2329 | case ADD_KEYWORD: |
| 2330 | instance->insubstmt_index = ((struct lys_deviate *)actual)->dflt_size; |
| 2331 | break; |
| 2332 | default: |
| 2333 | /* nothing changes */ |
| 2334 | break; |
PavolVican | 3feb2f9 | 2017-02-08 13:44:39 +0100 | [diff] [blame] | 2335 | } |
PavolVican | df9e797 | 2017-02-07 11:41:38 +0100 | [diff] [blame] | 2336 | break; |
| 2337 | case UNITS_KEYWORD: |
| 2338 | instance->insubstmt = LYEXT_SUBSTMT_UNITS; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2339 | stmt = LY_STMT_UNITS; |
PavolVican | df9e797 | 2017-02-07 11:41:38 +0100 | [diff] [blame] | 2340 | break; |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 2341 | case REQUIRE_INSTANCE_KEYWORD: |
| 2342 | instance->insubstmt = LYEXT_SUBSTMT_REQINSTANCE; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2343 | stmt = LY_STMT_REQINSTANCE; |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 2344 | break; |
| 2345 | case PATH_KEYWORD: |
| 2346 | instance->insubstmt = LYEXT_SUBSTMT_PATH; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2347 | stmt = LY_STMT_PATH; |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 2348 | break; |
| 2349 | case ERROR_MESSAGE_KEYWORD: |
| 2350 | instance->insubstmt = LYEXT_SUBSTMT_ERRMSG; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2351 | stmt = LY_STMT_ERRMSG; |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 2352 | break; |
| 2353 | case ERROR_APP_TAG_KEYWORD: |
| 2354 | instance->insubstmt = LYEXT_SUBSTMT_ERRTAG; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2355 | stmt = LY_STMT_ERRTAG; |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 2356 | break; |
| 2357 | case MODIFIER_KEYWORD: |
| 2358 | instance->insubstmt = LYEXT_SUBSTMT_MODIFIER; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2359 | stmt = LY_STMT_MODIFIER; |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 2360 | break; |
| 2361 | case FRACTION_DIGITS_KEYWORD: |
| 2362 | instance->insubstmt = LYEXT_SUBSTMT_DIGITS; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2363 | stmt = LY_STMT_DIGITS; |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 2364 | break; |
| 2365 | case VALUE_KEYWORD: |
| 2366 | instance->insubstmt = LYEXT_SUBSTMT_VALUE; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2367 | stmt = LY_STMT_VALUE; |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 2368 | break; |
| 2369 | case POSITION_KEYWORD: |
| 2370 | instance->insubstmt = LYEXT_SUBSTMT_POSITION; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2371 | stmt = LY_STMT_POSITION; |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 2372 | break; |
PavolVican | 5b91084 | 2017-02-08 13:08:47 +0100 | [diff] [blame] | 2373 | case PRESENCE_KEYWORD: |
| 2374 | instance->insubstmt = LYEXT_SUBSTMT_PRESENCE; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2375 | stmt = LY_STMT_PRESENCE; |
PavolVican | 5b91084 | 2017-02-08 13:08:47 +0100 | [diff] [blame] | 2376 | break; |
| 2377 | case CONFIG_KEYWORD: |
| 2378 | instance->insubstmt = LYEXT_SUBSTMT_CONFIG; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2379 | stmt = LY_STMT_CONFIG; |
PavolVican | 5b91084 | 2017-02-08 13:08:47 +0100 | [diff] [blame] | 2380 | break; |
PavolVican | 3feb2f9 | 2017-02-08 13:44:39 +0100 | [diff] [blame] | 2381 | case MANDATORY_KEYWORD: |
| 2382 | instance->insubstmt = LYEXT_SUBSTMT_MANDATORY; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2383 | stmt = LY_STMT_MANDATORY; |
PavolVican | 3feb2f9 | 2017-02-08 13:44:39 +0100 | [diff] [blame] | 2384 | break; |
| 2385 | case MIN_ELEMENTS_KEYWORD: |
| 2386 | instance->insubstmt = LYEXT_SUBSTMT_MIN; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2387 | stmt = LY_STMT_MIN; |
PavolVican | 3feb2f9 | 2017-02-08 13:44:39 +0100 | [diff] [blame] | 2388 | break; |
| 2389 | case MAX_ELEMENTS_KEYWORD: |
| 2390 | instance->insubstmt = LYEXT_SUBSTMT_MAX; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2391 | stmt = LY_STMT_MAX; |
PavolVican | 3feb2f9 | 2017-02-08 13:44:39 +0100 | [diff] [blame] | 2392 | break; |
| 2393 | case ORDERED_BY_KEYWORD: |
| 2394 | instance->insubstmt = LYEXT_SUBSTMT_ORDEREDBY; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2395 | stmt = LY_STMT_ORDEREDBY; |
PavolVican | 3feb2f9 | 2017-02-08 13:44:39 +0100 | [diff] [blame] | 2396 | break; |
| 2397 | case KEY_KEYWORD: |
| 2398 | instance->insubstmt = LYEXT_SUBSTMT_KEY; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2399 | stmt = LY_STMT_KEY; |
PavolVican | 3feb2f9 | 2017-02-08 13:44:39 +0100 | [diff] [blame] | 2400 | break; |
| 2401 | case UNIQUE_KEYWORD: |
| 2402 | instance->insubstmt = LYEXT_SUBSTMT_UNIQUE; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2403 | stmt = LY_STMT_UNIQUE; |
| 2404 | switch (backup_type) { |
| 2405 | case LIST_KEYWORD: |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 2406 | instance->insubstmt_index = ((struct lys_node_list *)actual)->unique_size; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2407 | break; |
| 2408 | case ADD_KEYWORD: |
| 2409 | case DELETE_KEYWORD: |
| 2410 | case REPLACE_KEYWORD: |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 2411 | instance->insubstmt_index = ((struct lys_deviate *)actual)->unique_size; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2412 | break; |
| 2413 | default: |
| 2414 | /* nothing changes */ |
| 2415 | break; |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 2416 | } |
PavolVican | 3feb2f9 | 2017-02-08 13:44:39 +0100 | [diff] [blame] | 2417 | break; |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 2418 | default: |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2419 | LOGINT(module->ctx); |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 2420 | return NULL; |
| 2421 | } |
| 2422 | } else { |
PavolVican | 4b80d04 | 2017-02-23 14:30:27 +0100 | [diff] [blame] | 2423 | instance = yang_ext_instance(actual, actual_type, is_ext_instance); |
PavolVican | e6fa67b | 2017-02-01 11:06:57 +0100 | [diff] [blame] | 2424 | if (!instance) { |
| 2425 | return NULL; |
| 2426 | } |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 2427 | instance->insubstmt = LYEXT_SUBSTMT_SELF; |
PavolVican | 19dc615 | 2017-02-06 12:04:15 +0100 | [diff] [blame] | 2428 | switch (actual_type) { |
| 2429 | case ARGUMENT_KEYWORD: |
| 2430 | instance->insubstmt = LYEXT_SUBSTMT_ARGUMENT; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2431 | stmt = LY_STMT_ARGUMENT; |
PavolVican | 19dc615 | 2017-02-06 12:04:15 +0100 | [diff] [blame] | 2432 | break; |
PavolVican | faa4970 | 2017-02-06 12:10:59 +0100 | [diff] [blame] | 2433 | case BELONGS_TO_KEYWORD: |
| 2434 | instance->insubstmt = LYEXT_SUBSTMT_BELONGSTO; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2435 | stmt = LY_STMT_BELONGSTO; |
PavolVican | faa4970 | 2017-02-06 12:10:59 +0100 | [diff] [blame] | 2436 | break; |
PavolVican | 19dc615 | 2017-02-06 12:04:15 +0100 | [diff] [blame] | 2437 | default: |
| 2438 | instance->insubstmt = LYEXT_SUBSTMT_SELF; |
| 2439 | break; |
| 2440 | } |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 2441 | } |
| 2442 | instance->flags |= LYEXT_OPT_YANG; |
| 2443 | instance->def = (struct lys_ext *)ext_name; /* hack for UNRES */ |
| 2444 | instance->arg_value = lydict_insert_zc(module->ctx, ext_arg); |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 2445 | if (is_ext_instance && stmt != LY_STMT_UNKNOWN && instance->parent_type == LYEXT_PAR_EXTINST) { |
| 2446 | instance->insubstmt_index = yang_fill_ext_substm_index(actual, stmt, backup_type); |
| 2447 | } |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 2448 | return instance; |
| 2449 | } |
| 2450 | |
PavolVican | 05c4f9b | 2017-09-07 13:33:54 +0200 | [diff] [blame] | 2451 | static int |
| 2452 | check_status_flag(struct lys_node *node, struct lys_node *parent) |
| 2453 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2454 | struct ly_ctx *ctx = node->module->ctx; |
PavolVican | 05c4f9b | 2017-09-07 13:33:54 +0200 | [diff] [blame] | 2455 | char *str; |
| 2456 | |
Radek Krejci | e4dce29 | 2017-10-30 11:16:47 +0100 | [diff] [blame] | 2457 | if (node->nodetype & (LYS_OUTPUT | LYS_INPUT)) { |
| 2458 | return EXIT_SUCCESS; |
| 2459 | } |
| 2460 | |
PavolVican | 05c4f9b | 2017-09-07 13:33:54 +0200 | [diff] [blame] | 2461 | if (parent && (parent->flags & (LYS_STATUS_DEPRC | LYS_STATUS_OBSLT))) { |
| 2462 | /* status is not inherited by specification, but it not make sense to have |
| 2463 | * current in deprecated or deprecated in obsolete, so we print warning |
| 2464 | * and fix the schema by inheriting */ |
| 2465 | if (!(node->flags & (LYS_STATUS_MASK))) { |
| 2466 | /* status not explicitely specified on the current node -> inherit */ |
Michal Vasko | 395b0a0 | 2018-01-22 09:36:20 +0100 | [diff] [blame] | 2467 | str = lys_path(node, LYS_PATH_FIRST_PREFIX); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2468 | LOGWRN(ctx, "Missing status in %s subtree (%s), inheriting.", |
PavolVican | 05c4f9b | 2017-09-07 13:33:54 +0200 | [diff] [blame] | 2469 | parent->flags & LYS_STATUS_DEPRC ? "deprecated" : "obsolete", str); |
| 2470 | free(str); |
| 2471 | node->flags |= parent->flags & LYS_STATUS_MASK; |
| 2472 | } else if ((parent->flags & LYS_STATUS_MASK) > (node->flags & LYS_STATUS_MASK)) { |
| 2473 | /* invalid combination of statuses */ |
| 2474 | switch (node->flags & LYS_STATUS_MASK) { |
| 2475 | case 0: |
| 2476 | case LYS_STATUS_CURR: |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2477 | LOGVAL(ctx, LYE_INSTATUS, LY_VLOG_LYS, parent, "current", strnodetype(node->nodetype), "is child of", |
PavolVican | 05c4f9b | 2017-09-07 13:33:54 +0200 | [diff] [blame] | 2478 | parent->flags & LYS_STATUS_DEPRC ? "deprecated" : "obsolete", parent->name); |
| 2479 | break; |
| 2480 | case LYS_STATUS_DEPRC: |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2481 | LOGVAL(ctx, LYE_INSTATUS, LY_VLOG_LYS, parent, "deprecated", strnodetype(node->nodetype), "is child of", |
PavolVican | 05c4f9b | 2017-09-07 13:33:54 +0200 | [diff] [blame] | 2482 | "obsolete", parent->name); |
| 2483 | break; |
| 2484 | } |
| 2485 | return EXIT_FAILURE; |
| 2486 | } |
| 2487 | } |
| 2488 | |
| 2489 | return EXIT_SUCCESS; |
| 2490 | } |
| 2491 | |
Pavol Vican | f4717e6 | 2016-03-16 11:30:01 +0100 | [diff] [blame] | 2492 | int |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 2493 | store_config_flag(struct lys_node *node, int options) |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2494 | { |
Pavol Vican | ec59881 | 2016-11-30 14:13:38 +0100 | [diff] [blame] | 2495 | switch (node->nodetype) { |
| 2496 | case LYS_CONTAINER: |
| 2497 | case LYS_LEAF: |
| 2498 | case LYS_LEAFLIST: |
| 2499 | case LYS_LIST: |
| 2500 | case LYS_CHOICE: |
| 2501 | case LYS_ANYDATA: |
| 2502 | case LYS_ANYXML: |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 2503 | if (options & LYS_PARSE_OPT_CFG_IGNORE) { |
Pavol Vican | ec59881 | 2016-11-30 14:13:38 +0100 | [diff] [blame] | 2504 | node->flags |= node->flags & (~(LYS_CONFIG_MASK | LYS_CONFIG_SET)); |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 2505 | } else if (!(options & LYS_PARSE_OPT_CFG_NOINHERIT)) { |
Pavol Vican | ec59881 | 2016-11-30 14:13:38 +0100 | [diff] [blame] | 2506 | if (!(node->flags & LYS_CONFIG_MASK)) { |
| 2507 | /* get config flag from parent */ |
| 2508 | if (node->parent) { |
| 2509 | node->flags |= node->parent->flags & LYS_CONFIG_MASK; |
| 2510 | } else { |
| 2511 | /* default config is true */ |
| 2512 | node->flags |= LYS_CONFIG_W; |
| 2513 | } |
Pavol Vican | c54a8f7 | 2016-11-23 16:45:55 +0100 | [diff] [blame] | 2514 | } |
| 2515 | } |
Pavol Vican | ec59881 | 2016-11-30 14:13:38 +0100 | [diff] [blame] | 2516 | break; |
| 2517 | case LYS_CASE: |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 2518 | if (!(options & (LYS_PARSE_OPT_CFG_IGNORE | LYS_PARSE_OPT_CFG_NOINHERIT))) { |
Pavol Vican | ec59881 | 2016-11-30 14:13:38 +0100 | [diff] [blame] | 2519 | if (!(node->flags & LYS_CONFIG_MASK)) { |
| 2520 | /* get config flag from parent */ |
| 2521 | if (node->parent) { |
| 2522 | node->flags |= node->parent->flags & LYS_CONFIG_MASK; |
| 2523 | } else { |
| 2524 | /* default config is true */ |
| 2525 | node->flags |= LYS_CONFIG_W; |
| 2526 | } |
| 2527 | } |
| 2528 | } |
| 2529 | break; |
Pavol Vican | ec59881 | 2016-11-30 14:13:38 +0100 | [diff] [blame] | 2530 | default: |
| 2531 | break; |
Pavol Vican | 1938d88 | 2016-04-10 13:36:31 +0200 | [diff] [blame] | 2532 | } |
Pavol Vican | ec59881 | 2016-11-30 14:13:38 +0100 | [diff] [blame] | 2533 | |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 2534 | return EXIT_SUCCESS; |
Pavol Vican | 1938d88 | 2016-04-10 13:36:31 +0200 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | int |
Pavol Vican | 9d50a77 | 2016-10-14 22:23:36 +0200 | [diff] [blame] | 2538 | yang_parse_mem(struct lys_module *module, struct lys_submodule *submodule, struct unres_schema *unres, |
| 2539 | const char *data, unsigned int size_data, struct lys_node **node) |
Pavol Vican | 1938d88 | 2016-04-10 13:36:31 +0200 | [diff] [blame] | 2540 | { |
Pavol Vican | 974377b | 2016-03-23 00:38:53 +0100 | [diff] [blame] | 2541 | unsigned int size; |
Pavol Vican | 4fb66c9 | 2016-03-17 10:32:27 +0100 | [diff] [blame] | 2542 | YY_BUFFER_STATE bp; |
| 2543 | yyscan_t scanner = NULL; |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 2544 | int ret = 0; |
Pavol Vican | 082afd0 | 2016-10-25 12:39:15 +0200 | [diff] [blame] | 2545 | struct lys_module *trg; |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 2546 | struct yang_parameter param; |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2547 | |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2548 | size = (size_data) ? size_data : strlen(data) + 2; |
Pavol Vican | 4fb66c9 | 2016-03-17 10:32:27 +0100 | [diff] [blame] | 2549 | yylex_init(&scanner); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2550 | yyset_extra(module->ctx, scanner); |
Pavol Vican | 4fb66c9 | 2016-03-17 10:32:27 +0100 | [diff] [blame] | 2551 | bp = yy_scan_buffer((char *)data, size, scanner); |
| 2552 | yy_switch_to_buffer(bp, scanner); |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 2553 | memset(¶m, 0, sizeof param); |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 2554 | param.module = module; |
| 2555 | param.submodule = submodule; |
| 2556 | param.unres = unres; |
| 2557 | param.node = node; |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 2558 | param.flags |= YANG_REMOVE_IMPORT; |
PavolVican | 196694c | 2017-01-27 10:33:09 +0100 | [diff] [blame] | 2559 | if (yyparse(scanner, ¶m)) { |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 2560 | if (param.flags & YANG_REMOVE_IMPORT) { |
Pavol Vican | 082afd0 | 2016-10-25 12:39:15 +0200 | [diff] [blame] | 2561 | trg = (submodule) ? (struct lys_module *)submodule : module; |
| 2562 | yang_free_import(trg->ctx, trg->imp, 0, trg->imp_size); |
| 2563 | yang_free_include(trg->ctx, trg->inc, 0, trg->inc_size); |
| 2564 | trg->inc_size = 0; |
| 2565 | trg->imp_size = 0; |
| 2566 | } |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 2567 | ret = (param.flags & YANG_EXIST_MODULE) ? 1 : -1; |
| 2568 | } |
| 2569 | yy_delete_buffer(bp, scanner); |
| 2570 | yylex_destroy(scanner); |
| 2571 | return ret; |
| 2572 | } |
| 2573 | |
| 2574 | int |
| 2575 | yang_parse_ext_substatement(struct lys_module *module, struct unres_schema *unres, const char *data, |
| 2576 | char *ext_name, struct lys_ext_instance_complex *ext) |
| 2577 | { |
| 2578 | unsigned int size; |
| 2579 | YY_BUFFER_STATE bp; |
| 2580 | yyscan_t scanner = NULL; |
| 2581 | int ret = 0; |
| 2582 | struct yang_parameter param; |
PavolVican | f3091bf | 2017-02-19 18:27:01 +0100 | [diff] [blame] | 2583 | struct lys_node *node = NULL; |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 2584 | |
PavolVican | db0e817 | 2017-02-20 00:46:09 +0100 | [diff] [blame] | 2585 | if (!data) { |
| 2586 | return EXIT_SUCCESS; |
| 2587 | } |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 2588 | size = strlen(data) + 2; |
| 2589 | yylex_init(&scanner); |
| 2590 | bp = yy_scan_buffer((char *)data, size, scanner); |
| 2591 | yy_switch_to_buffer(bp, scanner); |
| 2592 | memset(¶m, 0, sizeof param); |
| 2593 | param.module = module; |
| 2594 | param.unres = unres; |
PavolVican | f3091bf | 2017-02-19 18:27:01 +0100 | [diff] [blame] | 2595 | param.node = &node; |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 2596 | param.actual_node = (void **)ext; |
| 2597 | param.data_node = (void **)ext_name; |
| 2598 | param.flags |= EXT_INSTANCE_SUBSTMT; |
| 2599 | if (yyparse(scanner, ¶m)) { |
PavolVican | f3091bf | 2017-02-19 18:27:01 +0100 | [diff] [blame] | 2600 | yang_free_nodes(module->ctx, node); |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 2601 | ret = -1; |
PavolVican | f3091bf | 2017-02-19 18:27:01 +0100 | [diff] [blame] | 2602 | } else { |
| 2603 | /* success parse, but it needs some sematic controls */ |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 2604 | if (node && yang_check_nodes(module, (struct lys_node *)ext, node, LYS_PARSE_OPT_CFG_NOINHERIT, unres)) { |
PavolVican | f3091bf | 2017-02-19 18:27:01 +0100 | [diff] [blame] | 2605 | ret = -1; |
| 2606 | } |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2607 | } |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2608 | yy_delete_buffer(bp, scanner); |
| 2609 | yylex_destroy(scanner); |
Pavol Vican | 1938d88 | 2016-04-10 13:36:31 +0200 | [diff] [blame] | 2610 | return ret; |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2611 | } |
| 2612 | |
| 2613 | struct lys_module * |
Pavol Vican | 974377b | 2016-03-23 00:38:53 +0100 | [diff] [blame] | 2614 | yang_read_module(struct ly_ctx *ctx, const char* data, unsigned int size, const char *revision, int implement) |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2615 | { |
| 2616 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 2617 | struct lys_module *module = NULL, *tmp_mod; |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2618 | struct unres_schema *unres = NULL; |
Pavol Vican | 9d50a77 | 2016-10-14 22:23:36 +0200 | [diff] [blame] | 2619 | struct lys_node *node = NULL; |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 2620 | int ret; |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2621 | |
| 2622 | unres = calloc(1, sizeof *unres); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2623 | LY_CHECK_ERR_GOTO(!unres, LOGMEM(ctx), error); |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2624 | |
| 2625 | module = calloc(1, sizeof *module); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2626 | LY_CHECK_ERR_GOTO(!module, LOGMEM(ctx), error); |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2627 | |
| 2628 | /* initiale module */ |
Michal Vasko | fe7e5a7 | 2016-05-02 14:49:23 +0200 | [diff] [blame] | 2629 | module->ctx = ctx; |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2630 | module->type = 0; |
| 2631 | module->implemented = (implement ? 1 : 0); |
| 2632 | |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 2633 | /* add into the list of processed modules */ |
| 2634 | if (lyp_check_circmod_add(module)) { |
| 2635 | goto error; |
| 2636 | } |
| 2637 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 2638 | ret = yang_parse_mem(module, NULL, unres, data, size, &node); |
| 2639 | if (ret == -1) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2640 | if (ly_vecode(ctx) == LYVE_SUBMODULE) { |
Radek Krejci | 95e00a4 | 2017-11-02 16:29:22 +0100 | [diff] [blame] | 2641 | free(module); |
| 2642 | module = NULL; |
| 2643 | } else { |
| 2644 | free_yang_common(module, node); |
| 2645 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 2646 | goto error; |
Michal Vasko | 7b460e5 | 2017-02-10 14:50:26 +0100 | [diff] [blame] | 2647 | } else if (ret == 1) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 2648 | assert(!unres->count); |
| 2649 | } else { |
| 2650 | if (yang_check_sub_module(module, unres, node)) { |
| 2651 | goto error; |
| 2652 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 2653 | |
Michal Vasko | 0f43706 | 2018-06-08 15:52:39 +0200 | [diff] [blame] | 2654 | if (!implement && module->implemented && lys_make_implemented_r(module, unres)) { |
| 2655 | goto error; |
| 2656 | } |
| 2657 | |
Michal Vasko | 7b460e5 | 2017-02-10 14:50:26 +0100 | [diff] [blame] | 2658 | if (unres->count && resolve_unres_schema(module, unres)) { |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 2659 | goto error; |
| 2660 | } |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2661 | } |
| 2662 | |
PavolVican | fe83b15 | 2017-02-19 03:19:29 +0100 | [diff] [blame] | 2663 | lyp_sort_revisions(module); |
| 2664 | |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2665 | if (revision) { |
| 2666 | /* check revision of the parsed model */ |
| 2667 | if (!module->rev_size || strcmp(revision, module->rev[0].date)) { |
| 2668 | LOGVRB("Module \"%s\" parsed with the wrong revision (\"%s\" instead \"%s\").", |
| 2669 | module->name, module->rev[0].date, revision); |
| 2670 | goto error; |
| 2671 | } |
| 2672 | } |
| 2673 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 2674 | /* add into context if not already there */ |
| 2675 | if (!ret) { |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame] | 2676 | /* check correctness of includes */ |
| 2677 | if (lyp_check_include_missing(module)) { |
Michal Vasko | 2605575 | 2016-05-03 11:36:31 +0200 | [diff] [blame] | 2678 | goto error; |
| 2679 | } |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame] | 2680 | |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 2681 | if (lyp_rfn_apply_ext(module) || lyp_deviation_apply_ext(module)) { |
Michal Vasko | e8c73dd | 2017-02-10 11:34:17 +0100 | [diff] [blame] | 2682 | goto error; |
| 2683 | } |
| 2684 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 2685 | if (lyp_ctx_add_module(module)) { |
Michal Vasko | 7da5b0b | 2016-05-02 16:36:59 +0200 | [diff] [blame] | 2686 | goto error; |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 2687 | } |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 2688 | |
Michal Vasko | 10681e8 | 2018-01-16 14:54:16 +0100 | [diff] [blame] | 2689 | /* remove our submodules from the parsed submodules list */ |
| 2690 | lyp_del_includedup(module, 0); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 2691 | } else { |
| 2692 | tmp_mod = module; |
| 2693 | |
| 2694 | /* get the model from the context */ |
Radek Krejci | dfb00d6 | 2017-09-06 09:39:35 +0200 | [diff] [blame] | 2695 | module = (struct lys_module *)ly_ctx_get_module(ctx, module->name, revision, 0); |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 2696 | assert(module); |
| 2697 | |
| 2698 | /* free what was parsed */ |
Michal Vasko | 10681e8 | 2018-01-16 14:54:16 +0100 | [diff] [blame] | 2699 | lys_free(tmp_mod, NULL, 0, 0); |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 2700 | } |
| 2701 | |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 2702 | lyp_check_circmod_pop(ctx); |
Michal Vasko | 181b767 | 2018-04-23 12:03:44 +0200 | [diff] [blame] | 2703 | unres_schema_free(NULL, &unres, 0); |
Michal Vasko | be136f6 | 2017-09-21 12:08:39 +0200 | [diff] [blame] | 2704 | LOGVRB("Module \"%s%s%s\" successfully parsed as %s.", module->name, (module->rev_size ? "@" : ""), |
| 2705 | (module->rev_size ? module->rev[0].date : ""), (module->implemented ? "implemented" : "imported")); |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2706 | return module; |
| 2707 | |
| 2708 | error: |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 2709 | /* cleanup */ |
Michal Vasko | 181b767 | 2018-04-23 12:03:44 +0200 | [diff] [blame] | 2710 | lyp_check_circmod_pop(ctx); |
Michal Vasko | 44ab146 | 2017-05-18 13:18:36 +0200 | [diff] [blame] | 2711 | unres_schema_free(module, &unres, 1); |
Radek Krejci | f505cd1 | 2017-06-13 10:32:48 +0200 | [diff] [blame] | 2712 | if (!module) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2713 | if (ly_vecode(ctx) != LYVE_SUBMODULE) { |
| 2714 | LOGERR(ctx, ly_errno, "Module parsing failed."); |
Radek Krejci | 48cfa0f | 2016-11-08 19:18:34 +0100 | [diff] [blame] | 2715 | } |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2716 | return NULL; |
| 2717 | } |
| 2718 | |
Radek Krejci | f505cd1 | 2017-06-13 10:32:48 +0200 | [diff] [blame] | 2719 | if (module->name) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2720 | LOGERR(ctx, ly_errno, "Module \"%s\" parsing failed.", module->name); |
Radek Krejci | f505cd1 | 2017-06-13 10:32:48 +0200 | [diff] [blame] | 2721 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2722 | LOGERR(ctx, ly_errno, "Module parsing failed."); |
Radek Krejci | f505cd1 | 2017-06-13 10:32:48 +0200 | [diff] [blame] | 2723 | } |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 2724 | |
| 2725 | lys_sub_module_remove_devs_augs(module); |
Michal Vasko | 10681e8 | 2018-01-16 14:54:16 +0100 | [diff] [blame] | 2726 | lyp_del_includedup(module, 1); |
| 2727 | lys_free(module, NULL, 0, 1); |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2728 | return NULL; |
| 2729 | } |
| 2730 | |
| 2731 | struct lys_submodule * |
Pavol Vican | 974377b | 2016-03-23 00:38:53 +0100 | [diff] [blame] | 2732 | yang_read_submodule(struct lys_module *module, const char *data, unsigned int size, struct unres_schema *unres) |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2733 | { |
| 2734 | struct lys_submodule *submodule; |
Pavol Vican | 9d50a77 | 2016-10-14 22:23:36 +0200 | [diff] [blame] | 2735 | struct lys_node *node = NULL; |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2736 | |
| 2737 | submodule = calloc(1, sizeof *submodule); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2738 | LY_CHECK_ERR_GOTO(!submodule, LOGMEM(module->ctx), error); |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2739 | |
| 2740 | submodule->ctx = module->ctx; |
| 2741 | submodule->type = 1; |
Radek Krejci | 29eac3d | 2017-06-01 16:50:02 +0200 | [diff] [blame] | 2742 | submodule->implemented = module->implemented; |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2743 | submodule->belongsto = module; |
| 2744 | |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 2745 | /* add into the list of processed modules */ |
| 2746 | if (lyp_check_circmod_add((struct lys_module *)submodule)) { |
| 2747 | goto error; |
| 2748 | } |
| 2749 | |
PavolVican | 9e81c6a | 2017-02-09 13:09:07 +0100 | [diff] [blame] | 2750 | /* module cannot be changed in this case and 1 cannot be returned */ |
Pavol Vican | 9d50a77 | 2016-10-14 22:23:36 +0200 | [diff] [blame] | 2751 | if (yang_parse_mem(module, submodule, unres, data, size, &node)) { |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 2752 | free_yang_common((struct lys_module *)submodule, node); |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 2753 | goto error; |
| 2754 | } |
| 2755 | |
PavolVican | fe83b15 | 2017-02-19 03:19:29 +0100 | [diff] [blame] | 2756 | lyp_sort_revisions((struct lys_module *)submodule); |
| 2757 | |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 2758 | if (yang_check_sub_module((struct lys_module *)submodule, unres, node)) { |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2759 | goto error; |
| 2760 | } |
| 2761 | |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 2762 | lyp_check_circmod_pop(module->ctx); |
| 2763 | |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2764 | LOGVRB("Submodule \"%s\" successfully parsed.", submodule->name); |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2765 | return submodule; |
| 2766 | |
| 2767 | error: |
| 2768 | /* cleanup */ |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2769 | if (!submodule || !submodule->name) { |
| 2770 | free(submodule); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2771 | LOGERR(module->ctx, ly_errno, "Submodule parsing failed."); |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2772 | return NULL; |
| 2773 | } |
| 2774 | |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2775 | LOGERR(module->ctx, ly_errno, "Submodule \"%s\" parsing failed.", submodule->name); |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2776 | |
Michal Vasko | a972812 | 2018-01-16 14:00:13 +0100 | [diff] [blame] | 2777 | unres_schema_free((struct lys_module *)submodule, &unres, 0); |
Radek Krejci | 9e757e0 | 2017-03-08 17:18:09 +0100 | [diff] [blame] | 2778 | lyp_check_circmod_pop(module->ctx); |
Michal Vasko | 9eb6dd0 | 2016-05-02 14:52:40 +0200 | [diff] [blame] | 2779 | lys_sub_module_remove_devs_augs((struct lys_module *)submodule); |
| 2780 | lys_submodule_module_data_free(submodule); |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2781 | lys_submodule_free(submodule, NULL); |
Pavol Vican | 8e7110b | 2016-03-22 17:00:26 +0100 | [diff] [blame] | 2782 | return NULL; |
| 2783 | } |
Pavol Vican | 8760bb7 | 2016-04-07 09:44:01 +0200 | [diff] [blame] | 2784 | |
| 2785 | static int |
Pavol Vican | 8760bb7 | 2016-04-07 09:44:01 +0200 | [diff] [blame] | 2786 | read_indent(const char *input, int indent, int size, int in_index, int *out_index, char *output) |
| 2787 | { |
| 2788 | int k = 0, j; |
| 2789 | |
| 2790 | while (in_index < size) { |
| 2791 | if (input[in_index] == ' ') { |
| 2792 | k++; |
| 2793 | } else if (input[in_index] == '\t') { |
| 2794 | /* RFC 6020 6.1.3 tab character is treated as 8 space characters */ |
| 2795 | k += 8; |
Pavol Vican | 0fbb57b | 2016-09-27 21:46:12 +0200 | [diff] [blame] | 2796 | } else if (input[in_index] == '\\' && input[in_index + 1] == 't') { |
| 2797 | /* RFC 6020 6.1.3 tab character is treated as 8 space characters */ |
| 2798 | k += 8; |
| 2799 | ++in_index; |
Pavol Vican | 8760bb7 | 2016-04-07 09:44:01 +0200 | [diff] [blame] | 2800 | } else { |
| 2801 | break; |
| 2802 | } |
| 2803 | ++in_index; |
| 2804 | if (k >= indent) { |
| 2805 | for (j = k - indent; j > 0; --j) { |
| 2806 | output[*out_index] = ' '; |
Pavol Vican | a7bf337 | 2016-12-01 15:58:18 +0100 | [diff] [blame] | 2807 | if (j > 1) { |
| 2808 | ++(*out_index); |
| 2809 | } |
Pavol Vican | 8760bb7 | 2016-04-07 09:44:01 +0200 | [diff] [blame] | 2810 | } |
| 2811 | break; |
| 2812 | } |
| 2813 | } |
Pavol Vican | 0fbb57b | 2016-09-27 21:46:12 +0200 | [diff] [blame] | 2814 | return in_index - 1; |
Pavol Vican | 8760bb7 | 2016-04-07 09:44:01 +0200 | [diff] [blame] | 2815 | } |
| 2816 | |
| 2817 | char * |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2818 | yang_read_string(struct ly_ctx *ctx, const char *input, char *output, int size, int offset, int indent) |
| 2819 | { |
Pavol Vican | 3f59889 | 2016-09-28 15:41:07 +0200 | [diff] [blame] | 2820 | int i = 0, out_index = offset, space = 0; |
Pavol Vican | 8760bb7 | 2016-04-07 09:44:01 +0200 | [diff] [blame] | 2821 | |
Pavol Vican | 0fbb57b | 2016-09-27 21:46:12 +0200 | [diff] [blame] | 2822 | while (i < size) { |
| 2823 | switch (input[i]) { |
| 2824 | case '\n': |
| 2825 | out_index -= space; |
| 2826 | output[out_index] = '\n'; |
| 2827 | space = 0; |
| 2828 | i = read_indent(input, indent, size, i + 1, &out_index, output); |
| 2829 | break; |
| 2830 | case ' ': |
| 2831 | case '\t': |
| 2832 | output[out_index] = input[i]; |
| 2833 | ++space; |
| 2834 | break; |
| 2835 | case '\\': |
| 2836 | if (input[i + 1] == 'n') { |
| 2837 | out_index -= space; |
| 2838 | output[out_index] = '\n'; |
| 2839 | space = 0; |
| 2840 | i = read_indent(input, indent, size, i + 2, &out_index, output); |
| 2841 | } else if (input[i + 1] == 't') { |
| 2842 | output[out_index] = '\t'; |
| 2843 | ++i; |
| 2844 | ++space; |
| 2845 | } else if (input[i + 1] == '\\') { |
| 2846 | output[out_index] = '\\'; |
| 2847 | ++i; |
| 2848 | } else if ((i + 1) != size && input[i + 1] == '"') { |
| 2849 | output[out_index] = '"'; |
| 2850 | ++i; |
Pavol Vican | 8760bb7 | 2016-04-07 09:44:01 +0200 | [diff] [blame] | 2851 | } else { |
PavolVican | 1bc2206 | 2017-01-19 15:09:04 +0100 | [diff] [blame] | 2852 | /* backslash must not be followed by any other character */ |
Michal Vasko | c8f80a6 | 2018-02-16 12:32:00 +0100 | [diff] [blame] | 2853 | LOGVAL(ctx, LYE_XML_INCHAR, LY_VLOG_NONE, NULL, input + i); |
PavolVican | 1bc2206 | 2017-01-19 15:09:04 +0100 | [diff] [blame] | 2854 | return NULL; |
Pavol Vican | 8760bb7 | 2016-04-07 09:44:01 +0200 | [diff] [blame] | 2855 | } |
Pavol Vican | 0fbb57b | 2016-09-27 21:46:12 +0200 | [diff] [blame] | 2856 | break; |
| 2857 | default: |
| 2858 | output[out_index] = input[i]; |
| 2859 | space = 0; |
| 2860 | break; |
Pavol Vican | 8760bb7 | 2016-04-07 09:44:01 +0200 | [diff] [blame] | 2861 | } |
Pavol Vican | 0fbb57b | 2016-09-27 21:46:12 +0200 | [diff] [blame] | 2862 | ++i; |
Pavol Vican | 8760bb7 | 2016-04-07 09:44:01 +0200 | [diff] [blame] | 2863 | ++out_index; |
| 2864 | } |
Pavol Vican | 0fbb57b | 2016-09-27 21:46:12 +0200 | [diff] [blame] | 2865 | output[out_index] = '\0'; |
| 2866 | if (size != out_index) { |
Pavol Vican | 3f59889 | 2016-09-28 15:41:07 +0200 | [diff] [blame] | 2867 | output = realloc(output, out_index + 1); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 2868 | LY_CHECK_ERR_RETURN(!output, LOGMEM(ctx), NULL); |
Pavol Vican | 8760bb7 | 2016-04-07 09:44:01 +0200 | [diff] [blame] | 2869 | } |
Pavol Vican | 3f59889 | 2016-09-28 15:41:07 +0200 | [diff] [blame] | 2870 | return output; |
Pavol Vican | 8760bb7 | 2016-04-07 09:44:01 +0200 | [diff] [blame] | 2871 | } |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 2872 | |
| 2873 | /* free function */ |
| 2874 | |
PavolVican | a0fdbf3 | 2017-02-15 17:59:02 +0100 | [diff] [blame] | 2875 | void |
| 2876 | yang_type_free(struct ly_ctx *ctx, struct lys_type *type) |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 2877 | { |
| 2878 | struct yang_type *stype = (struct yang_type *)type->der; |
Radek Krejci | dce5f97 | 2017-09-12 15:47:49 +0200 | [diff] [blame] | 2879 | unsigned int i; |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 2880 | |
| 2881 | if (!stype) { |
| 2882 | return ; |
| 2883 | } |
Michal Vasko | 70bf8e5 | 2018-03-26 11:32:33 +0200 | [diff] [blame] | 2884 | if (type->base == LY_TYPE_DER || type->base == LY_TYPE_UNION) { |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 2885 | lydict_remove(ctx, stype->name); |
| 2886 | if (stype->base == LY_TYPE_IDENT && (!(stype->flags & LYS_NO_ERASE_IDENTITY))) { |
| 2887 | for (i = 0; i < type->info.ident.count; ++i) { |
| 2888 | free(type->info.ident.ref[i]); |
| 2889 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 2890 | } |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 2891 | if (stype->base == LY_TYPE_UNION) { |
| 2892 | for (i = 0; i < type->info.uni.count; ++i) { |
| 2893 | yang_type_free(ctx, &type->info.uni.types[i]); |
| 2894 | } |
| 2895 | free(type->info.uni.types); |
| 2896 | type->base = LY_TYPE_DER; |
| 2897 | } else { |
| 2898 | type->base = stype->base; |
| 2899 | } |
| 2900 | free(stype); |
| 2901 | type->der = NULL; |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 2902 | } |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 2903 | lys_type_free(ctx, type, NULL); |
Radek Krejci | 0ec2cc5 | 2017-11-09 16:30:12 +0100 | [diff] [blame] | 2904 | memset(type, 0, sizeof (struct lys_type)); |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 2905 | } |
| 2906 | |
| 2907 | static void |
Radek Krejci | a2ac926 | 2017-09-12 16:39:04 +0200 | [diff] [blame] | 2908 | yang_tpdf_free(struct ly_ctx *ctx, struct lys_tpdf *tpdf, uint16_t start, uint16_t size) |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 2909 | { |
| 2910 | uint8_t i; |
| 2911 | |
| 2912 | assert(ctx); |
| 2913 | if (!tpdf) { |
| 2914 | return; |
| 2915 | } |
| 2916 | |
| 2917 | for (i = start; i < size; ++i) { |
Pavol Vican | cee1080 | 2016-11-22 15:48:35 +0100 | [diff] [blame] | 2918 | lydict_remove(ctx, tpdf[i].name); |
| 2919 | lydict_remove(ctx, tpdf[i].dsc); |
| 2920 | lydict_remove(ctx, tpdf[i].ref); |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 2921 | |
Pavol Vican | cee1080 | 2016-11-22 15:48:35 +0100 | [diff] [blame] | 2922 | yang_type_free(ctx, &tpdf[i].type); |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 2923 | |
Pavol Vican | cee1080 | 2016-11-22 15:48:35 +0100 | [diff] [blame] | 2924 | lydict_remove(ctx, tpdf[i].units); |
| 2925 | lydict_remove(ctx, tpdf[i].dflt); |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 2926 | lys_extension_instances_free(ctx, tpdf[i].ext, tpdf[i].ext_size, NULL); |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 2927 | } |
| 2928 | } |
| 2929 | |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 2930 | static void |
| 2931 | yang_free_import(struct ly_ctx *ctx, struct lys_import *imp, uint8_t start, uint8_t size) |
| 2932 | { |
| 2933 | uint8_t i; |
| 2934 | |
| 2935 | for (i = start; i < size; ++i){ |
| 2936 | free((char *)imp[i].module); |
| 2937 | lydict_remove(ctx, imp[i].prefix); |
| 2938 | lydict_remove(ctx, imp[i].dsc); |
| 2939 | lydict_remove(ctx, imp[i].ref); |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 2940 | lys_extension_instances_free(ctx, imp[i].ext, imp[i].ext_size, NULL); |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 2941 | } |
| 2942 | } |
| 2943 | |
Pavol Vican | ec423c9 | 2016-10-24 21:33:43 +0200 | [diff] [blame] | 2944 | static void |
| 2945 | yang_free_include(struct ly_ctx *ctx, struct lys_include *inc, uint8_t start, uint8_t size) |
| 2946 | { |
| 2947 | uint8_t i; |
| 2948 | |
| 2949 | for (i = start; i < size; ++i){ |
| 2950 | free((char *)inc[i].submodule); |
| 2951 | lydict_remove(ctx, inc[i].dsc); |
| 2952 | lydict_remove(ctx, inc[i].ref); |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 2953 | lys_extension_instances_free(ctx, inc[i].ext, inc[i].ext_size, NULL); |
Pavol Vican | ec423c9 | 2016-10-24 21:33:43 +0200 | [diff] [blame] | 2954 | } |
| 2955 | } |
| 2956 | |
Pavol Vican | 36e2727 | 2016-11-22 15:47:28 +0100 | [diff] [blame] | 2957 | static void |
| 2958 | yang_free_ident_base(struct lys_ident *ident, uint32_t start, uint32_t size) |
| 2959 | { |
| 2960 | uint32_t i; |
| 2961 | uint8_t j; |
| 2962 | |
| 2963 | /* free base name */ |
| 2964 | for (i = start; i < size; ++i) { |
| 2965 | for (j = 0; j < ident[i].base_size; ++j) { |
| 2966 | free(ident[i].base[j]); |
| 2967 | } |
| 2968 | } |
| 2969 | } |
| 2970 | |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 2971 | static void |
| 2972 | yang_free_grouping(struct ly_ctx *ctx, struct lys_node_grp * grp) |
| 2973 | { |
| 2974 | yang_tpdf_free(ctx, grp->tpdf, 0, grp->tpdf_size); |
| 2975 | free(grp->tpdf); |
| 2976 | } |
| 2977 | |
| 2978 | static void |
Pavol Vican | c54a8f7 | 2016-11-23 16:45:55 +0100 | [diff] [blame] | 2979 | yang_free_container(struct ly_ctx *ctx, struct lys_node_container * cont) |
| 2980 | { |
| 2981 | uint8_t i; |
| 2982 | |
| 2983 | yang_tpdf_free(ctx, cont->tpdf, 0, cont->tpdf_size); |
| 2984 | free(cont->tpdf); |
| 2985 | lydict_remove(ctx, cont->presence); |
| 2986 | |
Pavol Vican | fda8c80 | 2016-12-03 02:00:42 +0100 | [diff] [blame] | 2987 | for (i = 0; i < cont->must_size; ++i) { |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 2988 | lys_restr_free(ctx, &cont->must[i], NULL); |
Pavol Vican | c54a8f7 | 2016-11-23 16:45:55 +0100 | [diff] [blame] | 2989 | } |
| 2990 | free(cont->must); |
| 2991 | |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 2992 | lys_when_free(ctx, cont->when, NULL); |
Pavol Vican | c54a8f7 | 2016-11-23 16:45:55 +0100 | [diff] [blame] | 2993 | } |
| 2994 | |
| 2995 | static void |
Pavol Vican | a69aff2 | 2016-11-24 18:23:50 +0100 | [diff] [blame] | 2996 | yang_free_leaf(struct ly_ctx *ctx, struct lys_node_leaf *leaf) |
| 2997 | { |
| 2998 | uint8_t i; |
| 2999 | |
| 3000 | for (i = 0; i < leaf->must_size; i++) { |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3001 | lys_restr_free(ctx, &leaf->must[i], NULL); |
Pavol Vican | a69aff2 | 2016-11-24 18:23:50 +0100 | [diff] [blame] | 3002 | } |
| 3003 | free(leaf->must); |
| 3004 | |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3005 | lys_when_free(ctx, leaf->when, NULL); |
Pavol Vican | a69aff2 | 2016-11-24 18:23:50 +0100 | [diff] [blame] | 3006 | |
| 3007 | yang_type_free(ctx, &leaf->type); |
| 3008 | lydict_remove(ctx, leaf->units); |
| 3009 | lydict_remove(ctx, leaf->dflt); |
| 3010 | } |
| 3011 | |
| 3012 | static void |
Pavol Vican | 36aff86 | 2016-11-26 17:07:05 +0100 | [diff] [blame] | 3013 | yang_free_leaflist(struct ly_ctx *ctx, struct lys_node_leaflist *leaflist) |
| 3014 | { |
| 3015 | uint8_t i; |
| 3016 | |
| 3017 | for (i = 0; i < leaflist->must_size; i++) { |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3018 | lys_restr_free(ctx, &leaflist->must[i], NULL); |
Pavol Vican | 36aff86 | 2016-11-26 17:07:05 +0100 | [diff] [blame] | 3019 | } |
| 3020 | free(leaflist->must); |
| 3021 | |
| 3022 | for (i = 0; i < leaflist->dflt_size; i++) { |
| 3023 | lydict_remove(ctx, leaflist->dflt[i]); |
| 3024 | } |
| 3025 | free(leaflist->dflt); |
| 3026 | |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3027 | lys_when_free(ctx, leaflist->when, NULL); |
Pavol Vican | 36aff86 | 2016-11-26 17:07:05 +0100 | [diff] [blame] | 3028 | |
| 3029 | yang_type_free(ctx, &leaflist->type); |
| 3030 | lydict_remove(ctx, leaflist->units); |
| 3031 | } |
| 3032 | |
| 3033 | static void |
Pavol Vican | d8136a4 | 2016-11-27 13:28:04 +0100 | [diff] [blame] | 3034 | yang_free_list(struct ly_ctx *ctx, struct lys_node_list *list) |
| 3035 | { |
| 3036 | uint8_t i; |
| 3037 | |
| 3038 | yang_tpdf_free(ctx, list->tpdf, 0, list->tpdf_size); |
| 3039 | free(list->tpdf); |
| 3040 | |
| 3041 | for (i = 0; i < list->must_size; ++i) { |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3042 | lys_restr_free(ctx, &list->must[i], NULL); |
Pavol Vican | d8136a4 | 2016-11-27 13:28:04 +0100 | [diff] [blame] | 3043 | } |
| 3044 | free(list->must); |
| 3045 | |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3046 | lys_when_free(ctx, list->when, NULL); |
Pavol Vican | d8136a4 | 2016-11-27 13:28:04 +0100 | [diff] [blame] | 3047 | |
| 3048 | for (i = 0; i < list->unique_size; ++i) { |
| 3049 | free(list->unique[i].expr); |
| 3050 | } |
| 3051 | free(list->unique); |
| 3052 | |
| 3053 | free(list->keys); |
| 3054 | } |
| 3055 | |
| 3056 | static void |
Pavol Vican | 36ace10 | 2016-11-28 11:46:59 +0100 | [diff] [blame] | 3057 | yang_free_choice(struct ly_ctx *ctx, struct lys_node_choice *choice) |
| 3058 | { |
| 3059 | free(choice->dflt); |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3060 | lys_when_free(ctx, choice->when, NULL); |
Pavol Vican | 36ace10 | 2016-11-28 11:46:59 +0100 | [diff] [blame] | 3061 | } |
| 3062 | |
| 3063 | static void |
Pavol Vican | bfa1a58 | 2016-11-28 15:35:59 +0100 | [diff] [blame] | 3064 | yang_free_anydata(struct ly_ctx *ctx, struct lys_node_anydata *anydata) |
| 3065 | { |
| 3066 | uint8_t i; |
| 3067 | |
| 3068 | for (i = 0; i < anydata->must_size; ++i) { |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3069 | lys_restr_free(ctx, &anydata->must[i], NULL); |
Pavol Vican | bfa1a58 | 2016-11-28 15:35:59 +0100 | [diff] [blame] | 3070 | } |
| 3071 | free(anydata->must); |
| 3072 | |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3073 | lys_when_free(ctx, anydata->when, NULL); |
Pavol Vican | bfa1a58 | 2016-11-28 15:35:59 +0100 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | static void |
Pavol Vican | 7872939 | 2016-11-28 17:18:22 +0100 | [diff] [blame] | 3077 | yang_free_inout(struct ly_ctx *ctx, struct lys_node_inout *inout) |
| 3078 | { |
| 3079 | uint8_t i; |
| 3080 | |
| 3081 | yang_tpdf_free(ctx, inout->tpdf, 0, inout->tpdf_size); |
| 3082 | free(inout->tpdf); |
| 3083 | |
| 3084 | for (i = 0; i < inout->must_size; ++i) { |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3085 | lys_restr_free(ctx, &inout->must[i], NULL); |
Pavol Vican | 7872939 | 2016-11-28 17:18:22 +0100 | [diff] [blame] | 3086 | } |
| 3087 | free(inout->must); |
| 3088 | } |
| 3089 | |
| 3090 | static void |
Pavol Vican | 29bf880 | 2016-11-28 20:44:57 +0100 | [diff] [blame] | 3091 | yang_free_notif(struct ly_ctx *ctx, struct lys_node_notif *notif) |
| 3092 | { |
| 3093 | uint8_t i; |
| 3094 | |
| 3095 | yang_tpdf_free(ctx, notif->tpdf, 0, notif->tpdf_size); |
| 3096 | free(notif->tpdf); |
| 3097 | |
| 3098 | for (i = 0; i < notif->must_size; ++i) { |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3099 | lys_restr_free(ctx, ¬if->must[i], NULL); |
Pavol Vican | 29bf880 | 2016-11-28 20:44:57 +0100 | [diff] [blame] | 3100 | } |
| 3101 | free(notif->must); |
| 3102 | } |
| 3103 | |
| 3104 | static void |
Pavol Vican | 3b5e82a | 2016-11-29 21:41:56 +0100 | [diff] [blame] | 3105 | yang_free_uses(struct ly_ctx *ctx, struct lys_node_uses *uses) |
| 3106 | { |
| 3107 | int i, j; |
| 3108 | |
| 3109 | for (i = 0; i < uses->refine_size; i++) { |
| 3110 | lydict_remove(ctx, uses->refine[i].target_name); |
| 3111 | lydict_remove(ctx, uses->refine[i].dsc); |
| 3112 | lydict_remove(ctx, uses->refine[i].ref); |
| 3113 | |
| 3114 | for (j = 0; j < uses->refine[i].must_size; j++) { |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3115 | lys_restr_free(ctx, &uses->refine[i].must[j], NULL); |
Pavol Vican | 3b5e82a | 2016-11-29 21:41:56 +0100 | [diff] [blame] | 3116 | } |
| 3117 | free(uses->refine[i].must); |
| 3118 | |
| 3119 | for (j = 0; j < uses->refine[i].dflt_size; j++) { |
| 3120 | lydict_remove(ctx, uses->refine[i].dflt[j]); |
| 3121 | } |
| 3122 | free(uses->refine[i].dflt); |
| 3123 | |
| 3124 | if (uses->refine[i].target_type & LYS_CONTAINER) { |
| 3125 | lydict_remove(ctx, uses->refine[i].mod.presence); |
| 3126 | } |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3127 | lys_extension_instances_free(ctx, uses->refine[i].ext, uses->refine[i].ext_size, NULL); |
Pavol Vican | 3b5e82a | 2016-11-29 21:41:56 +0100 | [diff] [blame] | 3128 | } |
| 3129 | free(uses->refine); |
| 3130 | |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3131 | lys_when_free(ctx, uses->when, NULL); |
Pavol Vican | 3b5e82a | 2016-11-29 21:41:56 +0100 | [diff] [blame] | 3132 | } |
| 3133 | |
Pavol Vican | 3b5e82a | 2016-11-29 21:41:56 +0100 | [diff] [blame] | 3134 | static void |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 3135 | yang_free_nodes(struct ly_ctx *ctx, struct lys_node *node) |
| 3136 | { |
| 3137 | struct lys_node *tmp, *child, *sibling; |
| 3138 | |
| 3139 | if (!node) { |
| 3140 | return; |
| 3141 | } |
| 3142 | tmp = node; |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 3143 | |
| 3144 | while (tmp) { |
Pavol Vican | e87ff8d | 2016-11-24 18:25:01 +0100 | [diff] [blame] | 3145 | child = tmp->child; |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 3146 | sibling = tmp->next; |
| 3147 | /* common part */ |
| 3148 | lydict_remove(ctx, tmp->name); |
| 3149 | if (!(tmp->nodetype & (LYS_INPUT | LYS_OUTPUT))) { |
Frank Rimpler | c4db1c7 | 2017-09-12 12:56:39 +0000 | [diff] [blame] | 3150 | lys_iffeature_free(ctx, tmp->iffeature, tmp->iffeature_size, 0, NULL); |
Pavol Vican | e87ff8d | 2016-11-24 18:25:01 +0100 | [diff] [blame] | 3151 | lydict_remove(ctx, tmp->dsc); |
| 3152 | lydict_remove(ctx, tmp->ref); |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 3153 | } |
| 3154 | |
| 3155 | switch (tmp->nodetype) { |
| 3156 | case LYS_GROUPING: |
Pavol Vican | ebc9ef8 | 2016-11-28 16:46:49 +0100 | [diff] [blame] | 3157 | case LYS_RPC: |
| 3158 | case LYS_ACTION: |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 3159 | yang_free_grouping(ctx, (struct lys_node_grp *)tmp); |
| 3160 | break; |
Pavol Vican | c54a8f7 | 2016-11-23 16:45:55 +0100 | [diff] [blame] | 3161 | case LYS_CONTAINER: |
| 3162 | yang_free_container(ctx, (struct lys_node_container *)tmp); |
| 3163 | break; |
Pavol Vican | a69aff2 | 2016-11-24 18:23:50 +0100 | [diff] [blame] | 3164 | case LYS_LEAF: |
| 3165 | yang_free_leaf(ctx, (struct lys_node_leaf *)tmp); |
| 3166 | break; |
Pavol Vican | 36aff86 | 2016-11-26 17:07:05 +0100 | [diff] [blame] | 3167 | case LYS_LEAFLIST: |
| 3168 | yang_free_leaflist(ctx, (struct lys_node_leaflist *)tmp); |
| 3169 | break; |
Pavol Vican | d8136a4 | 2016-11-27 13:28:04 +0100 | [diff] [blame] | 3170 | case LYS_LIST: |
| 3171 | yang_free_list(ctx, (struct lys_node_list *)tmp); |
| 3172 | break; |
Pavol Vican | 36ace10 | 2016-11-28 11:46:59 +0100 | [diff] [blame] | 3173 | case LYS_CHOICE: |
| 3174 | yang_free_choice(ctx, (struct lys_node_choice *)tmp); |
| 3175 | break; |
Pavol Vican | a420bac | 2016-11-28 14:51:54 +0100 | [diff] [blame] | 3176 | case LYS_CASE: |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3177 | lys_when_free(ctx, ((struct lys_node_case *)tmp)->when, NULL); |
Pavol Vican | a420bac | 2016-11-28 14:51:54 +0100 | [diff] [blame] | 3178 | break; |
Pavol Vican | bfa1a58 | 2016-11-28 15:35:59 +0100 | [diff] [blame] | 3179 | case LYS_ANYXML: |
| 3180 | case LYS_ANYDATA: |
| 3181 | yang_free_anydata(ctx, (struct lys_node_anydata *)tmp); |
| 3182 | break; |
Pavol Vican | 7872939 | 2016-11-28 17:18:22 +0100 | [diff] [blame] | 3183 | case LYS_INPUT: |
| 3184 | case LYS_OUTPUT: |
| 3185 | yang_free_inout(ctx, (struct lys_node_inout *)tmp); |
| 3186 | break; |
Pavol Vican | 29bf880 | 2016-11-28 20:44:57 +0100 | [diff] [blame] | 3187 | case LYS_NOTIF: |
| 3188 | yang_free_notif(ctx, (struct lys_node_notif *)tmp); |
| 3189 | break; |
Pavol Vican | 3b5e82a | 2016-11-29 21:41:56 +0100 | [diff] [blame] | 3190 | case LYS_USES: |
| 3191 | yang_free_uses(ctx, (struct lys_node_uses *)tmp); |
| 3192 | break; |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 3193 | default: |
| 3194 | break; |
| 3195 | } |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3196 | lys_extension_instances_free(ctx, tmp->ext, tmp->ext_size, NULL); |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 3197 | yang_free_nodes(ctx, child); |
| 3198 | free(tmp); |
| 3199 | tmp = sibling; |
| 3200 | } |
| 3201 | } |
| 3202 | |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 3203 | static void |
| 3204 | yang_free_augment(struct ly_ctx *ctx, struct lys_node_augment *aug) |
| 3205 | { |
| 3206 | lydict_remove(ctx, aug->target_name); |
| 3207 | lydict_remove(ctx, aug->dsc); |
| 3208 | lydict_remove(ctx, aug->ref); |
| 3209 | |
Frank Rimpler | c4db1c7 | 2017-09-12 12:56:39 +0000 | [diff] [blame] | 3210 | lys_iffeature_free(ctx, aug->iffeature, aug->iffeature_size, 0, NULL); |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3211 | lys_when_free(ctx, aug->when, NULL); |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 3212 | yang_free_nodes(ctx, aug->child); |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3213 | lys_extension_instances_free(ctx, aug->ext, aug->ext_size, NULL); |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 3214 | } |
| 3215 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 3216 | static void |
| 3217 | yang_free_deviate(struct ly_ctx *ctx, struct lys_deviation *dev, uint index) |
| 3218 | { |
| 3219 | uint i, j; |
| 3220 | |
| 3221 | for (i = index; i < dev->deviate_size; ++i) { |
| 3222 | lydict_remove(ctx, dev->deviate[i].units); |
| 3223 | |
| 3224 | if (dev->deviate[i].type) { |
| 3225 | yang_type_free(ctx, dev->deviate[i].type); |
| 3226 | } |
| 3227 | |
| 3228 | for (j = 0; j < dev->deviate[i].dflt_size; ++j) { |
| 3229 | lydict_remove(ctx, dev->deviate[i].dflt[j]); |
| 3230 | } |
| 3231 | free(dev->deviate[i].dflt); |
| 3232 | |
| 3233 | for (j = 0; j < dev->deviate[i].must_size; ++j) { |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3234 | lys_restr_free(ctx, &dev->deviate[i].must[j], NULL); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 3235 | } |
| 3236 | free(dev->deviate[i].must); |
| 3237 | |
| 3238 | for (j = 0; j < dev->deviate[i].unique_size; ++j) { |
| 3239 | free(dev->deviate[i].unique[j].expr); |
| 3240 | } |
| 3241 | free(dev->deviate[i].unique); |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 3242 | lys_extension_instances_free(ctx, dev->deviate[i].ext, dev->deviate[i].ext_size, NULL); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 3243 | } |
| 3244 | } |
| 3245 | |
PavolVican | db0e817 | 2017-02-20 00:46:09 +0100 | [diff] [blame] | 3246 | void |
| 3247 | yang_free_ext_data(struct yang_ext_substmt *substmt) |
| 3248 | { |
| 3249 | int i; |
| 3250 | |
| 3251 | if (!substmt) { |
| 3252 | return; |
| 3253 | } |
| 3254 | |
| 3255 | free(substmt->ext_substmt); |
| 3256 | if (substmt->ext_modules) { |
| 3257 | for (i = 0; substmt->ext_modules[i]; ++i) { |
| 3258 | free(substmt->ext_modules[i]); |
| 3259 | } |
| 3260 | free(substmt->ext_modules); |
| 3261 | } |
| 3262 | free(substmt); |
| 3263 | } |
| 3264 | |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3265 | /* free common item from module and submodule */ |
| 3266 | static void |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 3267 | free_yang_common(struct lys_module *module, struct lys_node *node) |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3268 | { |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 3269 | uint i; |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3270 | yang_tpdf_free(module->ctx, module->tpdf, 0, module->tpdf_size); |
| 3271 | module->tpdf_size = 0; |
Pavol Vican | 36e2727 | 2016-11-22 15:47:28 +0100 | [diff] [blame] | 3272 | yang_free_ident_base(module->ident, 0, module->ident_size); |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 3273 | yang_free_nodes(module->ctx, node); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 3274 | for (i = 0; i < module->augment_size; ++i) { |
| 3275 | yang_free_augment(module->ctx, &module->augment[i]); |
| 3276 | } |
| 3277 | module->augment_size = 0; |
| 3278 | for (i = 0; i < module->deviation_size; ++i) { |
| 3279 | yang_free_deviate(module->ctx, &module->deviation[i], 0); |
| 3280 | free(module->deviation[i].deviate); |
David Sedlák | 437ec40 | 2018-08-13 09:07:10 +0200 | [diff] [blame^] | 3281 | lydict_remove(module->ctx, module->deviation[i].target_name); |
| 3282 | lydict_remove(module->ctx, module->deviation[i].dsc); |
| 3283 | lydict_remove(module->ctx, module->deviation[i].ref); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 3284 | } |
| 3285 | module->deviation_size = 0; |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3286 | } |
| 3287 | |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 3288 | /* check function*/ |
| 3289 | |
| 3290 | int |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 3291 | yang_check_ext_instance(struct lys_module *module, struct lys_ext_instance ***ext, uint size, |
| 3292 | void *parent, struct unres_schema *unres) |
| 3293 | { |
| 3294 | struct unres_ext *info; |
| 3295 | uint i; |
| 3296 | |
| 3297 | for (i = 0; i < size; ++i) { |
| 3298 | info = malloc(sizeof *info); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3299 | LY_CHECK_ERR_RETURN(!info, LOGMEM(module->ctx), EXIT_FAILURE); |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 3300 | info->data.yang = (*ext)[i]->parent; |
| 3301 | info->datatype = LYS_IN_YANG; |
| 3302 | info->parent = parent; |
| 3303 | info->mod = module; |
| 3304 | info->parent_type = (*ext)[i]->parent_type; |
Radek Krejci | febdad7 | 2017-02-06 11:35:51 +0100 | [diff] [blame] | 3305 | info->substmt = (*ext)[i]->insubstmt; |
| 3306 | info->substmt_index = (*ext)[i]->insubstmt_index; |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 3307 | info->ext_index = i; |
| 3308 | if (unres_schema_add_node(module, unres, ext, UNRES_EXT, (struct lys_node *)info) == -1) { |
| 3309 | return EXIT_FAILURE; |
| 3310 | } |
| 3311 | } |
| 3312 | |
| 3313 | return EXIT_SUCCESS; |
| 3314 | } |
| 3315 | |
| 3316 | int |
Pavol Vican | ec423c9 | 2016-10-24 21:33:43 +0200 | [diff] [blame] | 3317 | yang_check_imports(struct lys_module *module, struct unres_schema *unres) |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 3318 | { |
| 3319 | struct lys_import *imp; |
Pavol Vican | ec423c9 | 2016-10-24 21:33:43 +0200 | [diff] [blame] | 3320 | struct lys_include *inc; |
| 3321 | uint8_t imp_size, inc_size, j = 0, i = 0; |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 3322 | char *s; |
| 3323 | |
| 3324 | imp = module->imp; |
| 3325 | imp_size = module->imp_size; |
Pavol Vican | ec423c9 | 2016-10-24 21:33:43 +0200 | [diff] [blame] | 3326 | inc = module->inc; |
| 3327 | inc_size = module->inc_size; |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 3328 | |
| 3329 | if (imp_size) { |
PavolVican | 5144fd8 | 2017-03-07 19:45:06 +0100 | [diff] [blame] | 3330 | module->imp = calloc(imp_size, sizeof *module->imp); |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 3331 | module->imp_size = 0; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3332 | LY_CHECK_ERR_GOTO(!module->imp, LOGMEM(module->ctx), error); |
Pavol Vican | ec423c9 | 2016-10-24 21:33:43 +0200 | [diff] [blame] | 3333 | } |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 3334 | |
Pavol Vican | ec423c9 | 2016-10-24 21:33:43 +0200 | [diff] [blame] | 3335 | if (inc_size) { |
PavolVican | 5144fd8 | 2017-03-07 19:45:06 +0100 | [diff] [blame] | 3336 | module->inc = calloc(inc_size, sizeof *module->inc); |
Pavol Vican | ec423c9 | 2016-10-24 21:33:43 +0200 | [diff] [blame] | 3337 | module->inc_size = 0; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3338 | LY_CHECK_ERR_GOTO(!module->inc, LOGMEM(module->ctx), error); |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 3339 | } |
| 3340 | |
| 3341 | for (i = 0; i < imp_size; ++i) { |
| 3342 | s = (char *) imp[i].module; |
| 3343 | imp[i].module = NULL; |
PavolVican | 7d0b5ab | 2017-02-01 13:06:53 +0100 | [diff] [blame] | 3344 | if (yang_fill_import(module, &imp[i], &module->imp[module->imp_size], s, unres)) { |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 3345 | ++i; |
| 3346 | goto error; |
| 3347 | } |
| 3348 | } |
Pavol Vican | ec423c9 | 2016-10-24 21:33:43 +0200 | [diff] [blame] | 3349 | for (j = 0; j < inc_size; ++j) { |
Pavol Vican | fda8c80 | 2016-12-03 02:00:42 +0100 | [diff] [blame] | 3350 | s = (char *) inc[j].submodule; |
| 3351 | inc[j].submodule = NULL; |
| 3352 | if (yang_fill_include(module, s, &inc[j], unres)) { |
| 3353 | ++j; |
Pavol Vican | ec423c9 | 2016-10-24 21:33:43 +0200 | [diff] [blame] | 3354 | goto error; |
| 3355 | } |
| 3356 | } |
| 3357 | free(inc); |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 3358 | free(imp); |
| 3359 | |
| 3360 | return EXIT_SUCCESS; |
| 3361 | |
| 3362 | error: |
| 3363 | yang_free_import(module->ctx, imp, i, imp_size); |
Pavol Vican | ec423c9 | 2016-10-24 21:33:43 +0200 | [diff] [blame] | 3364 | yang_free_include(module->ctx, inc, j, inc_size); |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 3365 | free(imp); |
Pavol Vican | ec423c9 | 2016-10-24 21:33:43 +0200 | [diff] [blame] | 3366 | free(inc); |
Pavol Vican | 1cc4e19 | 2016-10-24 16:38:31 +0200 | [diff] [blame] | 3367 | return EXIT_FAILURE; |
| 3368 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3369 | |
Pavol Vican | 5c8a9ad | 2016-11-22 11:50:54 +0100 | [diff] [blame] | 3370 | static int |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 3371 | yang_check_iffeatures(struct lys_module *module, void *ptr, void *parent, enum yytokentype type, struct unres_schema *unres) |
Pavol Vican | 5c8a9ad | 2016-11-22 11:50:54 +0100 | [diff] [blame] | 3372 | { |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 3373 | struct lys_iffeature *iffeature; |
| 3374 | uint8_t *ptr_size, size, i; |
| 3375 | char *s; |
| 3376 | int parent_is_feature = 0; |
Pavol Vican | 5c8a9ad | 2016-11-22 11:50:54 +0100 | [diff] [blame] | 3377 | |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 3378 | switch (type) { |
| 3379 | case FEATURE_KEYWORD: |
| 3380 | iffeature = ((struct lys_feature *)parent)->iffeature; |
| 3381 | size = ((struct lys_feature *)parent)->iffeature_size; |
| 3382 | ptr_size = &((struct lys_feature *)parent)->iffeature_size; |
| 3383 | parent_is_feature = 1; |
| 3384 | break; |
| 3385 | case IDENTITY_KEYWORD: |
| 3386 | iffeature = ((struct lys_ident *)parent)->iffeature; |
| 3387 | size = ((struct lys_ident *)parent)->iffeature_size; |
| 3388 | ptr_size = &((struct lys_ident *)parent)->iffeature_size; |
| 3389 | break; |
| 3390 | case ENUM_KEYWORD: |
| 3391 | iffeature = ((struct lys_type_enum *)ptr)->iffeature; |
| 3392 | size = ((struct lys_type_enum *)ptr)->iffeature_size; |
| 3393 | ptr_size = &((struct lys_type_enum *)ptr)->iffeature_size; |
| 3394 | break; |
| 3395 | case BIT_KEYWORD: |
| 3396 | iffeature = ((struct lys_type_bit *)ptr)->iffeature; |
| 3397 | size = ((struct lys_type_bit *)ptr)->iffeature_size; |
| 3398 | ptr_size = &((struct lys_type_bit *)ptr)->iffeature_size; |
| 3399 | break; |
| 3400 | case REFINE_KEYWORD: |
| 3401 | iffeature = ((struct lys_refine *)ptr)->iffeature; |
| 3402 | size = ((struct lys_refine *)ptr)->iffeature_size; |
| 3403 | ptr_size = &((struct lys_refine *)ptr)->iffeature_size; |
| 3404 | break; |
| 3405 | default: |
| 3406 | iffeature = ((struct lys_node *)parent)->iffeature; |
| 3407 | size = ((struct lys_node *)parent)->iffeature_size; |
| 3408 | ptr_size = &((struct lys_node *)parent)->iffeature_size; |
| 3409 | break; |
Pavol Vican | 5c8a9ad | 2016-11-22 11:50:54 +0100 | [diff] [blame] | 3410 | } |
| 3411 | |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 3412 | *ptr_size = 0; |
Pavol Vican | 5c8a9ad | 2016-11-22 11:50:54 +0100 | [diff] [blame] | 3413 | for (i = 0; i < size; ++i) { |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 3414 | s = (char *)iffeature[i].features; |
| 3415 | iffeature[i].features = NULL; |
| 3416 | if (yang_fill_iffeature(module, &iffeature[i], parent, s, unres, parent_is_feature)) { |
| 3417 | *ptr_size = size; |
| 3418 | return EXIT_FAILURE; |
Pavol Vican | 5c8a9ad | 2016-11-22 11:50:54 +0100 | [diff] [blame] | 3419 | } |
PavolVican | 8fa3124 | 2017-02-07 11:04:26 +0100 | [diff] [blame] | 3420 | if (yang_check_ext_instance(module, &iffeature[i].ext, iffeature[i].ext_size, &iffeature[i], unres)) { |
| 3421 | *ptr_size = size; |
| 3422 | return EXIT_FAILURE; |
| 3423 | } |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 3424 | (*ptr_size)++; |
Pavol Vican | 5c8a9ad | 2016-11-22 11:50:54 +0100 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | return EXIT_SUCCESS; |
Pavol Vican | 5c8a9ad | 2016-11-22 11:50:54 +0100 | [diff] [blame] | 3428 | } |
| 3429 | |
Pavol Vican | b60a1d1 | 2016-12-03 01:56:55 +0100 | [diff] [blame] | 3430 | static int |
| 3431 | yang_check_identityref(struct lys_module *module, struct lys_type *type, struct unres_schema *unres) |
| 3432 | { |
| 3433 | uint size, i; |
| 3434 | int rc; |
| 3435 | struct lys_ident **ref; |
| 3436 | const char *value; |
| 3437 | char *expr; |
| 3438 | |
| 3439 | ref = type->info.ident.ref; |
| 3440 | size = type->info.ident.count; |
| 3441 | type->info.ident.count = 0; |
| 3442 | type->info.ident.ref = NULL; |
| 3443 | ((struct yang_type *)type->der)->flags |= LYS_NO_ERASE_IDENTITY; |
| 3444 | |
| 3445 | for (i = 0; i < size; ++i) { |
| 3446 | expr = (char *)ref[i]; |
| 3447 | /* store in the JSON format */ |
| 3448 | value = transform_schema2json(module, expr); |
| 3449 | free(expr); |
| 3450 | |
| 3451 | if (!value) { |
| 3452 | goto error; |
| 3453 | } |
| 3454 | rc = unres_schema_add_str(module, unres, type, UNRES_TYPE_IDENTREF, value); |
| 3455 | lydict_remove(module->ctx, value); |
| 3456 | |
| 3457 | if (rc == -1) { |
| 3458 | goto error; |
| 3459 | } |
| 3460 | } |
| 3461 | free(ref); |
| 3462 | |
| 3463 | return EXIT_SUCCESS; |
| 3464 | error: |
| 3465 | for (i = i+1; i < size; ++i) { |
| 3466 | free(ref[i]); |
| 3467 | } |
| 3468 | free(ref); |
| 3469 | return EXIT_FAILURE; |
| 3470 | } |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 3471 | |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3472 | int |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 3473 | yang_fill_type(struct lys_module *module, struct lys_type *type, struct yang_type *stype, |
| 3474 | void *parent, struct unres_schema *unres) |
| 3475 | { |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3476 | unsigned int i, j; |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 3477 | |
| 3478 | type->parent = parent; |
| 3479 | if (yang_check_ext_instance(module, &type->ext, type->ext_size, type, unres)) { |
| 3480 | return EXIT_FAILURE; |
| 3481 | } |
Michal Vasko | e59ada9 | 2018-02-22 14:05:34 +0100 | [diff] [blame] | 3482 | for (j = 0; j < type->ext_size; ++j) { |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3483 | if (type->ext[j]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 3484 | type->parent->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3485 | break; |
| 3486 | } |
| 3487 | } |
| 3488 | |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 3489 | switch (stype->base) { |
| 3490 | case LY_TYPE_ENUM: |
| 3491 | for (i = 0; i < type->info.enums.count; ++i) { |
| 3492 | if (yang_check_iffeatures(module, &type->info.enums.enm[i], parent, ENUM_KEYWORD, unres)) { |
| 3493 | return EXIT_FAILURE; |
| 3494 | } |
| 3495 | if (yang_check_ext_instance(module, &type->info.enums.enm[i].ext, type->info.enums.enm[i].ext_size, |
| 3496 | &type->info.enums.enm[i], unres)) { |
| 3497 | return EXIT_FAILURE; |
| 3498 | } |
Michal Vasko | e59ada9 | 2018-02-22 14:05:34 +0100 | [diff] [blame] | 3499 | for (j = 0; j < type->info.enums.enm[i].ext_size; ++j) { |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3500 | if (type->info.enums.enm[i].ext[j]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 3501 | type->parent->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3502 | break; |
| 3503 | } |
| 3504 | } |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 3505 | } |
| 3506 | break; |
| 3507 | case LY_TYPE_BITS: |
| 3508 | for (i = 0; i < type->info.bits.count; ++i) { |
| 3509 | if (yang_check_iffeatures(module, &type->info.bits.bit[i], parent, BIT_KEYWORD, unres)) { |
| 3510 | return EXIT_FAILURE; |
| 3511 | } |
| 3512 | if (yang_check_ext_instance(module, &type->info.bits.bit[i].ext, type->info.bits.bit[i].ext_size, |
| 3513 | &type->info.bits.bit[i], unres)) { |
| 3514 | return EXIT_FAILURE; |
| 3515 | } |
Michal Vasko | e59ada9 | 2018-02-22 14:05:34 +0100 | [diff] [blame] | 3516 | for (j = 0; j < type->info.bits.bit[i].ext_size; ++j) { |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3517 | if (type->info.bits.bit[i].ext[j]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 3518 | type->parent->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3519 | break; |
| 3520 | } |
| 3521 | } |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 3522 | } |
| 3523 | break; |
| 3524 | case LY_TYPE_IDENT: |
| 3525 | if (yang_check_identityref(module, type, unres)) { |
| 3526 | return EXIT_FAILURE; |
| 3527 | } |
| 3528 | break; |
| 3529 | case LY_TYPE_STRING: |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3530 | if (type->info.str.length) { |
| 3531 | if (yang_check_ext_instance(module, &type->info.str.length->ext, |
| 3532 | type->info.str.length->ext_size, type->info.str.length, unres)) { |
| 3533 | return EXIT_FAILURE; |
| 3534 | } |
Michal Vasko | e59ada9 | 2018-02-22 14:05:34 +0100 | [diff] [blame] | 3535 | for (j = 0; j < type->info.str.length->ext_size; ++j) { |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3536 | if (type->info.str.length->ext[j]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 3537 | type->parent->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3538 | break; |
| 3539 | } |
| 3540 | } |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 3541 | } |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3542 | |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 3543 | for (i = 0; i < type->info.str.pat_count; ++i) { |
| 3544 | if (yang_check_ext_instance(module, &type->info.str.patterns[i].ext, type->info.str.patterns[i].ext_size, |
| 3545 | &type->info.str.patterns[i], unres)) { |
| 3546 | return EXIT_FAILURE; |
| 3547 | } |
Michal Vasko | e59ada9 | 2018-02-22 14:05:34 +0100 | [diff] [blame] | 3548 | for (j = 0; j < type->info.str.patterns[i].ext_size; ++j) { |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3549 | if (type->info.str.patterns[i].ext[j]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 3550 | type->parent->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3551 | break; |
| 3552 | } |
| 3553 | } |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 3554 | } |
| 3555 | break; |
| 3556 | case LY_TYPE_DEC64: |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3557 | if (type->info.dec64.range) { |
| 3558 | if (yang_check_ext_instance(module, &type->info.dec64.range->ext, |
| 3559 | type->info.dec64.range->ext_size, type->info.dec64.range, unres)) { |
| 3560 | return EXIT_FAILURE; |
| 3561 | } |
Michal Vasko | e59ada9 | 2018-02-22 14:05:34 +0100 | [diff] [blame] | 3562 | for (j = 0; j < type->info.dec64.range->ext_size; ++j) { |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3563 | if (type->info.dec64.range->ext[j]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 3564 | type->parent->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3565 | break; |
| 3566 | } |
| 3567 | } |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 3568 | } |
| 3569 | break; |
| 3570 | case LY_TYPE_UNION: |
| 3571 | for (i = 0; i < type->info.uni.count; ++i) { |
| 3572 | if (yang_fill_type(module, &type->info.uni.types[i], (struct yang_type *)type->info.uni.types[i].der, |
| 3573 | parent, unres)) { |
| 3574 | return EXIT_FAILURE; |
| 3575 | } |
| 3576 | } |
Radek Krejci | 57b4168 | 2017-03-07 12:33:24 +0100 | [diff] [blame] | 3577 | break; |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 3578 | default: |
| 3579 | /* nothing checks */ |
| 3580 | break; |
| 3581 | } |
| 3582 | return EXIT_SUCCESS; |
| 3583 | } |
| 3584 | |
| 3585 | int |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3586 | yang_check_typedef(struct lys_module *module, struct lys_node *parent, struct unres_schema *unres) |
| 3587 | { |
| 3588 | struct lys_tpdf *tpdf; |
Radek Krejci | daa547a | 2017-09-22 15:56:27 +0200 | [diff] [blame] | 3589 | uint8_t *ptr_tpdf_size = NULL; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3590 | uint16_t j, i, tpdf_size, *ptr_tpdf_size16 = NULL; |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3591 | |
| 3592 | if (!parent) { |
| 3593 | tpdf = module->tpdf; |
Radek Krejci | a2ac926 | 2017-09-12 16:39:04 +0200 | [diff] [blame] | 3594 | //ptr_tpdf_size = &module->tpdf_size; |
| 3595 | ptr_tpdf_size16 = &module->tpdf_size; |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 3596 | } else { |
| 3597 | switch (parent->nodetype) { |
| 3598 | case LYS_GROUPING: |
| 3599 | tpdf = ((struct lys_node_grp *)parent)->tpdf; |
Radek Krejci | a2ac926 | 2017-09-12 16:39:04 +0200 | [diff] [blame] | 3600 | ptr_tpdf_size16 = &((struct lys_node_grp *)parent)->tpdf_size; |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 3601 | break; |
Pavol Vican | c54a8f7 | 2016-11-23 16:45:55 +0100 | [diff] [blame] | 3602 | case LYS_CONTAINER: |
| 3603 | tpdf = ((struct lys_node_container *)parent)->tpdf; |
Radek Krejci | a2ac926 | 2017-09-12 16:39:04 +0200 | [diff] [blame] | 3604 | ptr_tpdf_size16 = &((struct lys_node_container *)parent)->tpdf_size; |
Pavol Vican | c54a8f7 | 2016-11-23 16:45:55 +0100 | [diff] [blame] | 3605 | break; |
Pavol Vican | d8136a4 | 2016-11-27 13:28:04 +0100 | [diff] [blame] | 3606 | case LYS_LIST: |
| 3607 | tpdf = ((struct lys_node_list *)parent)->tpdf; |
| 3608 | ptr_tpdf_size = &((struct lys_node_list *)parent)->tpdf_size; |
| 3609 | break; |
Pavol Vican | ebc9ef8 | 2016-11-28 16:46:49 +0100 | [diff] [blame] | 3610 | case LYS_RPC: |
| 3611 | case LYS_ACTION: |
| 3612 | tpdf = ((struct lys_node_rpc_action *)parent)->tpdf; |
Radek Krejci | a2ac926 | 2017-09-12 16:39:04 +0200 | [diff] [blame] | 3613 | ptr_tpdf_size16 = &((struct lys_node_rpc_action *)parent)->tpdf_size; |
Pavol Vican | ebc9ef8 | 2016-11-28 16:46:49 +0100 | [diff] [blame] | 3614 | break; |
Pavol Vican | 7872939 | 2016-11-28 17:18:22 +0100 | [diff] [blame] | 3615 | case LYS_INPUT: |
| 3616 | case LYS_OUTPUT: |
| 3617 | tpdf = ((struct lys_node_inout *)parent)->tpdf; |
Radek Krejci | a2ac926 | 2017-09-12 16:39:04 +0200 | [diff] [blame] | 3618 | ptr_tpdf_size16 = &((struct lys_node_inout *)parent)->tpdf_size; |
Pavol Vican | 7872939 | 2016-11-28 17:18:22 +0100 | [diff] [blame] | 3619 | break; |
Pavol Vican | 29bf880 | 2016-11-28 20:44:57 +0100 | [diff] [blame] | 3620 | case LYS_NOTIF: |
| 3621 | tpdf = ((struct lys_node_notif *)parent)->tpdf; |
Radek Krejci | a2ac926 | 2017-09-12 16:39:04 +0200 | [diff] [blame] | 3622 | ptr_tpdf_size16 = &((struct lys_node_notif *)parent)->tpdf_size; |
Pavol Vican | 29bf880 | 2016-11-28 20:44:57 +0100 | [diff] [blame] | 3623 | break; |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 3624 | default: |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3625 | LOGINT(module->ctx); |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 3626 | return EXIT_FAILURE; |
| 3627 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3628 | } |
| 3629 | |
Radek Krejci | a2ac926 | 2017-09-12 16:39:04 +0200 | [diff] [blame] | 3630 | if (ptr_tpdf_size16) { |
| 3631 | tpdf_size = *ptr_tpdf_size16; |
| 3632 | *ptr_tpdf_size16 = 0; |
| 3633 | } else { |
| 3634 | tpdf_size = *ptr_tpdf_size; |
| 3635 | *ptr_tpdf_size = 0; |
| 3636 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3637 | |
| 3638 | for (i = 0; i < tpdf_size; ++i) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3639 | if (lyp_check_identifier(module->ctx, tpdf[i].name, LY_IDENT_TYPE, module, parent)) { |
Pavol Vican | fda8c80 | 2016-12-03 02:00:42 +0100 | [diff] [blame] | 3640 | goto error; |
| 3641 | } |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 3642 | |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 3643 | if (yang_fill_type(module, &tpdf[i].type, (struct yang_type *)tpdf[i].type.der, &tpdf[i], unres)) { |
| 3644 | goto error; |
Pavol Vican | 5c8a9ad | 2016-11-22 11:50:54 +0100 | [diff] [blame] | 3645 | } |
PavolVican | df9e797 | 2017-02-07 11:41:38 +0100 | [diff] [blame] | 3646 | if (yang_check_ext_instance(module, &tpdf[i].ext, tpdf[i].ext_size, &tpdf[i], unres)) { |
| 3647 | goto error; |
| 3648 | } |
Michal Vasko | e59ada9 | 2018-02-22 14:05:34 +0100 | [diff] [blame] | 3649 | for (j = 0; j < tpdf[i].ext_size; ++j) { |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3650 | if (tpdf[i].ext[j]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 3651 | tpdf[i].flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 3652 | break; |
| 3653 | } |
| 3654 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3655 | if (unres_schema_add_node(module, unres, &tpdf[i].type, UNRES_TYPE_DER_TPDF, parent) == -1) { |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 3656 | goto error; |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3657 | } |
| 3658 | |
Radek Krejci | a2ac926 | 2017-09-12 16:39:04 +0200 | [diff] [blame] | 3659 | if (ptr_tpdf_size16) { |
| 3660 | (*ptr_tpdf_size16)++; |
| 3661 | } else { |
| 3662 | (*ptr_tpdf_size)++; |
| 3663 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3664 | /* check default value*/ |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 3665 | if (!(module->ctx->models.flags & LY_CTX_TRUSTED) |
| 3666 | && unres_schema_add_node(module, unres, &tpdf[i].type, UNRES_TYPEDEF_DFLT, (struct lys_node *)(&tpdf[i].dflt)) == -1) { |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3667 | ++i; |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 3668 | goto error; |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3669 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3670 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3671 | |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 3672 | return EXIT_SUCCESS; |
| 3673 | |
| 3674 | error: |
| 3675 | yang_tpdf_free(module->ctx, tpdf, i, tpdf_size); |
| 3676 | return EXIT_FAILURE; |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | static int |
Pavol Vican | 36e2727 | 2016-11-22 15:47:28 +0100 | [diff] [blame] | 3680 | yang_check_identities(struct lys_module *module, struct unres_schema *unres) |
| 3681 | { |
| 3682 | uint32_t i, size, base_size; |
| 3683 | uint8_t j; |
| 3684 | |
| 3685 | size = module->ident_size; |
| 3686 | module->ident_size = 0; |
| 3687 | for (i = 0; i < size; ++i) { |
| 3688 | base_size = module->ident[i].base_size; |
| 3689 | module->ident[i].base_size = 0; |
| 3690 | for (j = 0; j < base_size; ++j) { |
| 3691 | if (yang_read_base(module, &module->ident[i], (char *)module->ident[i].base[j], unres)) { |
| 3692 | ++j; |
| 3693 | module->ident_size = size; |
| 3694 | goto error; |
| 3695 | } |
| 3696 | } |
| 3697 | module->ident_size++; |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 3698 | if (yang_check_iffeatures(module, NULL, &module->ident[i], IDENTITY_KEYWORD, unres)) { |
| 3699 | goto error; |
| 3700 | } |
PavolVican | 8fa3124 | 2017-02-07 11:04:26 +0100 | [diff] [blame] | 3701 | if (yang_check_ext_instance(module, &module->ident[i].ext, module->ident[i].ext_size, &module->ident[i], unres)) { |
| 3702 | goto error; |
| 3703 | } |
Pavol Vican | 36e2727 | 2016-11-22 15:47:28 +0100 | [diff] [blame] | 3704 | } |
| 3705 | |
| 3706 | return EXIT_SUCCESS; |
| 3707 | |
| 3708 | error: |
| 3709 | for (; j< module->ident[i].base_size; ++j) { |
| 3710 | free(module->ident[i].base[j]); |
| 3711 | } |
| 3712 | yang_free_ident_base(module->ident, i + 1, size); |
| 3713 | return EXIT_FAILURE; |
| 3714 | } |
| 3715 | |
| 3716 | static int |
PavolVican | 38104a3 | 2017-02-08 12:25:23 +0100 | [diff] [blame] | 3717 | yang_check_must(struct lys_module *module, struct lys_restr *must, uint size, struct unres_schema *unres) |
| 3718 | { |
| 3719 | uint i; |
| 3720 | |
| 3721 | for (i = 0; i < size; ++i) { |
| 3722 | if (yang_check_ext_instance(module, &must[i].ext, must[i].ext_size, &must[i], unres)) { |
| 3723 | return EXIT_FAILURE; |
| 3724 | } |
| 3725 | } |
| 3726 | return EXIT_SUCCESS; |
| 3727 | } |
| 3728 | |
| 3729 | static int |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 3730 | yang_check_container(struct lys_module *module, struct lys_node_container *cont, struct lys_node **child, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3731 | int options, struct unres_schema *unres) |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 3732 | { |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 3733 | if (yang_check_typedef(module, (struct lys_node *)cont, unres)) { |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 3734 | goto error; |
| 3735 | } |
| 3736 | |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 3737 | if (yang_check_iffeatures(module, NULL, cont, CONTAINER_KEYWORD, unres)) { |
Pavol Vican | c54a8f7 | 2016-11-23 16:45:55 +0100 | [diff] [blame] | 3738 | goto error; |
| 3739 | } |
| 3740 | |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3741 | if (yang_check_nodes(module, (struct lys_node *)cont, *child, options, unres)) { |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 3742 | *child = NULL; |
| 3743 | goto error; |
| 3744 | } |
| 3745 | *child = NULL; |
| 3746 | |
PavolVican | 59ba460 | 2017-02-08 11:53:32 +0100 | [diff] [blame] | 3747 | if (cont->when && yang_check_ext_instance(module, &cont->when->ext, cont->when->ext_size, cont->when, unres)) { |
| 3748 | goto error; |
| 3749 | } |
PavolVican | 38104a3 | 2017-02-08 12:25:23 +0100 | [diff] [blame] | 3750 | if (yang_check_must(module, cont->must, cont->must_size, unres)) { |
| 3751 | goto error; |
| 3752 | } |
| 3753 | |
Pavol Vican | c54a8f7 | 2016-11-23 16:45:55 +0100 | [diff] [blame] | 3754 | /* check XPath dependencies */ |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 3755 | if (!(module->ctx->models.flags & LY_CTX_TRUSTED) && (cont->when || cont->must_size)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3756 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 3757 | if (lyxp_node_check_syntax((struct lys_node *)cont)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3758 | goto error; |
| 3759 | } |
| 3760 | } else { |
| 3761 | if (unres_schema_add_node(module, unres, cont, UNRES_XPATH, NULL) == -1) { |
| 3762 | goto error; |
| 3763 | } |
| 3764 | } |
Pavol Vican | c54a8f7 | 2016-11-23 16:45:55 +0100 | [diff] [blame] | 3765 | } |
| 3766 | |
| 3767 | return EXIT_SUCCESS; |
| 3768 | error: |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3769 | |
Pavol Vican | c54a8f7 | 2016-11-23 16:45:55 +0100 | [diff] [blame] | 3770 | return EXIT_FAILURE; |
| 3771 | } |
| 3772 | |
| 3773 | static int |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3774 | yang_check_leaf(struct lys_module *module, struct lys_node_leaf *leaf, int options, struct unres_schema *unres) |
Pavol Vican | a69aff2 | 2016-11-24 18:23:50 +0100 | [diff] [blame] | 3775 | { |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 3776 | if (yang_fill_type(module, &leaf->type, (struct yang_type *)leaf->type.der, leaf, unres)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3777 | yang_type_free(module->ctx, &leaf->type); |
| 3778 | goto error; |
Pavol Vican | a69aff2 | 2016-11-24 18:23:50 +0100 | [diff] [blame] | 3779 | } |
PavolVican | a08d365 | 2016-12-29 21:07:47 +0100 | [diff] [blame] | 3780 | if (yang_check_iffeatures(module, NULL, leaf, LEAF_KEYWORD, unres)) { |
| 3781 | yang_type_free(module->ctx, &leaf->type); |
| 3782 | goto error; |
| 3783 | } |
| 3784 | |
Pavol Vican | fda8c80 | 2016-12-03 02:00:42 +0100 | [diff] [blame] | 3785 | if (unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DER, (struct lys_node *)leaf) == -1) { |
Pavol Vican | a69aff2 | 2016-11-24 18:23:50 +0100 | [diff] [blame] | 3786 | yang_type_free(module->ctx, &leaf->type); |
| 3787 | goto error; |
| 3788 | } |
| 3789 | |
Michal Vasko | 6a05778 | 2018-03-09 13:24:33 +0100 | [diff] [blame] | 3790 | if (!(module->ctx->models.flags & LY_CTX_TRUSTED) && |
Radek Krejci | ab08f0f | 2017-03-09 16:37:15 +0100 | [diff] [blame] | 3791 | (unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DFLT, (struct lys_node *)&leaf->dflt) == -1)) { |
Pavol Vican | a69aff2 | 2016-11-24 18:23:50 +0100 | [diff] [blame] | 3792 | goto error; |
| 3793 | } |
| 3794 | |
PavolVican | 59ba460 | 2017-02-08 11:53:32 +0100 | [diff] [blame] | 3795 | if (leaf->when && yang_check_ext_instance(module, &leaf->when->ext, leaf->when->ext_size, leaf->when, unres)) { |
| 3796 | goto error; |
| 3797 | } |
PavolVican | 38104a3 | 2017-02-08 12:25:23 +0100 | [diff] [blame] | 3798 | if (yang_check_must(module, leaf->must, leaf->must_size, unres)) { |
| 3799 | goto error; |
| 3800 | } |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3801 | |
Pavol Vican | a69aff2 | 2016-11-24 18:23:50 +0100 | [diff] [blame] | 3802 | /* check XPath dependencies */ |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 3803 | if (!(module->ctx->models.flags & LY_CTX_TRUSTED) && (leaf->when || leaf->must_size)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3804 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 3805 | if (lyxp_node_check_syntax((struct lys_node *)leaf)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3806 | goto error; |
| 3807 | } |
| 3808 | } else { |
| 3809 | if (unres_schema_add_node(module, unres, leaf, UNRES_XPATH, NULL) == -1) { |
| 3810 | goto error; |
| 3811 | } |
| 3812 | } |
Pavol Vican | a69aff2 | 2016-11-24 18:23:50 +0100 | [diff] [blame] | 3813 | } |
| 3814 | |
| 3815 | return EXIT_SUCCESS; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3816 | |
Pavol Vican | a69aff2 | 2016-11-24 18:23:50 +0100 | [diff] [blame] | 3817 | error: |
| 3818 | return EXIT_FAILURE; |
| 3819 | } |
| 3820 | |
| 3821 | static int |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3822 | yang_check_leaflist(struct lys_module *module, struct lys_node_leaflist *leaflist, int options, |
| 3823 | struct unres_schema *unres) |
Pavol Vican | 36aff86 | 2016-11-26 17:07:05 +0100 | [diff] [blame] | 3824 | { |
Pavol Vican | fda8c80 | 2016-12-03 02:00:42 +0100 | [diff] [blame] | 3825 | int i, j; |
Pavol Vican | 36aff86 | 2016-11-26 17:07:05 +0100 | [diff] [blame] | 3826 | |
PavolVican | 056fcd1 | 2017-02-07 15:36:53 +0100 | [diff] [blame] | 3827 | if (yang_fill_type(module, &leaflist->type, (struct yang_type *)leaflist->type.der, leaflist, unres)) { |
PavolVican | 6a2148f | 2017-02-07 23:09:55 +0100 | [diff] [blame] | 3828 | yang_type_free(module->ctx, &leaflist->type); |
| 3829 | goto error; |
Pavol Vican | 36aff86 | 2016-11-26 17:07:05 +0100 | [diff] [blame] | 3830 | } |
PavolVican | a08d365 | 2016-12-29 21:07:47 +0100 | [diff] [blame] | 3831 | if (yang_check_iffeatures(module, NULL, leaflist, LEAF_LIST_KEYWORD, unres)) { |
| 3832 | yang_type_free(module->ctx, &leaflist->type); |
| 3833 | goto error; |
| 3834 | } |
| 3835 | |
Pavol Vican | fda8c80 | 2016-12-03 02:00:42 +0100 | [diff] [blame] | 3836 | if (unres_schema_add_node(module, unres, &leaflist->type, UNRES_TYPE_DER, (struct lys_node *)leaflist) == -1) { |
Pavol Vican | 36aff86 | 2016-11-26 17:07:05 +0100 | [diff] [blame] | 3837 | yang_type_free(module->ctx, &leaflist->type); |
| 3838 | goto error; |
| 3839 | } |
| 3840 | |
Pavol Vican | 36aff86 | 2016-11-26 17:07:05 +0100 | [diff] [blame] | 3841 | for (i = 0; i < leaflist->dflt_size; ++i) { |
Pavol Vican | fda8c80 | 2016-12-03 02:00:42 +0100 | [diff] [blame] | 3842 | /* check for duplicity in case of configuration data, |
| 3843 | * in case of status data duplicities are allowed */ |
| 3844 | if (leaflist->flags & LYS_CONFIG_W) { |
| 3845 | for (j = i +1; j < leaflist->dflt_size; ++j) { |
| 3846 | if (ly_strequal(leaflist->dflt[i], leaflist->dflt[j], 1)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3847 | LOGVAL(module->ctx, LYE_INARG, LY_VLOG_LYS, leaflist, leaflist->dflt[i], "default"); |
| 3848 | LOGVAL(module->ctx, LYE_SPEC, LY_VLOG_LYS, leaflist, "Duplicated default value \"%s\".", leaflist->dflt[i]); |
Pavol Vican | fda8c80 | 2016-12-03 02:00:42 +0100 | [diff] [blame] | 3849 | goto error; |
| 3850 | } |
| 3851 | } |
| 3852 | } |
| 3853 | /* check default value (if not defined, there still could be some restrictions |
| 3854 | * that need to be checked against a default value from a derived type) */ |
Michal Vasko | 6a05778 | 2018-03-09 13:24:33 +0100 | [diff] [blame] | 3855 | if (!(module->ctx->models.flags & LY_CTX_TRUSTED) && |
Radek Krejci | ab08f0f | 2017-03-09 16:37:15 +0100 | [diff] [blame] | 3856 | (unres_schema_add_node(module, unres, &leaflist->type, UNRES_TYPE_DFLT, |
| 3857 | (struct lys_node *)(&leaflist->dflt[i])) == -1)) { |
Pavol Vican | 36aff86 | 2016-11-26 17:07:05 +0100 | [diff] [blame] | 3858 | goto error; |
| 3859 | } |
| 3860 | } |
| 3861 | |
PavolVican | 59ba460 | 2017-02-08 11:53:32 +0100 | [diff] [blame] | 3862 | if (leaflist->when && yang_check_ext_instance(module, &leaflist->when->ext, leaflist->when->ext_size, leaflist->when, unres)) { |
| 3863 | goto error; |
| 3864 | } |
PavolVican | 38104a3 | 2017-02-08 12:25:23 +0100 | [diff] [blame] | 3865 | if (yang_check_must(module, leaflist->must, leaflist->must_size, unres)) { |
| 3866 | goto error; |
| 3867 | } |
PavolVican | 59ba460 | 2017-02-08 11:53:32 +0100 | [diff] [blame] | 3868 | |
Pavol Vican | 36aff86 | 2016-11-26 17:07:05 +0100 | [diff] [blame] | 3869 | /* check XPath dependencies */ |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 3870 | if (!(module->ctx->models.flags & LY_CTX_TRUSTED) && (leaflist->when || leaflist->must_size)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3871 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 3872 | if (lyxp_node_check_syntax((struct lys_node *)leaflist)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3873 | goto error; |
| 3874 | } |
| 3875 | } else { |
| 3876 | if (unres_schema_add_node(module, unres, leaflist, UNRES_XPATH, NULL) == -1) { |
| 3877 | goto error; |
| 3878 | } |
| 3879 | } |
Pavol Vican | 36aff86 | 2016-11-26 17:07:05 +0100 | [diff] [blame] | 3880 | } |
| 3881 | |
| 3882 | return EXIT_SUCCESS; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3883 | |
Pavol Vican | 36aff86 | 2016-11-26 17:07:05 +0100 | [diff] [blame] | 3884 | error: |
| 3885 | return EXIT_FAILURE; |
| 3886 | } |
| 3887 | |
| 3888 | static int |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 3889 | yang_check_list(struct lys_module *module, struct lys_node_list *list, struct lys_node **child, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3890 | int options, struct unres_schema *unres) |
Pavol Vican | d8136a4 | 2016-11-27 13:28:04 +0100 | [diff] [blame] | 3891 | { |
Pavol Vican | fda8c80 | 2016-12-03 02:00:42 +0100 | [diff] [blame] | 3892 | struct lys_node *node; |
| 3893 | |
Pavol Vican | d8136a4 | 2016-11-27 13:28:04 +0100 | [diff] [blame] | 3894 | if (yang_check_typedef(module, (struct lys_node *)list, unres)) { |
| 3895 | goto error; |
| 3896 | } |
| 3897 | |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 3898 | if (yang_check_iffeatures(module, NULL, list, LIST_KEYWORD, unres)) { |
| 3899 | goto error; |
Pavol Vican | d8136a4 | 2016-11-27 13:28:04 +0100 | [diff] [blame] | 3900 | } |
| 3901 | |
Pavol Vican | fda8c80 | 2016-12-03 02:00:42 +0100 | [diff] [blame] | 3902 | if (list->flags & LYS_CONFIG_R) { |
| 3903 | /* RFC 6020, 7.7.5 - ignore ordering when the list represents state data |
| 3904 | * ignore oredering MASK - 0x7F |
| 3905 | */ |
| 3906 | list->flags &= 0x7F; |
| 3907 | } |
| 3908 | /* check - if list is configuration, key statement is mandatory |
| 3909 | * (but only if we are not in a grouping or augment, then the check is deferred) */ |
PavolVican | c68dfea | 2017-02-21 15:40:43 +0100 | [diff] [blame] | 3910 | for (node = (struct lys_node *)list; node && !(node->nodetype & (LYS_GROUPING | LYS_AUGMENT | LYS_EXT)); node = node->parent); |
Pavol Vican | fda8c80 | 2016-12-03 02:00:42 +0100 | [diff] [blame] | 3911 | if (!node && (list->flags & LYS_CONFIG_W) && !list->keys) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3912 | LOGVAL(module->ctx, LYE_MISSCHILDSTMT, LY_VLOG_LYS, list, "key", "list"); |
Pavol Vican | fda8c80 | 2016-12-03 02:00:42 +0100 | [diff] [blame] | 3913 | goto error; |
| 3914 | } |
| 3915 | |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3916 | if (yang_check_nodes(module, (struct lys_node *)list, *child, options, unres)) { |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 3917 | *child = NULL; |
| 3918 | goto error; |
| 3919 | } |
| 3920 | *child = NULL; |
| 3921 | |
Pavol Vican | d8136a4 | 2016-11-27 13:28:04 +0100 | [diff] [blame] | 3922 | if (list->keys && yang_read_key(module, list, unres)) { |
| 3923 | goto error; |
| 3924 | } |
| 3925 | |
| 3926 | if (yang_read_unique(module, list, unres)) { |
| 3927 | goto error; |
| 3928 | } |
| 3929 | |
PavolVican | 59ba460 | 2017-02-08 11:53:32 +0100 | [diff] [blame] | 3930 | if (list->when && yang_check_ext_instance(module, &list->when->ext, list->when->ext_size, list->when, unres)) { |
| 3931 | goto error; |
| 3932 | } |
PavolVican | 38104a3 | 2017-02-08 12:25:23 +0100 | [diff] [blame] | 3933 | if (yang_check_must(module, list->must, list->must_size, unres)) { |
| 3934 | goto error; |
| 3935 | } |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3936 | |
Pavol Vican | d8136a4 | 2016-11-27 13:28:04 +0100 | [diff] [blame] | 3937 | /* check XPath dependencies */ |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 3938 | if (!(module->ctx->models.flags & LY_CTX_TRUSTED) && (list->when || list->must_size)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3939 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 3940 | if (lyxp_node_check_syntax((struct lys_node *)list)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3941 | goto error; |
| 3942 | } |
| 3943 | } else { |
| 3944 | if (unres_schema_add_node(module, unres, list, UNRES_XPATH, NULL) == -1) { |
| 3945 | goto error; |
| 3946 | } |
| 3947 | } |
Pavol Vican | d8136a4 | 2016-11-27 13:28:04 +0100 | [diff] [blame] | 3948 | } |
| 3949 | |
| 3950 | return EXIT_SUCCESS; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 3951 | |
Pavol Vican | d8136a4 | 2016-11-27 13:28:04 +0100 | [diff] [blame] | 3952 | error: |
| 3953 | return EXIT_FAILURE; |
| 3954 | } |
| 3955 | |
| 3956 | static int |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 3957 | yang_check_choice(struct lys_module *module, struct lys_node_choice *choice, struct lys_node **child, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3958 | int options, struct unres_schema *unres) |
Pavol Vican | 36ace10 | 2016-11-28 11:46:59 +0100 | [diff] [blame] | 3959 | { |
| 3960 | char *value; |
Pavol Vican | 36ace10 | 2016-11-28 11:46:59 +0100 | [diff] [blame] | 3961 | |
PavolVican | a08d365 | 2016-12-29 21:07:47 +0100 | [diff] [blame] | 3962 | if (yang_check_iffeatures(module, NULL, choice, CHOICE_KEYWORD, unres)) { |
| 3963 | free(choice->dflt); |
| 3964 | choice->dflt = NULL; |
| 3965 | goto error; |
| 3966 | } |
| 3967 | |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 3968 | if (yang_check_nodes(module, (struct lys_node *)choice, *child, options, unres)) { |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 3969 | *child = NULL; |
| 3970 | free(choice->dflt); |
| 3971 | choice->dflt = NULL; |
| 3972 | goto error; |
| 3973 | } |
| 3974 | *child = NULL; |
| 3975 | |
Pavol Vican | 36ace10 | 2016-11-28 11:46:59 +0100 | [diff] [blame] | 3976 | if (choice->dflt) { |
| 3977 | value = (char *)choice->dflt; |
| 3978 | choice->dflt = NULL; |
| 3979 | if (unres_schema_add_str(module, unres, choice, UNRES_CHOICE_DFLT, value) == -1) { |
| 3980 | free(value); |
| 3981 | goto error; |
| 3982 | } |
| 3983 | free(value); |
| 3984 | } |
| 3985 | |
PavolVican | 59ba460 | 2017-02-08 11:53:32 +0100 | [diff] [blame] | 3986 | if (choice->when && yang_check_ext_instance(module, &choice->when->ext, choice->when->ext_size, choice->when, unres)) { |
| 3987 | goto error; |
| 3988 | } |
| 3989 | |
Pavol Vican | 36ace10 | 2016-11-28 11:46:59 +0100 | [diff] [blame] | 3990 | /* check XPath dependencies */ |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 3991 | if (!(module->ctx->models.flags & LY_CTX_TRUSTED) && choice->when) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3992 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 3993 | if (lyxp_node_check_syntax((struct lys_node *)choice)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 3994 | goto error; |
| 3995 | } |
| 3996 | } else { |
| 3997 | if (unres_schema_add_node(module, unres, choice, UNRES_XPATH, NULL) == -1) { |
| 3998 | goto error; |
| 3999 | } |
| 4000 | } |
Pavol Vican | 36ace10 | 2016-11-28 11:46:59 +0100 | [diff] [blame] | 4001 | } |
| 4002 | |
| 4003 | return EXIT_SUCCESS; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4004 | |
Pavol Vican | 36ace10 | 2016-11-28 11:46:59 +0100 | [diff] [blame] | 4005 | error: |
| 4006 | return EXIT_FAILURE; |
| 4007 | } |
| 4008 | |
| 4009 | static int |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 4010 | yang_check_rpc_action(struct lys_module *module, struct lys_node_rpc_action *rpc, struct lys_node **child, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4011 | int options, struct unres_schema *unres) |
Pavol Vican | ebc9ef8 | 2016-11-28 16:46:49 +0100 | [diff] [blame] | 4012 | { |
Pavol Vican | ebc9ef8 | 2016-11-28 16:46:49 +0100 | [diff] [blame] | 4013 | struct lys_node *node; |
| 4014 | |
| 4015 | if (rpc->nodetype == LYS_ACTION) { |
| 4016 | for (node = rpc->parent; node; node = lys_parent(node)) { |
| 4017 | if ((node->nodetype & (LYS_RPC | LYS_ACTION | LYS_NOTIF)) |
Pavol Vican | 73ff803 | 2016-12-04 15:03:51 +0100 | [diff] [blame] | 4018 | || ((node->nodetype == LYS_LIST) && !((struct lys_node_list *)node)->keys)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4019 | LOGVAL(module->ctx, LYE_INPAR, LY_VLOG_LYS, rpc->parent, strnodetype(node->nodetype), "action"); |
Pavol Vican | ebc9ef8 | 2016-11-28 16:46:49 +0100 | [diff] [blame] | 4020 | goto error; |
| 4021 | } |
| 4022 | } |
| 4023 | } |
| 4024 | if (yang_check_typedef(module, (struct lys_node *)rpc, unres)) { |
| 4025 | goto error; |
| 4026 | } |
| 4027 | |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 4028 | if (yang_check_iffeatures(module, NULL, rpc, RPC_KEYWORD, unres)) { |
| 4029 | goto error; |
Pavol Vican | ebc9ef8 | 2016-11-28 16:46:49 +0100 | [diff] [blame] | 4030 | } |
| 4031 | |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4032 | if (yang_check_nodes(module, (struct lys_node *)rpc, *child, options | LYS_PARSE_OPT_CFG_IGNORE, unres)) { |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 4033 | *child = NULL; |
| 4034 | goto error; |
| 4035 | } |
| 4036 | *child = NULL; |
| 4037 | |
Pavol Vican | ebc9ef8 | 2016-11-28 16:46:49 +0100 | [diff] [blame] | 4038 | return EXIT_SUCCESS; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4039 | |
Pavol Vican | ebc9ef8 | 2016-11-28 16:46:49 +0100 | [diff] [blame] | 4040 | error: |
| 4041 | return EXIT_FAILURE; |
| 4042 | } |
| 4043 | |
| 4044 | static int |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 4045 | yang_check_notif(struct lys_module *module, struct lys_node_notif *notif, struct lys_node **child, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4046 | int options, struct unres_schema *unres) |
Pavol Vican | 29bf880 | 2016-11-28 20:44:57 +0100 | [diff] [blame] | 4047 | { |
Pavol Vican | 29bf880 | 2016-11-28 20:44:57 +0100 | [diff] [blame] | 4048 | if (yang_check_typedef(module, (struct lys_node *)notif, unres)) { |
| 4049 | goto error; |
| 4050 | } |
| 4051 | |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 4052 | if (yang_check_iffeatures(module, NULL, notif, NOTIFICATION_KEYWORD, unres)) { |
| 4053 | goto error; |
Pavol Vican | 29bf880 | 2016-11-28 20:44:57 +0100 | [diff] [blame] | 4054 | } |
| 4055 | |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4056 | if (yang_check_nodes(module, (struct lys_node *)notif, *child, options | LYS_PARSE_OPT_CFG_IGNORE, unres)) { |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 4057 | *child = NULL; |
| 4058 | goto error; |
| 4059 | } |
| 4060 | *child = NULL; |
| 4061 | |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4062 | if (yang_check_must(module, notif->must, notif->must_size, unres)) { |
| 4063 | goto error; |
| 4064 | } |
| 4065 | |
| 4066 | /* check XPath dependencies */ |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 4067 | if (!(module->ctx->models.flags & LY_CTX_TRUSTED) && notif->must_size) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4068 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 4069 | if (lyxp_node_check_syntax((struct lys_node *)notif)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4070 | goto error; |
| 4071 | } |
| 4072 | } else { |
| 4073 | if (unres_schema_add_node(module, unres, notif, UNRES_XPATH, NULL) == -1) { |
| 4074 | goto error; |
| 4075 | } |
PavolVican | 38104a3 | 2017-02-08 12:25:23 +0100 | [diff] [blame] | 4076 | } |
Pavol Vican | 29bf880 | 2016-11-28 20:44:57 +0100 | [diff] [blame] | 4077 | } |
| 4078 | |
| 4079 | return EXIT_SUCCESS; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4080 | |
Pavol Vican | 29bf880 | 2016-11-28 20:44:57 +0100 | [diff] [blame] | 4081 | error: |
| 4082 | return EXIT_FAILURE; |
| 4083 | } |
| 4084 | |
| 4085 | static int |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4086 | yang_check_augment(struct lys_module *module, struct lys_node_augment *augment, int options, struct unres_schema *unres) |
Pavol Vican | 3b5e82a | 2016-11-29 21:41:56 +0100 | [diff] [blame] | 4087 | { |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 4088 | struct lys_node *child; |
Pavol Vican | 3b5e82a | 2016-11-29 21:41:56 +0100 | [diff] [blame] | 4089 | |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 4090 | child = augment->child; |
| 4091 | augment->child = NULL; |
| 4092 | |
PavolVican | a08d365 | 2016-12-29 21:07:47 +0100 | [diff] [blame] | 4093 | if (yang_check_iffeatures(module, NULL, augment, AUGMENT_KEYWORD, unres)) { |
| 4094 | yang_free_nodes(module->ctx, child); |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 4095 | goto error; |
| 4096 | } |
| 4097 | |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4098 | if (yang_check_nodes(module, (struct lys_node *)augment, child, options, unres)) { |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 4099 | goto error; |
| 4100 | } |
| 4101 | |
PavolVican | fa9510e | 2017-02-08 17:20:46 +0100 | [diff] [blame] | 4102 | if (yang_check_ext_instance(module, &augment->ext, augment->ext_size, augment, unres)) { |
| 4103 | goto error; |
| 4104 | } |
| 4105 | |
PavolVican | 59ba460 | 2017-02-08 11:53:32 +0100 | [diff] [blame] | 4106 | if (augment->when && yang_check_ext_instance(module, &augment->when->ext, augment->when->ext_size, augment->when, unres)) { |
| 4107 | goto error; |
| 4108 | } |
| 4109 | |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 4110 | /* check XPath dependencies */ |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 4111 | if (!(module->ctx->models.flags & LY_CTX_TRUSTED) && augment->when) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4112 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 4113 | if (lyxp_node_check_syntax((struct lys_node *)augment)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4114 | goto error; |
| 4115 | } |
| 4116 | } else { |
| 4117 | if (unres_schema_add_node(module, unres, augment, UNRES_XPATH, NULL) == -1) { |
| 4118 | goto error; |
| 4119 | } |
| 4120 | } |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 4121 | } |
| 4122 | |
| 4123 | return EXIT_SUCCESS; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4124 | |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 4125 | error: |
| 4126 | return EXIT_FAILURE; |
| 4127 | } |
| 4128 | |
| 4129 | static int |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4130 | yang_check_uses(struct lys_module *module, struct lys_node_uses *uses, int options, struct unres_schema *unres) |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 4131 | { |
| 4132 | uint i, size; |
| 4133 | |
| 4134 | size = uses->augment_size; |
| 4135 | uses->augment_size = 0; |
| 4136 | |
| 4137 | if (yang_check_iffeatures(module, NULL, uses, USES_KEYWORD, unres)) { |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 4138 | goto error; |
Pavol Vican | 3b5e82a | 2016-11-29 21:41:56 +0100 | [diff] [blame] | 4139 | } |
| 4140 | |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 4141 | for (i = 0; i < uses->refine_size; ++i) { |
PavolVican | 77374ee | 2017-02-08 15:18:45 +0100 | [diff] [blame] | 4142 | if (yang_check_iffeatures(module, &uses->refine[i], uses, REFINE_KEYWORD, unres)) { |
| 4143 | goto error; |
| 4144 | } |
| 4145 | if (yang_check_must(module, uses->refine[i].must, uses->refine[i].must_size, unres)) { |
| 4146 | goto error; |
| 4147 | } |
| 4148 | if (yang_check_ext_instance(module, &uses->refine[i].ext, uses->refine[i].ext_size, &uses->refine[i], unres)) { |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 4149 | goto error; |
Pavol Vican | 3b5e82a | 2016-11-29 21:41:56 +0100 | [diff] [blame] | 4150 | } |
| 4151 | } |
| 4152 | |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 4153 | for (i = 0; i < size; ++i) { |
| 4154 | uses->augment_size++; |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4155 | if (yang_check_augment(module, &uses->augment[i], options, unres)) { |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 4156 | goto error; |
| 4157 | } |
| 4158 | } |
| 4159 | |
Pavol Vican | 3b5e82a | 2016-11-29 21:41:56 +0100 | [diff] [blame] | 4160 | if (unres_schema_add_node(module, unres, uses, UNRES_USES, NULL) == -1) { |
| 4161 | goto error; |
| 4162 | } |
| 4163 | |
PavolVican | 59ba460 | 2017-02-08 11:53:32 +0100 | [diff] [blame] | 4164 | if (uses->when && yang_check_ext_instance(module, &uses->when->ext, uses->when->ext_size, uses->when, unres)) { |
| 4165 | goto error; |
| 4166 | } |
| 4167 | |
Pavol Vican | 3b5e82a | 2016-11-29 21:41:56 +0100 | [diff] [blame] | 4168 | /* check XPath dependencies */ |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 4169 | if (!(module->ctx->models.flags & LY_CTX_TRUSTED) && uses->when) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4170 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 4171 | if (lyxp_node_check_syntax((struct lys_node *)uses)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4172 | goto error; |
| 4173 | } |
| 4174 | } else { |
| 4175 | if (unres_schema_add_node(module, unres, uses, UNRES_XPATH, NULL) == -1) { |
| 4176 | goto error; |
| 4177 | } |
| 4178 | } |
Pavol Vican | 3b5e82a | 2016-11-29 21:41:56 +0100 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | return EXIT_SUCCESS; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4182 | |
Pavol Vican | 3b5e82a | 2016-11-29 21:41:56 +0100 | [diff] [blame] | 4183 | error: |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 4184 | for (i = uses->augment_size; i < size; ++i) { |
| 4185 | yang_free_augment(module->ctx, &uses->augment[i]); |
| 4186 | } |
Pavol Vican | 3b5e82a | 2016-11-29 21:41:56 +0100 | [diff] [blame] | 4187 | return EXIT_FAILURE; |
| 4188 | } |
| 4189 | |
| 4190 | static int |
PavolVican | 59ba460 | 2017-02-08 11:53:32 +0100 | [diff] [blame] | 4191 | yang_check_anydata(struct lys_module *module, struct lys_node_anydata *anydata, struct lys_node **child, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4192 | int options, struct unres_schema *unres) |
PavolVican | 59ba460 | 2017-02-08 11:53:32 +0100 | [diff] [blame] | 4193 | { |
| 4194 | if (yang_check_iffeatures(module, NULL, anydata, ANYDATA_KEYWORD, unres)) { |
| 4195 | goto error; |
| 4196 | } |
| 4197 | |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4198 | if (yang_check_nodes(module, (struct lys_node *)anydata, *child, options, unres)) { |
PavolVican | 59ba460 | 2017-02-08 11:53:32 +0100 | [diff] [blame] | 4199 | *child = NULL; |
| 4200 | goto error; |
| 4201 | } |
| 4202 | *child = NULL; |
| 4203 | |
| 4204 | if (anydata->when && yang_check_ext_instance(module, &anydata->when->ext, anydata->when->ext_size, anydata->when, unres)) { |
| 4205 | goto error; |
| 4206 | } |
PavolVican | 38104a3 | 2017-02-08 12:25:23 +0100 | [diff] [blame] | 4207 | if (yang_check_must(module, anydata->must, anydata->must_size, unres)) { |
| 4208 | goto error; |
| 4209 | } |
PavolVican | 59ba460 | 2017-02-08 11:53:32 +0100 | [diff] [blame] | 4210 | |
| 4211 | /* check XPath dependencies */ |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 4212 | if (!(module->ctx->models.flags & LY_CTX_TRUSTED) && (anydata->when || anydata->must_size)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4213 | if (options & LYS_PARSE_OPT_INGRP) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 4214 | if (lyxp_node_check_syntax((struct lys_node *)anydata)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4215 | goto error; |
| 4216 | } |
| 4217 | } else { |
| 4218 | if (unres_schema_add_node(module, unres, anydata, UNRES_XPATH, NULL) == -1) { |
| 4219 | goto error; |
| 4220 | } |
| 4221 | } |
PavolVican | 59ba460 | 2017-02-08 11:53:32 +0100 | [diff] [blame] | 4222 | } |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4223 | |
PavolVican | 59ba460 | 2017-02-08 11:53:32 +0100 | [diff] [blame] | 4224 | return EXIT_SUCCESS; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4225 | |
PavolVican | 59ba460 | 2017-02-08 11:53:32 +0100 | [diff] [blame] | 4226 | error: |
| 4227 | return EXIT_FAILURE; |
| 4228 | } |
| 4229 | |
| 4230 | static int |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 4231 | yang_check_nodes(struct lys_module *module, struct lys_node *parent, struct lys_node *nodes, |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4232 | int options, struct unres_schema *unres) |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 4233 | { |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 4234 | struct lys_node *node = nodes, *sibling, *child; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 4235 | int i; |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 4236 | |
| 4237 | while (node) { |
| 4238 | sibling = node->next; |
| 4239 | child = node->child; |
| 4240 | node->next = NULL; |
| 4241 | node->child = NULL; |
PavolVican | bd1d1ae | 2017-07-20 00:06:00 +0200 | [diff] [blame] | 4242 | node->parent = NULL; |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 4243 | node->prev = node; |
| 4244 | |
PavolVican | 05c4f9b | 2017-09-07 13:33:54 +0200 | [diff] [blame] | 4245 | if (lys_node_addchild(parent, module->type ? ((struct lys_submodule *)module)->belongsto: module, node) || |
| 4246 | check_status_flag(node, parent)) { |
Pavol Vican | 24ba7f6 | 2016-11-28 12:15:20 +0100 | [diff] [blame] | 4247 | lys_node_unlink(node); |
PavolVican | 4b80d04 | 2017-02-23 14:30:27 +0100 | [diff] [blame] | 4248 | yang_free_nodes(module->ctx, node); |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 4249 | goto error; |
| 4250 | } |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4251 | store_config_flag(node, options); |
PavolVican | 70ce745 | 2017-02-01 15:39:39 +0100 | [diff] [blame] | 4252 | if (yang_check_ext_instance(module, &node->ext, node->ext_size, node, unres)) { |
| 4253 | goto error; |
| 4254 | } |
Michal Vasko | e59ada9 | 2018-02-22 14:05:34 +0100 | [diff] [blame] | 4255 | for (i = 0; i < node->ext_size; ++i) { |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 4256 | if (node->ext[i]->flags & LYEXT_OPT_VALID) { |
Michal Vasko | 1bdfd43 | 2018-03-09 09:30:19 +0100 | [diff] [blame] | 4257 | node->flags |= LYS_VALID_EXT; |
PavolVican | 92f2362 | 2017-12-12 13:35:56 +0100 | [diff] [blame] | 4258 | break; |
| 4259 | } |
| 4260 | } |
Pavol Vican | fda8c80 | 2016-12-03 02:00:42 +0100 | [diff] [blame] | 4261 | |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 4262 | switch (node->nodetype) { |
| 4263 | case LYS_GROUPING: |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 4264 | if (yang_check_typedef(module, node, unres)) { |
| 4265 | goto error; |
| 4266 | } |
| 4267 | if (yang_check_iffeatures(module, NULL, node, GROUPING_KEYWORD, unres)) { |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 4268 | goto error; |
| 4269 | } |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4270 | if (yang_check_nodes(module, node, child, options | LYS_PARSE_OPT_INGRP, unres)) { |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 4271 | child = NULL; |
| 4272 | goto error; |
| 4273 | } |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 4274 | break; |
Pavol Vican | c54a8f7 | 2016-11-23 16:45:55 +0100 | [diff] [blame] | 4275 | case LYS_CONTAINER: |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4276 | if (yang_check_container(module, (struct lys_node_container *)node, &child, options, unres)) { |
Pavol Vican | c54a8f7 | 2016-11-23 16:45:55 +0100 | [diff] [blame] | 4277 | goto error; |
| 4278 | } |
| 4279 | break; |
Pavol Vican | a69aff2 | 2016-11-24 18:23:50 +0100 | [diff] [blame] | 4280 | case LYS_LEAF: |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4281 | if (yang_check_leaf(module, (struct lys_node_leaf *)node, options, unres)) { |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 4282 | child = NULL; |
Pavol Vican | a69aff2 | 2016-11-24 18:23:50 +0100 | [diff] [blame] | 4283 | goto error; |
| 4284 | } |
| 4285 | break; |
Pavol Vican | 36aff86 | 2016-11-26 17:07:05 +0100 | [diff] [blame] | 4286 | case LYS_LEAFLIST: |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4287 | if (yang_check_leaflist(module, (struct lys_node_leaflist *)node, options, unres)) { |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 4288 | child = NULL; |
Pavol Vican | 36aff86 | 2016-11-26 17:07:05 +0100 | [diff] [blame] | 4289 | goto error; |
| 4290 | } |
| 4291 | break; |
Pavol Vican | d8136a4 | 2016-11-27 13:28:04 +0100 | [diff] [blame] | 4292 | case LYS_LIST: |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4293 | if (yang_check_list(module, (struct lys_node_list *)node, &child, options, unres)) { |
Pavol Vican | d8136a4 | 2016-11-27 13:28:04 +0100 | [diff] [blame] | 4294 | goto error; |
| 4295 | } |
| 4296 | break; |
Pavol Vican | 36ace10 | 2016-11-28 11:46:59 +0100 | [diff] [blame] | 4297 | case LYS_CHOICE: |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4298 | if (yang_check_choice(module, (struct lys_node_choice *)node, &child, options, unres)) { |
Pavol Vican | 36ace10 | 2016-11-28 11:46:59 +0100 | [diff] [blame] | 4299 | goto error; |
| 4300 | } |
| 4301 | break; |
Pavol Vican | a420bac | 2016-11-28 14:51:54 +0100 | [diff] [blame] | 4302 | case LYS_CASE: |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 4303 | if (yang_check_iffeatures(module, NULL, node, CASE_KEYWORD, unres)) { |
Pavol Vican | a420bac | 2016-11-28 14:51:54 +0100 | [diff] [blame] | 4304 | goto error; |
| 4305 | } |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4306 | if (yang_check_nodes(module, node, child, options, unres)) { |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 4307 | child = NULL; |
| 4308 | goto error; |
| 4309 | } |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4310 | if (((struct lys_node_case *)node)->when) { |
| 4311 | if (yang_check_ext_instance(module, &((struct lys_node_case *)node)->when->ext, |
| 4312 | ((struct lys_node_case *)node)->when->ext_size, ((struct lys_node_case *)node)->when, unres)) { |
| 4313 | goto error; |
| 4314 | } |
| 4315 | /* check XPath dependencies */ |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 4316 | if (!(module->ctx->models.flags & LY_CTX_TRUSTED) && (options & LYS_PARSE_OPT_INGRP)) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 4317 | if (lyxp_node_check_syntax(node)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4318 | goto error; |
| 4319 | } |
| 4320 | } else { |
| 4321 | if (unres_schema_add_node(module, unres, node, UNRES_XPATH, NULL) == -1) { |
| 4322 | goto error; |
| 4323 | } |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4324 | } |
| 4325 | } |
Pavol Vican | a420bac | 2016-11-28 14:51:54 +0100 | [diff] [blame] | 4326 | break; |
Pavol Vican | bfa1a58 | 2016-11-28 15:35:59 +0100 | [diff] [blame] | 4327 | case LYS_ANYDATA: |
| 4328 | case LYS_ANYXML: |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4329 | if (yang_check_anydata(module, (struct lys_node_anydata *)node, &child, options, unres)) { |
Pavol Vican | bfa1a58 | 2016-11-28 15:35:59 +0100 | [diff] [blame] | 4330 | goto error; |
| 4331 | } |
| 4332 | break; |
Pavol Vican | ebc9ef8 | 2016-11-28 16:46:49 +0100 | [diff] [blame] | 4333 | case LYS_RPC: |
| 4334 | case LYS_ACTION: |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4335 | if (yang_check_rpc_action(module, (struct lys_node_rpc_action *)node, &child, options, unres)){ |
Pavol Vican | ebc9ef8 | 2016-11-28 16:46:49 +0100 | [diff] [blame] | 4336 | goto error; |
| 4337 | } |
| 4338 | break; |
Pavol Vican | 7872939 | 2016-11-28 17:18:22 +0100 | [diff] [blame] | 4339 | case LYS_INPUT: |
| 4340 | case LYS_OUTPUT: |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 4341 | if (yang_check_typedef(module, node, unres)) { |
| 4342 | goto error; |
| 4343 | } |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4344 | if (yang_check_nodes(module, node, child, options, unres)) { |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 4345 | child = NULL; |
| 4346 | goto error; |
| 4347 | } |
PavolVican | 38104a3 | 2017-02-08 12:25:23 +0100 | [diff] [blame] | 4348 | if (((struct lys_node_inout *)node)->must_size) { |
| 4349 | if (yang_check_must(module, ((struct lys_node_inout *)node)->must, ((struct lys_node_inout *)node)->must_size, unres)) { |
| 4350 | goto error; |
| 4351 | } |
| 4352 | /* check XPath dependencies */ |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 4353 | if (!(module->ctx->models.flags & LY_CTX_TRUSTED) && (options & LYS_PARSE_OPT_INGRP)) { |
Michal Vasko | 364918a | 2017-03-17 13:23:46 +0100 | [diff] [blame] | 4354 | if (lyxp_node_check_syntax(node)) { |
Michal Vasko | 89afc11 | 2017-03-16 13:57:28 +0100 | [diff] [blame] | 4355 | goto error; |
| 4356 | } |
| 4357 | } else { |
| 4358 | if (unres_schema_add_node(module, unres, node, UNRES_XPATH, NULL) == -1) { |
| 4359 | goto error; |
| 4360 | } |
PavolVican | 38104a3 | 2017-02-08 12:25:23 +0100 | [diff] [blame] | 4361 | } |
Pavol Vican | 7872939 | 2016-11-28 17:18:22 +0100 | [diff] [blame] | 4362 | } |
Pavol Vican | 7872939 | 2016-11-28 17:18:22 +0100 | [diff] [blame] | 4363 | break; |
Pavol Vican | 29bf880 | 2016-11-28 20:44:57 +0100 | [diff] [blame] | 4364 | case LYS_NOTIF: |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4365 | if (yang_check_notif(module, (struct lys_node_notif *)node, &child, options, unres)) { |
Pavol Vican | 29bf880 | 2016-11-28 20:44:57 +0100 | [diff] [blame] | 4366 | goto error; |
| 4367 | } |
| 4368 | break; |
Pavol Vican | 3b5e82a | 2016-11-29 21:41:56 +0100 | [diff] [blame] | 4369 | case LYS_USES: |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4370 | if (yang_check_uses(module, (struct lys_node_uses *)node, options, unres)) { |
PavolVican | e87cb93 | 2016-12-30 15:36:18 +0100 | [diff] [blame] | 4371 | child = NULL; |
Pavol Vican | 3b5e82a | 2016-11-29 21:41:56 +0100 | [diff] [blame] | 4372 | goto error; |
| 4373 | } |
| 4374 | break; |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 4375 | default: |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4376 | LOGINT(module->ctx); |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 4377 | goto error; |
| 4378 | } |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 4379 | node = sibling; |
| 4380 | } |
| 4381 | |
| 4382 | return EXIT_SUCCESS; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4383 | |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 4384 | error: |
| 4385 | yang_free_nodes(module->ctx, sibling); |
| 4386 | yang_free_nodes(module->ctx, child); |
| 4387 | return EXIT_FAILURE; |
| 4388 | } |
| 4389 | |
| 4390 | static int |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4391 | yang_check_deviate(struct lys_module *module, struct unres_schema *unres, struct lys_deviate *deviate, |
| 4392 | struct lys_node *dev_target, struct ly_set *dflt_check) |
| 4393 | { |
| 4394 | struct lys_node_leaflist *llist; |
| 4395 | struct lys_type *type; |
| 4396 | struct lys_tpdf *tmp_parent; |
| 4397 | int i, j; |
| 4398 | |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 4399 | if (yang_check_ext_instance(module, &deviate->ext, deviate->ext_size, deviate, unres)) { |
| 4400 | goto error; |
| 4401 | } |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4402 | if (deviate->must_size && yang_check_deviate_must(module, unres, deviate, dev_target)) { |
| 4403 | goto error; |
| 4404 | } |
| 4405 | if (deviate->unique && yang_check_deviate_unique(module, deviate, dev_target)) { |
| 4406 | goto error; |
| 4407 | } |
| 4408 | if (deviate->dflt_size) { |
| 4409 | if (yang_read_deviate_default(module, deviate, dev_target, dflt_check)) { |
| 4410 | goto error; |
| 4411 | } |
| 4412 | if (dev_target->nodetype == LYS_LEAFLIST && deviate->mod == LY_DEVIATE_DEL) { |
| 4413 | /* consolidate the final list in the target after removing items from it */ |
| 4414 | llist = (struct lys_node_leaflist *)dev_target; |
| 4415 | for (i = j = 0; j < llist->dflt_size; j++) { |
| 4416 | llist->dflt[i] = llist->dflt[j]; |
| 4417 | if (llist->dflt[i]) { |
| 4418 | i++; |
| 4419 | } |
| 4420 | } |
| 4421 | llist->dflt_size = i + 1; |
| 4422 | } |
| 4423 | } |
| 4424 | |
| 4425 | if (deviate->max_set && yang_read_deviate_minmax(deviate, dev_target, deviate->max, 1)) { |
| 4426 | goto error; |
| 4427 | } |
| 4428 | |
| 4429 | if (deviate->min_set && yang_read_deviate_minmax(deviate, dev_target, deviate->min, 0)) { |
| 4430 | goto error; |
| 4431 | } |
| 4432 | |
| 4433 | if (deviate->units && yang_read_deviate_units(module->ctx, deviate, dev_target)) { |
| 4434 | goto error; |
| 4435 | } |
| 4436 | |
| 4437 | if ((deviate->flags & LYS_CONFIG_MASK)) { |
| 4438 | /* add and replace are the same in this case */ |
| 4439 | /* remove current config value of the target ... */ |
| 4440 | dev_target->flags &= ~LYS_CONFIG_MASK; |
| 4441 | |
| 4442 | /* ... and replace it with the value specified in deviation */ |
| 4443 | dev_target->flags |= deviate->flags & LYS_CONFIG_MASK; |
| 4444 | } |
| 4445 | |
| 4446 | if ((deviate->flags & LYS_MAND_MASK) && yang_check_deviate_mandatory(deviate, dev_target)) { |
| 4447 | goto error; |
| 4448 | } |
| 4449 | |
| 4450 | if (deviate->type) { |
| 4451 | /* check target node type */ |
| 4452 | if (dev_target->nodetype == LYS_LEAF) { |
| 4453 | type = &((struct lys_node_leaf *)dev_target)->type; |
| 4454 | } else if (dev_target->nodetype == LYS_LEAFLIST) { |
| 4455 | type = &((struct lys_node_leaflist *)dev_target)->type; |
| 4456 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4457 | LOGVAL(module->ctx, LYE_INSTMT, LY_VLOG_NONE, NULL, "type"); |
| 4458 | LOGVAL(module->ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Target node does not allow \"type\" property."); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4459 | goto error; |
| 4460 | } |
| 4461 | /* remove type and initialize it */ |
| 4462 | tmp_parent = type->parent; |
Radek Krejci | 5138e9f | 2017-04-12 13:10:46 +0200 | [diff] [blame] | 4463 | lys_type_free(module->ctx, type, NULL); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4464 | memcpy(type, deviate->type, sizeof *deviate->type); |
| 4465 | free(deviate->type); |
| 4466 | deviate->type = type; |
| 4467 | deviate->type->parent = tmp_parent; |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 4468 | if (yang_fill_type(module, type, (struct yang_type *)type->der, tmp_parent, unres)) { |
| 4469 | goto error; |
| 4470 | } |
| 4471 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4472 | if (unres_schema_add_node(module, unres, deviate->type, UNRES_TYPE_DER, dev_target) == -1) { |
| 4473 | goto error; |
| 4474 | } |
| 4475 | } |
| 4476 | |
| 4477 | return EXIT_SUCCESS; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4478 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4479 | error: |
| 4480 | if (deviate->type) { |
| 4481 | yang_type_free(module->ctx, deviate->type); |
| 4482 | deviate->type = NULL; |
| 4483 | } |
| 4484 | return EXIT_FAILURE; |
| 4485 | } |
| 4486 | |
| 4487 | static int |
| 4488 | yang_check_deviation(struct lys_module *module, struct unres_schema *unres, struct lys_deviation *dev) |
| 4489 | { |
| 4490 | int rc; |
| 4491 | uint i; |
| 4492 | struct lys_node *dev_target = NULL, *parent; |
Michal Vasko | 5057671 | 2017-07-28 12:28:33 +0200 | [diff] [blame] | 4493 | struct ly_set *dflt_check = ly_set_new(), *set; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4494 | unsigned int u; |
| 4495 | const char *value, *target_name; |
| 4496 | struct lys_node_leaflist *llist; |
| 4497 | struct lys_node_leaf *leaf; |
| 4498 | struct unres_schema tmp_unres; |
| 4499 | struct lys_module *mod; |
| 4500 | |
| 4501 | /* resolve target node */ |
Michal Vasko | 5057671 | 2017-07-28 12:28:33 +0200 | [diff] [blame] | 4502 | rc = resolve_schema_nodeid(dev->target_name, NULL, module, &set, 0, 1); |
| 4503 | if (rc == -1) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4504 | LOGVAL(module->ctx, LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, "deviation"); |
Michal Vasko | 5057671 | 2017-07-28 12:28:33 +0200 | [diff] [blame] | 4505 | ly_set_free(set); |
Michal Vasko | 9b7a33b | 2018-05-14 15:23:10 +0200 | [diff] [blame] | 4506 | i = 0; |
| 4507 | goto free_type_error; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4508 | } |
Michal Vasko | 5057671 | 2017-07-28 12:28:33 +0200 | [diff] [blame] | 4509 | dev_target = set->set.s[0]; |
| 4510 | ly_set_free(set); |
| 4511 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4512 | if (dev_target->module == lys_main_module(module)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4513 | LOGVAL(module->ctx, LYE_INARG, LY_VLOG_NONE, NULL, dev->target_name, "deviation"); |
| 4514 | LOGVAL(module->ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "Deviating own module is not allowed."); |
Michal Vasko | 9b7a33b | 2018-05-14 15:23:10 +0200 | [diff] [blame] | 4515 | i = 0; |
| 4516 | goto free_type_error; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4517 | } |
| 4518 | |
| 4519 | if (!dflt_check) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4520 | LOGMEM(module->ctx); |
Michal Vasko | 9b7a33b | 2018-05-14 15:23:10 +0200 | [diff] [blame] | 4521 | i = 0; |
| 4522 | goto free_type_error; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4523 | } |
| 4524 | |
| 4525 | if (dev->deviate[0].mod == LY_DEVIATE_NO) { |
| 4526 | /* you cannot remove a key leaf */ |
| 4527 | if ((dev_target->nodetype == LYS_LEAF) && dev_target->parent && (dev_target->parent->nodetype == LYS_LIST)) { |
| 4528 | for (i = 0; i < ((struct lys_node_list *)dev_target->parent)->keys_size; ++i) { |
| 4529 | if (((struct lys_node_list *)dev_target->parent)->keys[i] == (struct lys_node_leaf *)dev_target) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4530 | LOGVAL(module->ctx, LYE_INARG, LY_VLOG_NONE, NULL, "not-supported", "deviation"); |
| 4531 | LOGVAL(module->ctx, LYE_SPEC, LY_VLOG_NONE, NULL, "\"not-supported\" deviation cannot remove a list key."); |
Michal Vasko | 9b7a33b | 2018-05-14 15:23:10 +0200 | [diff] [blame] | 4532 | i = 0; |
| 4533 | goto free_type_error; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4534 | } |
| 4535 | } |
| 4536 | } |
| 4537 | /* unlink and store the original node */ |
Radek Krejci | 9cf034c | 2017-08-24 17:10:35 +0200 | [diff] [blame] | 4538 | parent = dev_target->parent; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4539 | lys_node_unlink(dev_target); |
Michal Vasko | a1074a5 | 2018-01-03 12:18:53 +0100 | [diff] [blame] | 4540 | if (parent && (parent->nodetype & (LYS_AUGMENT | LYS_USES))) { |
Radek Krejci | 9cf034c | 2017-08-24 17:10:35 +0200 | [diff] [blame] | 4541 | /* hack for augment, because when the original will be sometime reconnected back, we actually need |
| 4542 | * to reconnect it to both - the augment and its target (which is deduced from the deviations target |
| 4543 | * path), so we need to remember the augment as an addition */ |
Michal Vasko | a1074a5 | 2018-01-03 12:18:53 +0100 | [diff] [blame] | 4544 | /* remember uses parent so we can reconnect to it */ |
Radek Krejci | 9cf034c | 2017-08-24 17:10:35 +0200 | [diff] [blame] | 4545 | dev_target->parent = parent; |
| 4546 | } |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4547 | dev->orig_node = dev_target; |
| 4548 | } else { |
| 4549 | /* store a shallow copy of the original node */ |
| 4550 | memset(&tmp_unres, 0, sizeof tmp_unres); |
PavolVican | 8c33b15 | 2017-01-27 12:45:34 +0100 | [diff] [blame] | 4551 | dev->orig_node = lys_node_dup(dev_target->module, NULL, dev_target, &tmp_unres, 1); |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4552 | /* just to be safe */ |
| 4553 | if (tmp_unres.count) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4554 | LOGINT(module->ctx); |
Michal Vasko | 9b7a33b | 2018-05-14 15:23:10 +0200 | [diff] [blame] | 4555 | i = 0; |
| 4556 | goto free_type_error; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4557 | } |
| 4558 | } |
| 4559 | |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 4560 | if (yang_check_ext_instance(module, &dev->ext, dev->ext_size, dev, unres)) { |
Michal Vasko | 9b7a33b | 2018-05-14 15:23:10 +0200 | [diff] [blame] | 4561 | i = 0; |
| 4562 | goto free_type_error; |
PavolVican | 6f00092 | 2017-02-10 12:56:59 +0100 | [diff] [blame] | 4563 | } |
| 4564 | |
Michal Vasko | 9b7a33b | 2018-05-14 15:23:10 +0200 | [diff] [blame] | 4565 | for (i = 0; i < dev->deviate_size; ++i) { |
| 4566 | if (yang_check_deviate(module, unres, &dev->deviate[i], dev_target, dflt_check)) { |
| 4567 | yang_free_deviate(module->ctx, dev, i + 1); |
| 4568 | dev->deviate_size = i + 1; |
| 4569 | goto free_type_error; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4570 | } |
Michal Vasko | 9b7a33b | 2018-05-14 15:23:10 +0200 | [diff] [blame] | 4571 | } |
| 4572 | /* now check whether default value, if any, matches the type */ |
| 4573 | for (u = 0; u < dflt_check->number; ++u) { |
| 4574 | value = NULL; |
| 4575 | rc = EXIT_SUCCESS; |
| 4576 | if (dflt_check->set.s[u]->nodetype == LYS_LEAF) { |
| 4577 | leaf = (struct lys_node_leaf *)dflt_check->set.s[u]; |
| 4578 | target_name = leaf->name; |
| 4579 | value = leaf->dflt; |
| 4580 | rc = unres_schema_add_node(module, unres, &leaf->type, UNRES_TYPE_DFLT, (struct lys_node *)(&leaf->dflt)); |
| 4581 | } else { /* LYS_LEAFLIST */ |
| 4582 | llist = (struct lys_node_leaflist *)dflt_check->set.s[u]; |
| 4583 | target_name = llist->name; |
| 4584 | for (i = 0; i < llist->dflt_size; i++) { |
| 4585 | rc = unres_schema_add_node(module, unres, &llist->type, UNRES_TYPE_DFLT, |
| 4586 | (struct lys_node *)(&llist->dflt[i])); |
| 4587 | if (rc == -1) { |
| 4588 | value = llist->dflt[i]; |
| 4589 | break; |
Michal Vasko | 15a4337 | 2017-09-25 14:12:42 +0200 | [diff] [blame] | 4590 | } |
| 4591 | } |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4592 | } |
Michal Vasko | 9b7a33b | 2018-05-14 15:23:10 +0200 | [diff] [blame] | 4593 | if (rc == -1) { |
| 4594 | LOGVAL(module->ctx, LYE_INARG, LY_VLOG_NONE, NULL, value, "default"); |
| 4595 | LOGVAL(module->ctx, LYE_SPEC, LY_VLOG_NONE, NULL, |
| 4596 | "The default value \"%s\" of the deviated node \"%s\"no longer matches its type.", |
| 4597 | target_name); |
| 4598 | goto error; |
| 4599 | } |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4600 | } |
Michal Vasko | 9b7a33b | 2018-05-14 15:23:10 +0200 | [diff] [blame] | 4601 | ly_set_free(dflt_check); |
| 4602 | dflt_check = NULL; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4603 | |
Radek Krejci | 29eac3d | 2017-06-01 16:50:02 +0200 | [diff] [blame] | 4604 | /* mark all the affected modules as deviated and implemented */ |
| 4605 | for (parent = dev_target; parent; parent = lys_parent(parent)) { |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4606 | mod = lys_node_module(parent); |
| 4607 | if (module != mod) { |
Radek Krejci | 29eac3d | 2017-06-01 16:50:02 +0200 | [diff] [blame] | 4608 | mod->deviated = 1; /* main module */ |
| 4609 | parent->module->deviated = 1; /* possible submodule */ |
Michal Vasko | 0f43706 | 2018-06-08 15:52:39 +0200 | [diff] [blame] | 4610 | if (!mod->implemented) { |
| 4611 | mod->implemented = 1; |
| 4612 | if (unres_schema_add_node(mod, unres, NULL, UNRES_MOD_IMPLEMENT, NULL) == -1) { |
| 4613 | goto error; |
| 4614 | } |
Radek Krejci | 29eac3d | 2017-06-01 16:50:02 +0200 | [diff] [blame] | 4615 | } |
| 4616 | } |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4617 | } |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4618 | |
| 4619 | return EXIT_SUCCESS; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4620 | |
Michal Vasko | 9b7a33b | 2018-05-14 15:23:10 +0200 | [diff] [blame] | 4621 | free_type_error: |
| 4622 | /* we need to free types because they are for now allocated dynamically (use i as it is now, is set correctly) */ |
| 4623 | for (; i < dev->deviate_size; ++i) { |
| 4624 | if (dev->deviate[i].type) { |
| 4625 | yang_type_free(module->ctx, dev->deviate[i].type); |
| 4626 | free(dev->deviate[i].type); |
| 4627 | dev->deviate[i].type = NULL; |
| 4628 | } |
| 4629 | } |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4630 | error: |
| 4631 | ly_set_free(dflt_check); |
| 4632 | return EXIT_FAILURE; |
| 4633 | } |
| 4634 | |
| 4635 | static int |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 4636 | yang_check_sub_module(struct lys_module *module, struct unres_schema *unres, struct lys_node *node) |
| 4637 | { |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4638 | uint i, erase_identities = 1, erase_nodes = 1, aug_size, dev_size = 0; |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 4639 | |
| 4640 | aug_size = module->augment_size; |
| 4641 | module->augment_size = 0; |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4642 | dev_size = module->deviation_size; |
| 4643 | module->deviation_size = 0; |
Pavol Vican | 7a7916f | 2016-11-21 23:38:30 +0100 | [diff] [blame] | 4644 | |
PavolVican | 6f87bf9 | 2017-02-15 19:38:55 +0100 | [diff] [blame] | 4645 | if (yang_check_typedef(module, NULL, unres)) { |
| 4646 | goto error; |
| 4647 | } |
| 4648 | |
PavolVican | c180726 | 2017-01-31 18:00:27 +0100 | [diff] [blame] | 4649 | if (yang_check_ext_instance(module, &module->ext, module->ext_size, module, unres)) { |
| 4650 | goto error; |
| 4651 | } |
| 4652 | |
PavolVican | 171717d | 2017-02-01 14:49:55 +0100 | [diff] [blame] | 4653 | /* check extension in revision */ |
| 4654 | for (i = 0; i < module->rev_size; ++i) { |
| 4655 | if (yang_check_ext_instance(module, &module->rev[i].ext, module->rev[i].ext_size, &module->rev[i], unres)) { |
| 4656 | goto error; |
| 4657 | } |
| 4658 | } |
| 4659 | |
PavolVican | 19dc615 | 2017-02-06 12:04:15 +0100 | [diff] [blame] | 4660 | /* check extension in definition of extension */ |
PavolVican | 5393d3f | 2017-02-06 23:30:55 +0100 | [diff] [blame] | 4661 | for (i = 0; i < module->extensions_size; ++i) { |
PavolVican | 19dc615 | 2017-02-06 12:04:15 +0100 | [diff] [blame] | 4662 | if (yang_check_ext_instance(module, &module->extensions[i].ext, module->extensions[i].ext_size, &module->extensions[i], unres)) { |
| 4663 | goto error; |
| 4664 | } |
| 4665 | } |
| 4666 | |
Pavol Vican | 7a7916f | 2016-11-21 23:38:30 +0100 | [diff] [blame] | 4667 | /* check features */ |
| 4668 | for (i = 0; i < module->features_size; ++i) { |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 4669 | if (yang_check_iffeatures(module, NULL, &module->features[i], FEATURE_KEYWORD, unres)) { |
| 4670 | goto error; |
| 4671 | } |
PavolVican | 5393d3f | 2017-02-06 23:30:55 +0100 | [diff] [blame] | 4672 | if (yang_check_ext_instance(module, &module->features[i].ext, module->features[i].ext_size, &module->features[i], unres)) { |
| 4673 | goto error; |
| 4674 | } |
| 4675 | |
Pavol Vican | df9a95c | 2016-12-02 23:34:51 +0100 | [diff] [blame] | 4676 | /* check for circular dependencies */ |
| 4677 | if (module->features[i].iffeature_size && (unres_schema_add_node(module, unres, &module->features[i], UNRES_FEATURE, NULL) == -1)) { |
| 4678 | goto error; |
Pavol Vican | 7a7916f | 2016-11-21 23:38:30 +0100 | [diff] [blame] | 4679 | } |
| 4680 | } |
Pavol Vican | 36e2727 | 2016-11-22 15:47:28 +0100 | [diff] [blame] | 4681 | erase_identities = 0; |
| 4682 | if (yang_check_identities(module, unres)) { |
| 4683 | goto error; |
| 4684 | } |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 4685 | erase_nodes = 0; |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4686 | if (yang_check_nodes(module, NULL, node, 0, unres)) { |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 4687 | goto error; |
| 4688 | } |
Pavol Vican | 7a7916f | 2016-11-21 23:38:30 +0100 | [diff] [blame] | 4689 | |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4690 | /* check deviation */ |
| 4691 | for (i = 0; i < dev_size; ++i) { |
| 4692 | module->deviation_size++; |
| 4693 | if (yang_check_deviation(module, unres, &module->deviation[i])) { |
| 4694 | goto error; |
| 4695 | } |
| 4696 | } |
| 4697 | |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 4698 | /* check augments */ |
| 4699 | for (i = 0; i < aug_size; ++i) { |
| 4700 | module->augment_size++; |
Radek Krejci | 7212e0a | 2017-03-08 15:58:22 +0100 | [diff] [blame] | 4701 | if (yang_check_augment(module, &module->augment[i], 0, unres)) { |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 4702 | goto error; |
| 4703 | } |
| 4704 | if (unres_schema_add_node(module, unres, &module->augment[i], UNRES_AUGMENT, NULL) == -1) { |
| 4705 | goto error; |
| 4706 | } |
| 4707 | } |
| 4708 | |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 4709 | return EXIT_SUCCESS; |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4710 | |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 4711 | error: |
Pavol Vican | 36e2727 | 2016-11-22 15:47:28 +0100 | [diff] [blame] | 4712 | if (erase_identities) { |
| 4713 | yang_free_ident_base(module->ident, 0, module->ident_size); |
| 4714 | } |
Pavol Vican | 05810b6 | 2016-11-23 14:07:22 +0100 | [diff] [blame] | 4715 | if (erase_nodes) { |
| 4716 | yang_free_nodes(module->ctx, node); |
| 4717 | } |
Pavol Vican | 3ad50f8 | 2016-12-04 15:00:36 +0100 | [diff] [blame] | 4718 | for (i = module->augment_size; i < aug_size; ++i) { |
| 4719 | yang_free_augment(module->ctx, &module->augment[i]); |
| 4720 | } |
PavolVican | 75af21d | 2016-12-29 20:04:07 +0100 | [diff] [blame] | 4721 | for (i = module->deviation_size; i < dev_size; ++i) { |
| 4722 | yang_free_deviate(module->ctx, &module->deviation[i], 0); |
| 4723 | free(module->deviation[i].deviate); |
| 4724 | } |
Pavol Vican | 7313fc0 | 2016-11-14 01:10:31 +0100 | [diff] [blame] | 4725 | return EXIT_FAILURE; |
| 4726 | } |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 4727 | |
| 4728 | int |
Michal Vasko | 3e3228d | 2017-02-24 14:55:32 +0100 | [diff] [blame] | 4729 | yang_read_extcomplex_str(struct lys_module *module, struct lys_ext_instance_complex *ext, const char *arg_name, |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 4730 | const char *parent_name, char *value, int parent_stmt, LY_STMT stmt) |
| 4731 | { |
| 4732 | int c; |
| 4733 | const char **str, ***p = NULL; |
| 4734 | void *reallocated; |
| 4735 | struct lyext_substmt *info; |
| 4736 | |
| 4737 | c = 0; |
| 4738 | if (stmt == LY_STMT_PREFIX && parent_stmt == LY_STMT_BELONGSTO) { |
PavolVican | 4b80d04 | 2017-02-23 14:30:27 +0100 | [diff] [blame] | 4739 | /* str contains no NULL value */ |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 4740 | str = lys_ext_complex_get_substmt(LY_STMT_BELONGSTO, ext, &info); |
| 4741 | if (info->cardinality < LY_STMT_CARD_SOME) { |
| 4742 | str++; |
| 4743 | } else { |
| 4744 | /* get the index in the array to add new item */ |
| 4745 | p = (const char ***)str; |
| 4746 | for (c = 0; p[0][c + 1]; c++); |
| 4747 | str = p[1]; |
| 4748 | } |
| 4749 | str[c] = lydict_insert_zc(module->ctx, value); |
| 4750 | } else { |
| 4751 | str = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 4752 | if (!str) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4753 | LOGVAL(module->ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, arg_name, parent_name); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4754 | goto error; |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 4755 | } |
| 4756 | if (info->cardinality < LY_STMT_CARD_SOME && *str) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4757 | LOGVAL(module->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, arg_name, parent_name); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4758 | goto error; |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 4759 | } |
| 4760 | |
| 4761 | if (info->cardinality >= LY_STMT_CARD_SOME) { |
| 4762 | /* there can be multiple instances, str is actually const char *** */ |
| 4763 | p = (const char ***)str; |
| 4764 | if (!p[0]) { |
| 4765 | /* allocate initial array */ |
PavolVican | 5080974 | 2017-02-18 21:22:54 +0100 | [diff] [blame] | 4766 | p[0] = calloc(2, sizeof(const char *)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4767 | LY_CHECK_ERR_GOTO(!p[0], LOGMEM(module->ctx), error); |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 4768 | if (stmt == LY_STMT_BELONGSTO) { |
| 4769 | /* allocate another array for the belongs-to's prefixes */ |
| 4770 | p[1] = calloc(2, sizeof(const char *)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4771 | LY_CHECK_ERR_GOTO(!p[1], LOGMEM(module->ctx), error); |
PavolVican | 5080974 | 2017-02-18 21:22:54 +0100 | [diff] [blame] | 4772 | } else if (stmt == LY_STMT_ARGUMENT) { |
| 4773 | /* allocate another array for the yin element */ |
PavolVican | 4b80d04 | 2017-02-23 14:30:27 +0100 | [diff] [blame] | 4774 | ((uint8_t **)p)[1] = calloc(2, sizeof(uint8_t)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4775 | LY_CHECK_ERR_GOTO(!p[1], LOGMEM(module->ctx), error); |
PavolVican | 5080974 | 2017-02-18 21:22:54 +0100 | [diff] [blame] | 4776 | /* default value of yin element */ |
| 4777 | ((uint8_t *)p[1])[0] = 2; |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 4778 | } |
| 4779 | } else { |
| 4780 | /* get the index in the array to add new item */ |
| 4781 | for (c = 0; p[0][c]; c++); |
| 4782 | } |
| 4783 | str = p[0]; |
| 4784 | } |
| 4785 | |
| 4786 | str[c] = lydict_insert_zc(module->ctx, value); |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4787 | value = NULL; |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 4788 | |
PavolVican | 5080974 | 2017-02-18 21:22:54 +0100 | [diff] [blame] | 4789 | if (c) { |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 4790 | /* enlarge the array(s) */ |
| 4791 | reallocated = realloc(p[0], (c + 2) * sizeof(const char *)); |
| 4792 | if (!reallocated) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4793 | LOGMEM(module->ctx); |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 4794 | lydict_remove(module->ctx, p[0][c]); |
| 4795 | p[0][c] = NULL; |
| 4796 | return EXIT_FAILURE; |
| 4797 | } |
| 4798 | p[0] = reallocated; |
| 4799 | p[0][c + 1] = NULL; |
| 4800 | |
| 4801 | if (stmt == LY_STMT_BELONGSTO) { |
| 4802 | /* enlarge the second belongs-to's array with prefixes */ |
| 4803 | reallocated = realloc(p[1], (c + 2) * sizeof(const char *)); |
| 4804 | if (!reallocated) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4805 | LOGMEM(module->ctx); |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 4806 | lydict_remove(module->ctx, p[1][c]); |
| 4807 | p[1][c] = NULL; |
| 4808 | return EXIT_FAILURE; |
| 4809 | } |
| 4810 | p[1] = reallocated; |
| 4811 | p[1][c + 1] = NULL; |
PavolVican | 5080974 | 2017-02-18 21:22:54 +0100 | [diff] [blame] | 4812 | } else if (stmt == LY_STMT_ARGUMENT) { |
| 4813 | /* enlarge the second argument's array with yin element */ |
| 4814 | reallocated = realloc(p[1], (c + 2) * sizeof(uint8_t)); |
| 4815 | if (!reallocated) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4816 | LOGMEM(module->ctx); |
PavolVican | 5080974 | 2017-02-18 21:22:54 +0100 | [diff] [blame] | 4817 | ((uint8_t *)p[1])[c] = 0; |
| 4818 | return EXIT_FAILURE; |
| 4819 | } |
| 4820 | p[1] = reallocated; |
| 4821 | ((uint8_t *)p[1])[c + 1] = 0; |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 4822 | } |
| 4823 | } |
| 4824 | } |
| 4825 | |
| 4826 | return EXIT_SUCCESS; |
Radek Krejci | a8d111f | 2017-05-31 13:57:37 +0200 | [diff] [blame] | 4827 | |
| 4828 | error: |
| 4829 | free(value); |
| 4830 | return EXIT_FAILURE; |
PavolVican | 22e8868 | 2017-02-14 22:38:18 +0100 | [diff] [blame] | 4831 | } |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 4832 | |
| 4833 | static int |
| 4834 | yang_fill_ext_substm_index(struct lys_ext_instance_complex *ext, LY_STMT stmt, enum yytokentype keyword) |
| 4835 | { |
| 4836 | int c = 0, decrement = 0; |
| 4837 | const char **str, ***p = NULL; |
| 4838 | struct lyext_substmt *info; |
| 4839 | |
| 4840 | |
| 4841 | if (keyword == BELONGS_TO_KEYWORD || stmt == LY_STMT_BELONGSTO) { |
| 4842 | stmt = LY_STMT_BELONGSTO; |
| 4843 | decrement = -1; |
PavolVican | 5080974 | 2017-02-18 21:22:54 +0100 | [diff] [blame] | 4844 | } else if (keyword == ARGUMENT_KEYWORD || stmt == LY_STMT_ARGUMENT) { |
| 4845 | stmt = LY_STMT_ARGUMENT; |
| 4846 | decrement = -1; |
PavolVican | 5334c89 | 2017-02-15 16:29:09 +0100 | [diff] [blame] | 4847 | } |
| 4848 | |
| 4849 | str = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 4850 | if (!str || info->cardinality < LY_STMT_CARD_SOME || !((const char ***)str)[0]) { |
| 4851 | return 0; |
| 4852 | } else { |
| 4853 | p = (const char ***)str; |
| 4854 | /* get the index in the array */ |
| 4855 | for (c = 0; p[0][c]; c++); |
| 4856 | return c + decrement; |
| 4857 | } |
| 4858 | } |
PavolVican | a0fdbf3 | 2017-02-15 17:59:02 +0100 | [diff] [blame] | 4859 | |
| 4860 | void ** |
PavolVican | fe83b15 | 2017-02-19 03:19:29 +0100 | [diff] [blame] | 4861 | yang_getplace_for_extcomplex_struct(struct lys_ext_instance_complex *ext, int *index, |
| 4862 | char *parent_name, char *node_name, LY_STMT stmt) |
PavolVican | a0fdbf3 | 2017-02-15 17:59:02 +0100 | [diff] [blame] | 4863 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4864 | struct ly_ctx *ctx = ext->module->ctx; |
PavolVican | a0fdbf3 | 2017-02-15 17:59:02 +0100 | [diff] [blame] | 4865 | int c; |
| 4866 | void **data, ***p = NULL; |
| 4867 | void *reallocated; |
| 4868 | struct lyext_substmt *info; |
| 4869 | |
| 4870 | data = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 4871 | if (!data) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4872 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node_name, parent_name); |
PavolVican | a0fdbf3 | 2017-02-15 17:59:02 +0100 | [diff] [blame] | 4873 | return NULL; |
| 4874 | } |
| 4875 | if (info->cardinality < LY_STMT_CARD_SOME && *data) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4876 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node_name, parent_name); |
PavolVican | a0fdbf3 | 2017-02-15 17:59:02 +0100 | [diff] [blame] | 4877 | return NULL; |
| 4878 | } |
| 4879 | |
| 4880 | c = 0; |
| 4881 | if (info->cardinality >= LY_STMT_CARD_SOME) { |
| 4882 | /* there can be multiple instances, so instead of pointer to array, |
| 4883 | * we have in data pointer to pointer to array */ |
| 4884 | p = (void ***)data; |
| 4885 | data = *p; |
| 4886 | if (!data) { |
| 4887 | /* allocate initial array */ |
PavolVican | eef1d91 | 2017-02-19 00:19:15 +0100 | [diff] [blame] | 4888 | *p = data = calloc(2, sizeof(void *)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4889 | LY_CHECK_ERR_RETURN(!data, LOGMEM(ctx), NULL); |
PavolVican | a0fdbf3 | 2017-02-15 17:59:02 +0100 | [diff] [blame] | 4890 | } else { |
| 4891 | for (c = 0; *data; data++, c++); |
| 4892 | } |
| 4893 | } |
| 4894 | |
PavolVican | eef1d91 | 2017-02-19 00:19:15 +0100 | [diff] [blame] | 4895 | if (c) { |
PavolVican | a0fdbf3 | 2017-02-15 17:59:02 +0100 | [diff] [blame] | 4896 | /* enlarge the array */ |
| 4897 | reallocated = realloc(*p, (c + 2) * sizeof(void *)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4898 | LY_CHECK_ERR_RETURN(!reallocated, LOGMEM(ctx), NULL); |
PavolVican | a0fdbf3 | 2017-02-15 17:59:02 +0100 | [diff] [blame] | 4899 | *p = reallocated; |
| 4900 | data = *p; |
| 4901 | data[c + 1] = NULL; |
| 4902 | } |
| 4903 | |
PavolVican | fe83b15 | 2017-02-19 03:19:29 +0100 | [diff] [blame] | 4904 | if (index) { |
| 4905 | *index = c; |
| 4906 | return data; |
| 4907 | } else { |
| 4908 | return &data[c]; |
| 4909 | } |
PavolVican | a0fdbf3 | 2017-02-15 17:59:02 +0100 | [diff] [blame] | 4910 | } |
PavolVican | ff0f7f4 | 2017-02-16 11:35:42 +0100 | [diff] [blame] | 4911 | |
| 4912 | int |
| 4913 | yang_fill_extcomplex_flags(struct lys_ext_instance_complex *ext, char *parent_name, char *node_name, |
| 4914 | LY_STMT stmt, uint16_t value, uint16_t mask) |
| 4915 | { |
| 4916 | uint16_t *data; |
| 4917 | struct lyext_substmt *info; |
| 4918 | |
| 4919 | data = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 4920 | if (!data) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4921 | LOGVAL(ext->module->ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node_name, parent_name); |
PavolVican | ff0f7f4 | 2017-02-16 11:35:42 +0100 | [diff] [blame] | 4922 | return EXIT_FAILURE; |
| 4923 | } |
| 4924 | if (info->cardinality < LY_STMT_CARD_SOME && (*data & mask)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4925 | LOGVAL(ext->module->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node_name, parent_name); |
PavolVican | ff0f7f4 | 2017-02-16 11:35:42 +0100 | [diff] [blame] | 4926 | return EXIT_FAILURE; |
| 4927 | } |
| 4928 | |
| 4929 | *data |= value; |
| 4930 | return EXIT_SUCCESS; |
| 4931 | } |
PavolVican | 8e8dfd1 | 2017-02-16 13:51:41 +0100 | [diff] [blame] | 4932 | |
| 4933 | int |
PavolVican | 6a852a6 | 2017-02-16 15:36:01 +0100 | [diff] [blame] | 4934 | yang_fill_extcomplex_uint8(struct lys_ext_instance_complex *ext, char *parent_name, char *node_name, |
| 4935 | LY_STMT stmt, uint8_t value) |
PavolVican | 8e8dfd1 | 2017-02-16 13:51:41 +0100 | [diff] [blame] | 4936 | { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4937 | struct ly_ctx *ctx = ext->module->ctx; |
PavolVican | 6a852a6 | 2017-02-16 15:36:01 +0100 | [diff] [blame] | 4938 | uint8_t *val, **pp = NULL, *reallocated; |
PavolVican | 8e8dfd1 | 2017-02-16 13:51:41 +0100 | [diff] [blame] | 4939 | struct lyext_substmt *info; |
PavolVican | 6a852a6 | 2017-02-16 15:36:01 +0100 | [diff] [blame] | 4940 | int i = 0; |
PavolVican | 8e8dfd1 | 2017-02-16 13:51:41 +0100 | [diff] [blame] | 4941 | |
| 4942 | val = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 4943 | if (!val) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4944 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node_name, parent_name); |
PavolVican | 8e8dfd1 | 2017-02-16 13:51:41 +0100 | [diff] [blame] | 4945 | return EXIT_FAILURE; |
| 4946 | } |
PavolVican | 6a852a6 | 2017-02-16 15:36:01 +0100 | [diff] [blame] | 4947 | if (stmt == LY_STMT_DIGITS) { |
| 4948 | if (info->cardinality < LY_STMT_CARD_SOME && *val) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4949 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node_name, parent_name); |
PavolVican | 6a852a6 | 2017-02-16 15:36:01 +0100 | [diff] [blame] | 4950 | return EXIT_FAILURE; |
| 4951 | } |
PavolVican | 8e8dfd1 | 2017-02-16 13:51:41 +0100 | [diff] [blame] | 4952 | |
PavolVican | 6a852a6 | 2017-02-16 15:36:01 +0100 | [diff] [blame] | 4953 | if (info->cardinality >= LY_STMT_CARD_SOME) { |
| 4954 | /* there can be multiple instances */ |
| 4955 | pp = (uint8_t**)val; |
| 4956 | if (!(*pp)) { |
| 4957 | *pp = calloc(2, sizeof(uint8_t)); /* allocate initial array */ |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4958 | LY_CHECK_ERR_RETURN(!*pp, LOGMEM(ctx), EXIT_FAILURE); |
PavolVican | 6a852a6 | 2017-02-16 15:36:01 +0100 | [diff] [blame] | 4959 | } else { |
| 4960 | for (i = 0; (*pp)[i]; i++); |
| 4961 | } |
| 4962 | val = &(*pp)[i]; |
| 4963 | } |
| 4964 | |
| 4965 | /* stored value */ |
| 4966 | *val = value; |
| 4967 | |
| 4968 | if (i) { |
| 4969 | /* enlarge the array */ |
| 4970 | reallocated = realloc(*pp, (i + 2) * sizeof *val); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4971 | LY_CHECK_ERR_RETURN(!reallocated, LOGMEM(ctx), EXIT_FAILURE); |
PavolVican | 6a852a6 | 2017-02-16 15:36:01 +0100 | [diff] [blame] | 4972 | *pp = reallocated; |
| 4973 | (*pp)[i + 1] = 0; |
| 4974 | } |
PavolVican | 8e8dfd1 | 2017-02-16 13:51:41 +0100 | [diff] [blame] | 4975 | } else { |
PavolVican | 6a852a6 | 2017-02-16 15:36:01 +0100 | [diff] [blame] | 4976 | if (*val) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4977 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node_name, parent_name); |
PavolVican | 6a852a6 | 2017-02-16 15:36:01 +0100 | [diff] [blame] | 4978 | return EXIT_FAILURE; |
| 4979 | } |
| 4980 | |
| 4981 | if (stmt == LY_STMT_REQINSTANCE) { |
| 4982 | *val = (value == 1) ? 1 : 2; |
| 4983 | } else if (stmt == LY_STMT_MODIFIER) { |
| 4984 | *val = 1; |
| 4985 | } else { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 4986 | LOGINT(ctx); |
PavolVican | 6a852a6 | 2017-02-16 15:36:01 +0100 | [diff] [blame] | 4987 | return EXIT_FAILURE; |
| 4988 | } |
PavolVican | 8e8dfd1 | 2017-02-16 13:51:41 +0100 | [diff] [blame] | 4989 | } |
| 4990 | |
| 4991 | return EXIT_SUCCESS; |
| 4992 | } |
PavolVican | 3f47b29 | 2017-02-16 20:38:16 +0100 | [diff] [blame] | 4993 | |
PavolVican | f3091bf | 2017-02-19 18:27:01 +0100 | [diff] [blame] | 4994 | int |
| 4995 | yang_extcomplex_node(struct lys_ext_instance_complex *ext, char *parent_name, char *node_name, |
| 4996 | struct lys_node *node, LY_STMT stmt) |
| 4997 | { |
| 4998 | struct lyext_substmt *info; |
| 4999 | struct lys_node **snode, *siter; |
| 5000 | |
| 5001 | snode = lys_ext_complex_get_substmt(stmt, ext, &info); |
| 5002 | if (!snode) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5003 | LOGVAL(ext->module->ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, node_name, parent_name); |
PavolVican | f3091bf | 2017-02-19 18:27:01 +0100 | [diff] [blame] | 5004 | return EXIT_FAILURE; |
| 5005 | } |
| 5006 | if (info->cardinality < LY_STMT_CARD_SOME) { |
| 5007 | LY_TREE_FOR(node, siter) { |
| 5008 | if (stmt == lys_snode2stmt(siter->nodetype)) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5009 | LOGVAL(ext->module->ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, node_name, parent_name); |
PavolVican | f3091bf | 2017-02-19 18:27:01 +0100 | [diff] [blame] | 5010 | return EXIT_FAILURE; |
| 5011 | } |
| 5012 | } |
| 5013 | } |
| 5014 | |
| 5015 | return EXIT_SUCCESS; |
| 5016 | } |
PavolVican | db0e817 | 2017-02-20 00:46:09 +0100 | [diff] [blame] | 5017 | |
| 5018 | int |
| 5019 | yang_fill_extcomplex_module(struct ly_ctx *ctx, struct lys_ext_instance_complex *ext, |
| 5020 | char *parent_name, char **values, int implemented) |
| 5021 | { |
| 5022 | int c, i; |
| 5023 | struct lys_module **modules, ***p, *reallocated, **pp; |
| 5024 | struct lyext_substmt *info; |
| 5025 | |
| 5026 | if (!values) { |
| 5027 | return EXIT_SUCCESS; |
| 5028 | } |
| 5029 | pp = modules = lys_ext_complex_get_substmt(LY_STMT_MODULE, ext, &info); |
| 5030 | if (!modules) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5031 | LOGVAL(ctx, LYE_INCHILDSTMT, LY_VLOG_NONE, NULL, "module", parent_name); |
PavolVican | db0e817 | 2017-02-20 00:46:09 +0100 | [diff] [blame] | 5032 | return EXIT_FAILURE; |
| 5033 | } |
| 5034 | |
| 5035 | for (i = 0; values[i]; ++i) { |
| 5036 | c = 0; |
| 5037 | if (info->cardinality < LY_STMT_CARD_SOME && *modules) { |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5038 | LOGVAL(ctx, LYE_TOOMANY, LY_VLOG_NONE, NULL, "module", parent_name); |
PavolVican | db0e817 | 2017-02-20 00:46:09 +0100 | [diff] [blame] | 5039 | return EXIT_FAILURE; |
| 5040 | } |
| 5041 | if (info->cardinality >= LY_STMT_CARD_SOME) { |
| 5042 | /* there can be multiple instances, so instead of pointer to array, |
| 5043 | * we have in modules pointer to pointer to array */ |
| 5044 | p = (struct lys_module ***)pp; |
| 5045 | modules = *p; |
| 5046 | if (!modules) { |
| 5047 | /* allocate initial array */ |
| 5048 | *p = modules = calloc(2, sizeof(struct lys_module *)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5049 | LY_CHECK_ERR_RETURN(!*p, LOGMEM(ctx), EXIT_FAILURE); |
PavolVican | db0e817 | 2017-02-20 00:46:09 +0100 | [diff] [blame] | 5050 | } else { |
| 5051 | for (c = 0; *modules; modules++, c++); |
| 5052 | } |
| 5053 | } |
| 5054 | |
| 5055 | if (c) { |
| 5056 | /* enlarge the array */ |
| 5057 | reallocated = realloc(*p, (c + 2) * sizeof(struct lys_module *)); |
Michal Vasko | 53b7da0 | 2018-02-13 15:28:42 +0100 | [diff] [blame] | 5058 | LY_CHECK_ERR_RETURN(!reallocated, LOGMEM(ctx), EXIT_FAILURE); |
PavolVican | db0e817 | 2017-02-20 00:46:09 +0100 | [diff] [blame] | 5059 | *p = (struct lys_module **)reallocated; |
| 5060 | modules = *p; |
| 5061 | modules[c + 1] = NULL; |
| 5062 | } |
| 5063 | |
| 5064 | modules[c] = yang_read_module(ctx, values[i], 0, NULL, implemented); |
| 5065 | if (!modules[c]) { |
| 5066 | return EXIT_FAILURE; |
| 5067 | } |
| 5068 | } |
| 5069 | |
| 5070 | return EXIT_SUCCESS; |
| 5071 | } |