Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 2 | * @file tree_schema_free.c |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 4 | * @brief Freeing functions for schema tree structures. |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 5 | * |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 6 | * Copyright (c) 2019 CESNET, z.s.p.o. |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 7 | * |
| 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 |
| 13 | */ |
| 14 | |
Michal Vasko | ee75760 | 2021-06-10 14:38:19 +0200 | [diff] [blame] | 15 | #include <assert.h> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 16 | #include <stdlib.h> |
| 17 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 18 | #include "common.h" |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 19 | #include "compat.h" |
Radek Krejci | 7711410 | 2021-03-10 15:21:57 +0100 | [diff] [blame] | 20 | #include "dict.h" |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 21 | #include "log.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 22 | #include "plugins_exts.h" |
| 23 | #include "plugins_types.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 24 | #include "tree.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 25 | #include "tree_data.h" |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 26 | #include "tree_data_internal.h" |
Radek Krejci | 859a15a | 2021-03-05 20:56:59 +0100 | [diff] [blame] | 27 | #include "tree_edit.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 28 | #include "tree_schema.h" |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 29 | #include "tree_schema_internal.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 30 | #include "xml.h" |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 31 | #include "xpath.h" |
| 32 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 33 | void lysp_grp_free(struct ly_ctx *ctx, struct lysp_node_grp *grp); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 34 | static void lysc_node_free_(struct ly_ctx *ctx, struct lysc_node *node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 35 | |
| 36 | static void |
| 37 | lysp_stmt_free(struct ly_ctx *ctx, struct lysp_stmt *stmt) |
| 38 | { |
| 39 | struct lysp_stmt *child, *next; |
| 40 | |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 41 | lydict_remove(ctx, stmt->stmt); |
| 42 | lydict_remove(ctx, stmt->arg); |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 43 | ly_free_prefix_data(stmt->format, stmt->prefix_data); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 44 | |
| 45 | LY_LIST_FOR_SAFE(stmt->child, next, child) { |
| 46 | lysp_stmt_free(ctx, child); |
| 47 | } |
| 48 | |
| 49 | free(stmt); |
| 50 | } |
| 51 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 52 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 53 | lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext) |
| 54 | { |
| 55 | struct lysp_stmt *stmt, *next; |
aPiecek | 60d9d67 | 2021-04-27 15:49:57 +0200 | [diff] [blame] | 56 | struct lysp_node *node, *next_node; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 57 | |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 58 | lydict_remove(ctx, ext->name); |
| 59 | lydict_remove(ctx, ext->argument); |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 60 | ly_free_prefix_data(ext->format, ext->prefix_data); |
aPiecek | 60d9d67 | 2021-04-27 15:49:57 +0200 | [diff] [blame] | 61 | LY_LIST_FOR_SAFE(ext->parsed, next_node, node) { |
| 62 | lysp_node_free(ctx, node); |
| 63 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 64 | |
| 65 | LY_LIST_FOR_SAFE(ext->child, next, stmt) { |
| 66 | lysp_stmt_free(ctx, stmt); |
| 67 | } |
| 68 | } |
| 69 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 70 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 71 | lysp_import_free(struct ly_ctx *ctx, struct lysp_import *import) |
| 72 | { |
| 73 | /* imported module is freed directly from the context's list */ |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 74 | lydict_remove(ctx, import->name); |
| 75 | lydict_remove(ctx, import->prefix); |
| 76 | lydict_remove(ctx, import->dsc); |
| 77 | lydict_remove(ctx, import->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 78 | FREE_ARRAY(ctx, import->exts, lysp_ext_instance_free); |
| 79 | } |
| 80 | |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 81 | /** |
| 82 | * @brief Common function to erase include record in main module and submodule. |
| 83 | * |
| 84 | * There is a difference since the main module is expected to have the complete list if the included submodules and |
| 85 | * the parsed submodule is shared with any include in a submodule. Therefore, the referenced submodules in the include |
| 86 | * record are freed only from main module's records. |
| 87 | * |
| 88 | * @param[in] ctx libyang context |
| 89 | * @param[in] include The include record to be erased, the record itself is not freed. |
| 90 | * @param[in] main_module Flag to get know if the include record is placed in main module so also the referenced submodule |
| 91 | * is supposed to be freed. |
| 92 | */ |
| 93 | static void |
| 94 | lysp_include_free_(struct ly_ctx *ctx, struct lysp_include *include, ly_bool main_module) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 95 | { |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 96 | if (main_module && include->submodule) { |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 97 | lysp_module_free((struct lysp_module *)include->submodule); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 98 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 99 | lydict_remove(ctx, include->name); |
| 100 | lydict_remove(ctx, include->dsc); |
| 101 | lydict_remove(ctx, include->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 102 | FREE_ARRAY(ctx, include->exts, lysp_ext_instance_free); |
| 103 | } |
| 104 | |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 105 | void |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 106 | lysp_include_free_submodule(struct ly_ctx *ctx, struct lysp_include *include) |
| 107 | { |
Michal Vasko | a0a498b | 2021-09-22 12:17:48 +0200 | [diff] [blame] | 108 | lysp_include_free_(ctx, include, 0); |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void |
| 112 | lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include) |
| 113 | { |
Michal Vasko | a0a498b | 2021-09-22 12:17:48 +0200 | [diff] [blame] | 114 | lysp_include_free_(ctx, include, 1); |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 118 | lysp_revision_free(struct ly_ctx *ctx, struct lysp_revision *rev) |
| 119 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 120 | lydict_remove(ctx, rev->dsc); |
| 121 | lydict_remove(ctx, rev->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 122 | FREE_ARRAY(ctx, rev->exts, lysp_ext_instance_free); |
| 123 | } |
| 124 | |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 125 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 126 | lysp_ext_free(struct ly_ctx *ctx, struct lysp_ext *ext) |
| 127 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 128 | lydict_remove(ctx, ext->name); |
Radek Krejci | 9f87b0c | 2021-03-05 14:45:26 +0100 | [diff] [blame] | 129 | lydict_remove(ctx, ext->argname); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 130 | lydict_remove(ctx, ext->dsc); |
| 131 | lydict_remove(ctx, ext->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 132 | FREE_ARRAY(ctx, ext->exts, lysp_ext_instance_free); |
Michal Vasko | 5fe75f1 | 2020-03-02 13:52:37 +0100 | [diff] [blame] | 133 | if (ext->compiled) { |
| 134 | lysc_extension_free(ctx, &ext->compiled); |
| 135 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 136 | } |
| 137 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 138 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 139 | lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat) |
| 140 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 141 | lydict_remove(ctx, feat->name); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 142 | FREE_ARRAY(ctx, feat->iffeatures, lysp_qname_free); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 143 | FREE_ARRAY(ctx, feat->iffeatures_c, lysc_iffeature_free); |
| 144 | LY_ARRAY_FREE(feat->depfeatures); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 145 | lydict_remove(ctx, feat->dsc); |
| 146 | lydict_remove(ctx, feat->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 147 | FREE_ARRAY(ctx, feat->exts, lysp_ext_instance_free); |
| 148 | } |
| 149 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 150 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 151 | lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident) |
| 152 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 153 | lydict_remove(ctx, ident->name); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 154 | FREE_ARRAY(ctx, ident->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 155 | FREE_STRINGS(ctx, ident->bases); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 156 | lydict_remove(ctx, ident->dsc); |
| 157 | lydict_remove(ctx, ident->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 158 | FREE_ARRAY(ctx, ident->exts, lysp_ext_instance_free); |
| 159 | } |
| 160 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 161 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 162 | lysp_restr_free(struct ly_ctx *ctx, struct lysp_restr *restr) |
| 163 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 164 | lydict_remove(ctx, restr->arg.str); |
| 165 | lydict_remove(ctx, restr->emsg); |
| 166 | lydict_remove(ctx, restr->eapptag); |
| 167 | lydict_remove(ctx, restr->dsc); |
| 168 | lydict_remove(ctx, restr->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 169 | FREE_ARRAY(ctx, restr->exts, lysp_ext_instance_free); |
| 170 | } |
| 171 | |
| 172 | static void |
| 173 | lysp_type_enum_free(struct ly_ctx *ctx, struct lysp_type_enum *item) |
| 174 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 175 | lydict_remove(ctx, item->name); |
| 176 | lydict_remove(ctx, item->dsc); |
| 177 | lydict_remove(ctx, item->ref); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 178 | FREE_ARRAY(ctx, item->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 179 | FREE_ARRAY(ctx, item->exts, lysp_ext_instance_free); |
| 180 | } |
| 181 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 182 | void lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type); |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 183 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 184 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 185 | lysp_type_free(struct ly_ctx *ctx, struct lysp_type *type) |
| 186 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 187 | lydict_remove(ctx, type->name); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 188 | FREE_MEMBER(ctx, type->range, lysp_restr_free); |
| 189 | FREE_MEMBER(ctx, type->length, lysp_restr_free); |
| 190 | FREE_ARRAY(ctx, type->patterns, lysp_restr_free); |
| 191 | FREE_ARRAY(ctx, type->enums, lysp_type_enum_free); |
| 192 | FREE_ARRAY(ctx, type->bits, lysp_type_enum_free); |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 193 | lyxp_expr_free(ctx, type->path); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 194 | FREE_STRINGS(ctx, type->bases); |
| 195 | FREE_ARRAY(ctx, type->types, lysp_type_free); |
| 196 | FREE_ARRAY(ctx, type->exts, lysp_ext_instance_free); |
| 197 | if (type->compiled) { |
| 198 | lysc_type_free(ctx, type->compiled); |
| 199 | } |
| 200 | } |
| 201 | |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 202 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 203 | lysp_tpdf_free(struct ly_ctx *ctx, struct lysp_tpdf *tpdf) |
| 204 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 205 | lydict_remove(ctx, tpdf->name); |
| 206 | lydict_remove(ctx, tpdf->units); |
| 207 | lydict_remove(ctx, tpdf->dflt.str); |
| 208 | lydict_remove(ctx, tpdf->dsc); |
| 209 | lydict_remove(ctx, tpdf->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 210 | FREE_ARRAY(ctx, tpdf->exts, lysp_ext_instance_free); |
| 211 | |
| 212 | lysp_type_free(ctx, &tpdf->type); |
| 213 | |
| 214 | } |
| 215 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 216 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 217 | lysp_grp_free(struct ly_ctx *ctx, struct lysp_node_grp *grp) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 218 | { |
| 219 | struct lysp_node *node, *next; |
| 220 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 221 | FREE_ARRAY(ctx, grp->typedefs, lysp_tpdf_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 222 | LY_LIST_FOR_SAFE((struct lysp_node *)grp->groupings, next, node) { |
| 223 | lysp_node_free(ctx, node); |
| 224 | } |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 225 | LY_LIST_FOR_SAFE(grp->child, next, node) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 226 | lysp_node_free(ctx, node); |
| 227 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 228 | LY_LIST_FOR_SAFE((struct lysp_node *)grp->actions, next, node) { |
| 229 | lysp_node_free(ctx, node); |
| 230 | } |
| 231 | LY_LIST_FOR_SAFE((struct lysp_node *)grp->notifs, next, node) { |
| 232 | lysp_node_free(ctx, node); |
| 233 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 234 | } |
| 235 | |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 236 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 237 | lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when) |
| 238 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 239 | lydict_remove(ctx, when->cond); |
| 240 | lydict_remove(ctx, when->dsc); |
| 241 | lydict_remove(ctx, when->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 242 | FREE_ARRAY(ctx, when->exts, lysp_ext_instance_free); |
| 243 | } |
| 244 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 245 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 246 | lysp_augment_free(struct ly_ctx *ctx, struct lysp_node_augment *augment) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 247 | { |
| 248 | struct lysp_node *node, *next; |
| 249 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 250 | LY_LIST_FOR_SAFE(augment->child, next, node) { |
| 251 | lysp_node_free(ctx, node); |
| 252 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 253 | LY_LIST_FOR_SAFE((struct lysp_node *)augment->actions, next, node) { |
| 254 | lysp_node_free(ctx, node); |
| 255 | } |
| 256 | LY_LIST_FOR_SAFE((struct lysp_node *)augment->notifs, next, node) { |
| 257 | lysp_node_free(ctx, node); |
| 258 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 259 | } |
| 260 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 261 | void |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 262 | lysp_qname_free(struct ly_ctx *ctx, struct lysp_qname *qname) |
| 263 | { |
| 264 | if (qname) { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 265 | lydict_remove(ctx, qname->str); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | |
| 269 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 270 | lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d) |
| 271 | { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 272 | struct lysp_deviate_add *add = (struct lysp_deviate_add *)d; |
| 273 | struct lysp_deviate_rpl *rpl = (struct lysp_deviate_rpl *)d; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 274 | |
| 275 | FREE_ARRAY(ctx, d->exts, lysp_ext_instance_free); |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 276 | switch (d->mod) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 277 | case LYS_DEV_NOT_SUPPORTED: |
| 278 | /* nothing to do */ |
| 279 | break; |
| 280 | case LYS_DEV_ADD: |
| 281 | case LYS_DEV_DELETE: /* compatible for dynamically allocated data */ |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 282 | lydict_remove(ctx, add->units); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 283 | FREE_ARRAY(ctx, add->musts, lysp_restr_free); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 284 | FREE_ARRAY(ctx, add->uniques, lysp_qname_free); |
| 285 | FREE_ARRAY(ctx, add->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 286 | break; |
| 287 | case LYS_DEV_REPLACE: |
| 288 | FREE_MEMBER(ctx, rpl->type, lysp_type_free); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 289 | lydict_remove(ctx, rpl->units); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 290 | lysp_qname_free(ctx, &rpl->dflt); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 291 | break; |
| 292 | default: |
| 293 | LOGINT(ctx); |
| 294 | break; |
| 295 | } |
| 296 | } |
| 297 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 298 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 299 | lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev) |
| 300 | { |
| 301 | struct lysp_deviate *next, *iter; |
| 302 | |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 303 | lydict_remove(ctx, dev->nodeid); |
| 304 | lydict_remove(ctx, dev->dsc); |
| 305 | lydict_remove(ctx, dev->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 306 | LY_LIST_FOR_SAFE(dev->deviates, next, iter) { |
| 307 | lysp_deviate_free(ctx, iter); |
| 308 | free(iter); |
| 309 | } |
| 310 | FREE_ARRAY(ctx, dev->exts, lysp_ext_instance_free); |
| 311 | } |
| 312 | |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 313 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 314 | lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref) |
| 315 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 316 | lydict_remove(ctx, ref->nodeid); |
| 317 | lydict_remove(ctx, ref->dsc); |
| 318 | lydict_remove(ctx, ref->ref); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 319 | FREE_ARRAY(ctx, ref->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 320 | FREE_ARRAY(ctx, ref->musts, lysp_restr_free); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 321 | lydict_remove(ctx, ref->presence); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 322 | FREE_ARRAY(ctx, ref->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 323 | FREE_ARRAY(ctx, ref->exts, lysp_ext_instance_free); |
| 324 | } |
| 325 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 326 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 327 | lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node) |
| 328 | { |
| 329 | struct lysp_node *child, *next; |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 330 | struct lysp_node_container *cont; |
| 331 | struct lysp_node_leaf *leaf; |
| 332 | struct lysp_node_leaflist *llist; |
| 333 | struct lysp_node_list *list; |
| 334 | struct lysp_node_choice *choice; |
| 335 | struct lysp_node_case *cas; |
| 336 | struct lysp_node_uses *uses; |
| 337 | struct lysp_node_action *act; |
| 338 | struct lysp_node_action_inout *inout; |
| 339 | struct lysp_node_notif *notif; |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 340 | struct lysp_restr *musts = lysp_node_musts(node); |
| 341 | struct lysp_when *when = lysp_node_when(node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 342 | |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 343 | lydict_remove(ctx, node->name); |
| 344 | lydict_remove(ctx, node->dsc); |
| 345 | lydict_remove(ctx, node->ref); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 346 | FREE_ARRAY(ctx, node->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 347 | FREE_ARRAY(ctx, node->exts, lysp_ext_instance_free); |
| 348 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 349 | FREE_MEMBER(ctx, when, lysp_when_free); |
| 350 | FREE_ARRAY(ctx, musts, lysp_restr_free); |
| 351 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 352 | switch (node->nodetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 353 | case LYS_CONTAINER: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 354 | cont = (struct lysp_node_container *)node; |
| 355 | |
| 356 | lydict_remove(ctx, cont->presence); |
| 357 | FREE_ARRAY(ctx, cont->typedefs, lysp_tpdf_free); |
| 358 | if (cont->groupings) { |
| 359 | LY_LIST_FOR_SAFE(&cont->groupings->node, next, child) { |
| 360 | lysp_node_free(ctx, child); |
| 361 | } |
| 362 | } |
| 363 | LY_LIST_FOR_SAFE(cont->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 364 | lysp_node_free(ctx, child); |
| 365 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 366 | if (cont->actions) { |
| 367 | LY_LIST_FOR_SAFE(&cont->actions->node, next, child) { |
| 368 | lysp_node_free(ctx, child); |
| 369 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 370 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 371 | if (cont->notifs) { |
| 372 | LY_LIST_FOR_SAFE(&cont->notifs->node, next, child) { |
| 373 | lysp_node_free(ctx, child); |
| 374 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 375 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 376 | break; |
| 377 | case LYS_LEAF: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 378 | leaf = (struct lysp_node_leaf *)node; |
| 379 | |
| 380 | lysp_type_free(ctx, &leaf->type); |
| 381 | lydict_remove(ctx, leaf->units); |
| 382 | lydict_remove(ctx, leaf->dflt.str); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 383 | break; |
| 384 | case LYS_LEAFLIST: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 385 | llist = (struct lysp_node_leaflist *)node; |
| 386 | |
| 387 | lysp_type_free(ctx, &llist->type); |
| 388 | lydict_remove(ctx, llist->units); |
| 389 | FREE_ARRAY(ctx, llist->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 390 | break; |
| 391 | case LYS_LIST: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 392 | list = (struct lysp_node_list *)node; |
| 393 | |
| 394 | lydict_remove(ctx, list->key); |
| 395 | FREE_ARRAY(ctx, list->typedefs, lysp_tpdf_free); |
| 396 | if (list->groupings) { |
| 397 | LY_LIST_FOR_SAFE(&list->groupings->node, next, child) { |
| 398 | lysp_node_free(ctx, child); |
| 399 | } |
| 400 | } |
| 401 | LY_LIST_FOR_SAFE(list->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 402 | lysp_node_free(ctx, child); |
| 403 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 404 | if (list->actions) { |
| 405 | LY_LIST_FOR_SAFE(&list->actions->node, next, child) { |
| 406 | lysp_node_free(ctx, child); |
| 407 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 408 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 409 | if (list->notifs) { |
| 410 | LY_LIST_FOR_SAFE(&list->notifs->node, next, child) { |
| 411 | lysp_node_free(ctx, child); |
| 412 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 413 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 414 | FREE_ARRAY(ctx, list->uniques, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 415 | break; |
| 416 | case LYS_CHOICE: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 417 | choice = (struct lysp_node_choice *)node; |
| 418 | |
| 419 | LY_LIST_FOR_SAFE(choice->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 420 | lysp_node_free(ctx, child); |
| 421 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 422 | lydict_remove(ctx, choice->dflt.str); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 423 | break; |
| 424 | case LYS_CASE: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 425 | cas = (struct lysp_node_case *)node; |
| 426 | |
| 427 | LY_LIST_FOR_SAFE(cas->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 428 | lysp_node_free(ctx, child); |
| 429 | } |
| 430 | break; |
| 431 | case LYS_ANYDATA: |
| 432 | case LYS_ANYXML: |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 433 | /* nothing special to do */ |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 434 | break; |
| 435 | case LYS_USES: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 436 | uses = (struct lysp_node_uses *)node; |
| 437 | |
| 438 | FREE_ARRAY(ctx, uses->refines, lysp_refine_free); |
| 439 | if (uses->augments) { |
| 440 | LY_LIST_FOR_SAFE(&uses->augments->node, next, child) { |
| 441 | lysp_node_free(ctx, child); |
| 442 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 443 | } |
| 444 | break; |
| 445 | case LYS_RPC: |
| 446 | case LYS_ACTION: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 447 | act = (struct lysp_node_action *)node; |
| 448 | |
| 449 | FREE_ARRAY(ctx, act->typedefs, lysp_tpdf_free); |
| 450 | if (act->groupings) { |
| 451 | LY_LIST_FOR_SAFE(&act->groupings->node, next, child) { |
| 452 | lysp_node_free(ctx, child); |
| 453 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 454 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 455 | if (act->input.nodetype) { |
| 456 | lysp_node_free(ctx, &act->input.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 457 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 458 | if (act->output.nodetype) { |
| 459 | lysp_node_free(ctx, &act->output.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 460 | } |
| 461 | break; |
| 462 | case LYS_INPUT: |
| 463 | case LYS_OUTPUT: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 464 | inout = (struct lysp_node_action_inout *)node; |
| 465 | |
| 466 | FREE_ARRAY(ctx, inout->typedefs, lysp_tpdf_free); |
| 467 | if (inout->groupings) { |
| 468 | LY_LIST_FOR_SAFE(&inout->groupings->node, next, child) { |
| 469 | lysp_node_free(ctx, child); |
| 470 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 471 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 472 | LY_LIST_FOR_SAFE(inout->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 473 | lysp_node_free(ctx, child); |
| 474 | } |
| 475 | /* do not free the node, it is never standalone but part of the action node */ |
| 476 | return; |
| 477 | case LYS_NOTIF: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 478 | notif = (struct lysp_node_notif *)node; |
| 479 | |
| 480 | FREE_ARRAY(ctx, notif->typedefs, lysp_tpdf_free); |
| 481 | if (notif->groupings) { |
| 482 | LY_LIST_FOR_SAFE(¬if->groupings->node, next, child) { |
| 483 | lysp_node_free(ctx, child); |
| 484 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 485 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 486 | LY_LIST_FOR_SAFE(notif->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 487 | lysp_node_free(ctx, child); |
| 488 | } |
| 489 | break; |
| 490 | case LYS_GROUPING: |
| 491 | lysp_grp_free(ctx, (struct lysp_node_grp *)node); |
| 492 | break; |
| 493 | case LYS_AUGMENT: |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 494 | lysp_augment_free(ctx, ((struct lysp_node_augment *)node)); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 495 | break; |
| 496 | default: |
| 497 | LOGINT(ctx); |
| 498 | } |
| 499 | |
| 500 | free(node); |
| 501 | } |
| 502 | |
Radek Krejci | 15f10ab | 2020-11-03 14:14:14 +0100 | [diff] [blame] | 503 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 504 | lysp_module_free(struct lysp_module *module) |
| 505 | { |
| 506 | struct ly_ctx *ctx; |
| 507 | struct lysp_node *node, *next; |
| 508 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 509 | if (!module) { |
| 510 | return; |
| 511 | } |
| 512 | ctx = module->mod->ctx; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 513 | |
| 514 | FREE_ARRAY(ctx, module->imports, lysp_import_free); |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 515 | FREE_ARRAY(ctx, module->includes, module->is_submod ? lysp_include_free_submodule : lysp_include_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 516 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 517 | FREE_ARRAY(ctx, module->revs, lysp_revision_free); |
| 518 | FREE_ARRAY(ctx, module->extensions, lysp_ext_free); |
| 519 | FREE_ARRAY(ctx, module->features, lysp_feature_free); |
| 520 | FREE_ARRAY(ctx, module->identities, lysp_ident_free); |
| 521 | FREE_ARRAY(ctx, module->typedefs, lysp_tpdf_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 522 | LY_LIST_FOR_SAFE((struct lysp_node *)module->groupings, next, node) { |
| 523 | lysp_node_free(ctx, node); |
| 524 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 525 | LY_LIST_FOR_SAFE(module->data, next, node) { |
| 526 | lysp_node_free(ctx, node); |
| 527 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 528 | LY_LIST_FOR_SAFE((struct lysp_node *)module->augments, next, node) { |
| 529 | lysp_node_free(ctx, node); |
| 530 | } |
| 531 | LY_LIST_FOR_SAFE((struct lysp_node *)module->rpcs, next, node) { |
| 532 | lysp_node_free(ctx, node); |
| 533 | } |
| 534 | LY_LIST_FOR_SAFE((struct lysp_node *)module->notifs, next, node) { |
| 535 | lysp_node_free(ctx, node); |
| 536 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 537 | FREE_ARRAY(ctx, module->deviations, lysp_deviation_free); |
| 538 | FREE_ARRAY(ctx, module->exts, lysp_ext_instance_free); |
| 539 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 540 | if (module->is_submod) { |
| 541 | struct lysp_submodule *submod = (struct lysp_submodule *)module; |
| 542 | |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 543 | lydict_remove(ctx, submod->name); |
| 544 | lydict_remove(ctx, submod->filepath); |
| 545 | lydict_remove(ctx, submod->prefix); |
| 546 | lydict_remove(ctx, submod->org); |
| 547 | lydict_remove(ctx, submod->contact); |
| 548 | lydict_remove(ctx, submod->dsc); |
| 549 | lydict_remove(ctx, submod->ref); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 550 | } |
| 551 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 552 | free(module); |
| 553 | } |
| 554 | |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 555 | void |
Michal Vasko | 6f4cbb6 | 2020-02-28 11:15:47 +0100 | [diff] [blame] | 556 | lysc_extension_free(struct ly_ctx *ctx, struct lysc_ext **ext) |
| 557 | { |
| 558 | if (--(*ext)->refcount) { |
| 559 | return; |
| 560 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 561 | lydict_remove(ctx, (*ext)->name); |
Radek Krejci | 9f87b0c | 2021-03-05 14:45:26 +0100 | [diff] [blame] | 562 | lydict_remove(ctx, (*ext)->argname); |
Michal Vasko | 6f4cbb6 | 2020-02-28 11:15:47 +0100 | [diff] [blame] | 563 | FREE_ARRAY(ctx, (*ext)->exts, lysc_ext_instance_free); |
| 564 | free(*ext); |
Radek Krejci | 720d261 | 2021-03-03 19:44:22 +0100 | [diff] [blame] | 565 | *ext = NULL; |
Michal Vasko | 6f4cbb6 | 2020-02-28 11:15:47 +0100 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 569 | lysc_ext_instance_free(struct ly_ctx *ctx, struct lysc_ext_instance *ext) |
| 570 | { |
fredgan | ebc5057 | 2019-10-31 15:39:23 +0800 | [diff] [blame] | 571 | if (ext->def && ext->def->plugin && ext->def->plugin->free) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 572 | ext->def->plugin->free(ctx, ext); |
| 573 | } |
Juraj Vijtiuk | 4a19ab0 | 2020-03-03 13:50:14 +0100 | [diff] [blame] | 574 | if (ext->def) { |
| 575 | lysc_extension_free(ctx, &ext->def); |
| 576 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 577 | lydict_remove(ctx, ext->argument); |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 578 | FREE_ARRAY(ctx, ext->exts, lysc_ext_instance_free); |
| 579 | } |
| 580 | |
| 581 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 582 | lysc_iffeature_free(struct ly_ctx *UNUSED(ctx), struct lysc_iffeature *iff) |
| 583 | { |
| 584 | LY_ARRAY_FREE(iff->features); |
| 585 | free(iff->expr); |
| 586 | } |
| 587 | |
| 588 | static void |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 589 | lysc_when_free(struct ly_ctx *ctx, struct lysc_when **w) |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 590 | { |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 591 | if (--(*w)->refcount) { |
| 592 | return; |
| 593 | } |
| 594 | lyxp_expr_free(ctx, (*w)->cond); |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 595 | ly_free_prefix_data(LY_VALUE_SCHEMA_RESOLVED, (*w)->prefixes); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 596 | lydict_remove(ctx, (*w)->dsc); |
| 597 | lydict_remove(ctx, (*w)->ref); |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 598 | FREE_ARRAY(ctx, (*w)->exts, lysc_ext_instance_free); |
| 599 | free(*w); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 600 | } |
| 601 | |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 602 | void |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 603 | lysc_must_free(struct ly_ctx *ctx, struct lysc_must *must) |
| 604 | { |
| 605 | lyxp_expr_free(ctx, must->cond); |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 606 | ly_free_prefix_data(LY_VALUE_SCHEMA_RESOLVED, must->prefixes); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 607 | lydict_remove(ctx, must->emsg); |
| 608 | lydict_remove(ctx, must->eapptag); |
| 609 | lydict_remove(ctx, must->dsc); |
| 610 | lydict_remove(ctx, must->ref); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 611 | FREE_ARRAY(ctx, must->exts, lysc_ext_instance_free); |
| 612 | } |
| 613 | |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 614 | static void |
| 615 | lysc_ident_derived_unlink(const struct lysc_ident *ident) |
| 616 | { |
| 617 | LY_ARRAY_COUNT_TYPE u, v, w; |
| 618 | const struct lysp_submodule *submod; |
Michal Vasko | d84b813 | 2022-03-15 10:45:44 +0100 | [diff] [blame] | 619 | const struct lysp_module *base_pmod = NULL; |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 620 | const struct lysp_ident *identp = NULL; |
| 621 | const struct lys_module *mod; |
| 622 | const char *base_name; |
| 623 | |
| 624 | /* find the parsed identity */ |
| 625 | LY_ARRAY_FOR(ident->module->parsed->identities, u) { |
| 626 | if (ident->module->parsed->identities[u].name == ident->name) { |
| 627 | identp = &ident->module->parsed->identities[u]; |
| 628 | base_pmod = ident->module->parsed; |
| 629 | break; |
| 630 | } |
| 631 | } |
| 632 | if (!identp) { |
| 633 | LY_ARRAY_FOR(ident->module->parsed->includes, v) { |
| 634 | submod = ident->module->parsed->includes[v].submodule; |
| 635 | LY_ARRAY_FOR(submod->identities, u) { |
| 636 | if (submod->identities[u].name == ident->name) { |
| 637 | identp = &submod->identities[u]; |
| 638 | base_pmod = (struct lysp_module *)submod; |
| 639 | break; |
| 640 | } |
| 641 | } |
| 642 | } |
| 643 | } |
| 644 | assert(identp); |
| 645 | |
| 646 | /* remove link from all the foreign bases, it may not be there if identity compilation failed */ |
| 647 | LY_ARRAY_FOR(identp->bases, u) { |
| 648 | base_name = strchr(identp->bases[u], ':'); |
| 649 | if (!base_name) { |
| 650 | continue; |
| 651 | } |
| 652 | |
| 653 | /* prefixed identity */ |
| 654 | mod = ly_resolve_prefix(ident->module->ctx, identp->bases[u], base_name - identp->bases[u], LY_VALUE_SCHEMA, |
| 655 | (void *)base_pmod); |
| 656 | if (!mod) { |
| 657 | continue; |
| 658 | } |
| 659 | ++base_name; |
| 660 | |
| 661 | /* find the compiled base */ |
| 662 | LY_ARRAY_FOR(mod->identities, v) { |
| 663 | if (!strcmp(mod->identities[v].name, base_name)) { |
| 664 | /* find the derived link */ |
| 665 | LY_ARRAY_FOR(mod->identities[v].derived, w) { |
| 666 | if (mod->identities[v].derived[w] == ident) { |
| 667 | /* remove the link */ |
| 668 | LY_ARRAY_DECREMENT(mod->identities[v].derived); |
| 669 | if (w < LY_ARRAY_COUNT(mod->identities[v].derived)) { |
| 670 | memmove(mod->identities[v].derived + w, mod->identities[v].derived + w + 1, |
| 671 | (LY_ARRAY_COUNT(mod->identities[v].derived) - w) * sizeof ident); |
| 672 | } |
| 673 | break; |
| 674 | } |
| 675 | } |
| 676 | break; |
| 677 | } |
| 678 | } |
| 679 | } |
| 680 | } |
| 681 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 682 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 683 | lysc_ident_free(struct ly_ctx *ctx, struct lysc_ident *ident) |
| 684 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 685 | lydict_remove(ctx, ident->name); |
| 686 | lydict_remove(ctx, ident->dsc); |
| 687 | lydict_remove(ctx, ident->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 688 | LY_ARRAY_FREE(ident->derived); |
| 689 | FREE_ARRAY(ctx, ident->exts, lysc_ext_instance_free); |
| 690 | } |
| 691 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 692 | static void |
| 693 | lysc_range_free(struct ly_ctx *ctx, struct lysc_range *range) |
| 694 | { |
| 695 | LY_ARRAY_FREE(range->parts); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 696 | lydict_remove(ctx, range->eapptag); |
| 697 | lydict_remove(ctx, range->emsg); |
| 698 | lydict_remove(ctx, range->dsc); |
| 699 | lydict_remove(ctx, range->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 700 | FREE_ARRAY(ctx, range->exts, lysc_ext_instance_free); |
| 701 | } |
| 702 | |
| 703 | static void |
| 704 | lysc_pattern_free(struct ly_ctx *ctx, struct lysc_pattern **pattern) |
| 705 | { |
| 706 | if (--(*pattern)->refcount) { |
| 707 | return; |
| 708 | } |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 709 | pcre2_code_free((*pattern)->code); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 710 | lydict_remove(ctx, (*pattern)->expr); |
| 711 | lydict_remove(ctx, (*pattern)->eapptag); |
| 712 | lydict_remove(ctx, (*pattern)->emsg); |
| 713 | lydict_remove(ctx, (*pattern)->dsc); |
| 714 | lydict_remove(ctx, (*pattern)->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 715 | FREE_ARRAY(ctx, (*pattern)->exts, lysc_ext_instance_free); |
| 716 | free(*pattern); |
| 717 | } |
| 718 | |
Michal Vasko | f4fa90d | 2021-11-11 15:05:19 +0100 | [diff] [blame] | 719 | void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 720 | lysc_enum_item_free(struct ly_ctx *ctx, struct lysc_type_bitenum_item *item) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 721 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 722 | lydict_remove(ctx, item->name); |
| 723 | lydict_remove(ctx, item->dsc); |
| 724 | lydict_remove(ctx, item->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 725 | FREE_ARRAY(ctx, item->exts, lysc_ext_instance_free); |
| 726 | } |
| 727 | |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 728 | static void |
| 729 | lysc_type2_free(struct ly_ctx *ctx, struct lysc_type **type) |
| 730 | { |
| 731 | lysc_type_free(ctx, *type); |
| 732 | } |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 733 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 734 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 735 | lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type) |
| 736 | { |
Michal Vasko | d310504 | 2021-09-01 08:11:57 +0200 | [diff] [blame] | 737 | if (LY_ATOMIC_DEC_BARRIER(type->refcount) > 1) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 738 | return; |
| 739 | } |
Radek Krejci | b915ac9 | 2020-08-14 23:31:04 +0200 | [diff] [blame] | 740 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 741 | switch (type->basetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 742 | case LY_TYPE_BINARY: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 743 | FREE_MEMBER(ctx, ((struct lysc_type_bin *)type)->length, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 744 | break; |
| 745 | case LY_TYPE_BITS: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 746 | FREE_ARRAY(ctx, (struct lysc_type_bitenum_item *)((struct lysc_type_bits *)type)->bits, lysc_enum_item_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 747 | break; |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 748 | case LY_TYPE_DEC64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 749 | FREE_MEMBER(ctx, ((struct lysc_type_dec *)type)->range, lysc_range_free); |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 750 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 751 | case LY_TYPE_STRING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 752 | FREE_MEMBER(ctx, ((struct lysc_type_str *)type)->length, lysc_range_free); |
| 753 | FREE_ARRAY(ctx, ((struct lysc_type_str *)type)->patterns, lysc_pattern_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 754 | break; |
| 755 | case LY_TYPE_ENUM: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 756 | FREE_ARRAY(ctx, ((struct lysc_type_enum *)type)->enums, lysc_enum_item_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 757 | break; |
| 758 | case LY_TYPE_INT8: |
| 759 | case LY_TYPE_UINT8: |
| 760 | case LY_TYPE_INT16: |
| 761 | case LY_TYPE_UINT16: |
| 762 | case LY_TYPE_INT32: |
| 763 | case LY_TYPE_UINT32: |
| 764 | case LY_TYPE_INT64: |
| 765 | case LY_TYPE_UINT64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 766 | FREE_MEMBER(ctx, ((struct lysc_type_num *)type)->range, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 767 | break; |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 768 | case LY_TYPE_IDENT: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 769 | LY_ARRAY_FREE(((struct lysc_type_identityref *)type)->bases); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 770 | break; |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 771 | case LY_TYPE_UNION: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 772 | FREE_ARRAY(ctx, ((struct lysc_type_union *)type)->types, lysc_type2_free); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 773 | break; |
| 774 | case LY_TYPE_LEAFREF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 775 | lyxp_expr_free(ctx, ((struct lysc_type_leafref *)type)->path); |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 776 | ly_free_prefix_data(LY_VALUE_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 777 | break; |
Radek Krejci | 16c0f82 | 2018-11-16 10:46:10 +0100 | [diff] [blame] | 778 | case LY_TYPE_INST: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 779 | case LY_TYPE_BOOL: |
| 780 | case LY_TYPE_EMPTY: |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 781 | case LY_TYPE_UNKNOWN: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 782 | /* nothing to do */ |
| 783 | break; |
| 784 | } |
Michal Vasko | ba99a3e | 2020-08-18 15:50:05 +0200 | [diff] [blame] | 785 | |
| 786 | FREE_ARRAY(ctx, type->exts, lysc_ext_instance_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 787 | free(type); |
| 788 | } |
| 789 | |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 790 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 791 | lysc_node_action_inout_free(struct ly_ctx *ctx, struct lysc_node_action_inout *inout) |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 792 | { |
| 793 | struct lysc_node *child, *child_next; |
| 794 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 795 | FREE_ARRAY(ctx, inout->musts, lysc_must_free); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 796 | LY_LIST_FOR_SAFE(inout->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 797 | lysc_node_free_(ctx, child); |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 798 | } |
| 799 | } |
| 800 | |
| 801 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 802 | lysc_node_action_free(struct ly_ctx *ctx, struct lysc_node_action *action) |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 803 | { |
Michal Vasko | 37a0fe6 | 2021-02-03 09:53:04 +0100 | [diff] [blame] | 804 | FREE_ARRAY(ctx, action->when, lysc_when_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 805 | if (action->input.nodetype) { |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 806 | lysc_node_free_(ctx, &action->input.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 807 | } |
| 808 | if (action->output.nodetype) { |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 809 | lysc_node_free_(ctx, &action->output.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 810 | } |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 811 | } |
| 812 | |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 813 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 814 | lysc_node_notif_free(struct ly_ctx *ctx, struct lysc_node_notif *notif) |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 815 | { |
| 816 | struct lysc_node *child, *child_next; |
| 817 | |
Michal Vasko | 37a0fe6 | 2021-02-03 09:53:04 +0100 | [diff] [blame] | 818 | FREE_ARRAY(ctx, notif->when, lysc_when_free); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 819 | FREE_ARRAY(ctx, notif->musts, lysc_must_free); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 820 | LY_LIST_FOR_SAFE(notif->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 821 | lysc_node_free_(ctx, child); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 822 | } |
| 823 | } |
| 824 | |
Radek Krejci | f2de0ed | 2019-05-02 14:13:18 +0200 | [diff] [blame] | 825 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 826 | lysc_node_container_free(struct ly_ctx *ctx, struct lysc_node_container *node) |
| 827 | { |
| 828 | struct lysc_node *child, *child_next; |
| 829 | |
| 830 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 831 | lysc_node_free_(ctx, child); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 832 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 833 | LY_LIST_FOR_SAFE((struct lysc_node *)node->actions, child_next, child) { |
| 834 | lysc_node_free_(ctx, child); |
| 835 | } |
| 836 | LY_LIST_FOR_SAFE((struct lysc_node *)node->notifs, child_next, child) { |
| 837 | lysc_node_free_(ctx, child); |
| 838 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 839 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 840 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | static void |
| 844 | lysc_node_leaf_free(struct ly_ctx *ctx, struct lysc_node_leaf *node) |
| 845 | { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 846 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 847 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 848 | if (node->type) { |
| 849 | lysc_type_free(ctx, node->type); |
| 850 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 851 | lydict_remove(ctx, node->units); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 852 | if (node->dflt) { |
| 853 | node->dflt->realtype->plugin->free(ctx, node->dflt); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 854 | lysc_type_free(ctx, (struct lysc_type *)node->dflt->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 855 | free(node->dflt); |
| 856 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 857 | } |
| 858 | |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 859 | static void |
| 860 | lysc_node_leaflist_free(struct ly_ctx *ctx, struct lysc_node_leaflist *node) |
| 861 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 862 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 863 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 864 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 865 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 866 | if (node->type) { |
| 867 | lysc_type_free(ctx, node->type); |
| 868 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 869 | lydict_remove(ctx, node->units); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 870 | LY_ARRAY_FOR(node->dflts, u) { |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 871 | node->dflts[u]->realtype->plugin->free(ctx, node->dflts[u]); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 872 | lysc_type_free(ctx, (struct lysc_type *)node->dflts[u]->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 873 | free(node->dflts[u]); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 874 | } |
| 875 | LY_ARRAY_FREE(node->dflts); |
| 876 | } |
| 877 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 878 | static void |
| 879 | lysc_node_list_free(struct ly_ctx *ctx, struct lysc_node_list *node) |
| 880 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 881 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 882 | struct lysc_node *child, *child_next; |
| 883 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 884 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 885 | lysc_node_free_(ctx, child); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 886 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 887 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 888 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 889 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 890 | LY_ARRAY_FOR(node->uniques, u) { |
| 891 | LY_ARRAY_FREE(node->uniques[u]); |
| 892 | } |
| 893 | LY_ARRAY_FREE(node->uniques); |
| 894 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 895 | LY_LIST_FOR_SAFE((struct lysc_node *)node->actions, child_next, child) { |
| 896 | lysc_node_free_(ctx, child); |
| 897 | } |
| 898 | LY_LIST_FOR_SAFE((struct lysc_node *)node->notifs, child_next, child) { |
| 899 | lysc_node_free_(ctx, child); |
| 900 | } |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 901 | } |
| 902 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 903 | static void |
| 904 | lysc_node_choice_free(struct ly_ctx *ctx, struct lysc_node_choice *node) |
| 905 | { |
| 906 | struct lysc_node *child, *child_next; |
| 907 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 908 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 909 | LY_LIST_FOR_SAFE((struct lysc_node *)node->cases, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 910 | lysc_node_free_(ctx, child); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 911 | } |
| 912 | } |
| 913 | |
| 914 | static void |
| 915 | lysc_node_case_free(struct ly_ctx *ctx, struct lysc_node_case *node) |
| 916 | { |
| 917 | struct lysc_node *child, *child_next; |
| 918 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 919 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 920 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 921 | lysc_node_free_(ctx, child); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 922 | } |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 923 | } |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 924 | |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 925 | static void |
| 926 | lysc_node_anydata_free(struct ly_ctx *ctx, struct lysc_node_anydata *node) |
| 927 | { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 928 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 929 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 930 | } |
| 931 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 932 | static void |
| 933 | lysc_node_free_(struct ly_ctx *ctx, struct lysc_node *node) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 934 | { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 935 | ly_bool inout = 0; |
| 936 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 937 | /* common part */ |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 938 | lydict_remove(ctx, node->name); |
| 939 | lydict_remove(ctx, node->dsc); |
| 940 | lydict_remove(ctx, node->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 941 | |
| 942 | /* nodetype-specific part */ |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 943 | switch (node->nodetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 944 | case LYS_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 945 | lysc_node_container_free(ctx, (struct lysc_node_container *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 946 | break; |
| 947 | case LYS_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 948 | lysc_node_leaf_free(ctx, (struct lysc_node_leaf *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 949 | break; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 950 | case LYS_LEAFLIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 951 | lysc_node_leaflist_free(ctx, (struct lysc_node_leaflist *)node); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 952 | break; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 953 | case LYS_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 954 | lysc_node_list_free(ctx, (struct lysc_node_list *)node); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 955 | break; |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 956 | case LYS_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 957 | lysc_node_choice_free(ctx, (struct lysc_node_choice *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 958 | break; |
| 959 | case LYS_CASE: |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 960 | lysc_node_case_free(ctx, (struct lysc_node_case *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 961 | break; |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 962 | case LYS_ANYDATA: |
| 963 | case LYS_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 964 | lysc_node_anydata_free(ctx, (struct lysc_node_anydata *)node); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 965 | break; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 966 | case LYS_RPC: |
| 967 | case LYS_ACTION: |
| 968 | lysc_node_action_free(ctx, (struct lysc_node_action *)node); |
| 969 | break; |
| 970 | case LYS_INPUT: |
| 971 | case LYS_OUTPUT: |
| 972 | lysc_node_action_inout_free(ctx, (struct lysc_node_action_inout *)node); |
| 973 | inout = 1; |
| 974 | break; |
| 975 | case LYS_NOTIF: |
| 976 | lysc_node_notif_free(ctx, (struct lysc_node_notif *)node); |
| 977 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 978 | default: |
| 979 | LOGINT(ctx); |
| 980 | } |
| 981 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 982 | FREE_ARRAY(ctx, node->exts, lysc_ext_instance_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 983 | |
| 984 | if (!inout) { |
| 985 | free(node); |
| 986 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 987 | } |
| 988 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 989 | void |
| 990 | lysc_node_free(struct ly_ctx *ctx, struct lysc_node *node, ly_bool unlink) |
| 991 | { |
Michal Vasko | e02e740 | 2021-07-23 08:29:28 +0200 | [diff] [blame] | 992 | struct lysc_node *next, *iter, **child_p; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 993 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 994 | if (node->nodetype & (LYS_INPUT | LYS_OUTPUT)) { |
Michal Vasko | e02e740 | 2021-07-23 08:29:28 +0200 | [diff] [blame] | 995 | /* inouts are part of actions and cannot be unlinked/freed separately, we can only free all the children */ |
| 996 | struct lysc_node_action_inout *inout = (struct lysc_node_action_inout *)node; |
| 997 | LY_LIST_FOR_SAFE(inout->child, next, iter) { |
| 998 | lysc_node_free_(ctx, iter); |
| 999 | } |
| 1000 | inout->child = NULL; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1001 | return; |
| 1002 | } |
| 1003 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1004 | if (unlink) { |
| 1005 | /* unlink from siblings */ |
| 1006 | if (node->prev->next) { |
| 1007 | node->prev->next = node->next; |
| 1008 | } |
| 1009 | if (node->next) { |
| 1010 | node->next->prev = node->prev; |
| 1011 | } else { |
| 1012 | /* unlinking the last node */ |
| 1013 | if (node->parent) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1014 | if (node->nodetype == LYS_ACTION) { |
| 1015 | iter = (struct lysc_node *)lysc_node_actions(node->parent); |
| 1016 | } else if (node->nodetype == LYS_NOTIF) { |
| 1017 | iter = (struct lysc_node *)lysc_node_notifs(node->parent); |
| 1018 | } else { |
Michal Vasko | 544e58a | 2021-01-28 14:33:41 +0100 | [diff] [blame] | 1019 | iter = (struct lysc_node *)lysc_node_child(node->parent); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1020 | } |
Michal Vasko | 539c4a6 | 2020-11-03 17:21:34 +0100 | [diff] [blame] | 1021 | LY_CHECK_ERR_RET(!iter, LOGINT(ctx), ); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1022 | } else if (node->nodetype == LYS_RPC) { |
| 1023 | iter = (struct lysc_node *)node->module->compiled->rpcs; |
| 1024 | } else if (node->nodetype == LYS_NOTIF) { |
| 1025 | iter = (struct lysc_node *)node->module->compiled->notifs; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1026 | } else { |
| 1027 | iter = node->module->compiled->data; |
| 1028 | } |
| 1029 | /* update the "last" pointer from the first node */ |
| 1030 | iter->prev = node->prev; |
| 1031 | } |
| 1032 | |
| 1033 | /* unlink from parent */ |
| 1034 | if (node->parent) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1035 | if (node->nodetype == LYS_ACTION) { |
| 1036 | child_p = (struct lysc_node **)lysc_node_actions_p(node->parent); |
| 1037 | } else if (node->nodetype == LYS_NOTIF) { |
| 1038 | child_p = (struct lysc_node **)lysc_node_notifs_p(node->parent); |
| 1039 | } else { |
Michal Vasko | 544e58a | 2021-01-28 14:33:41 +0100 | [diff] [blame] | 1040 | child_p = lysc_node_child_p(node->parent); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1041 | } |
| 1042 | } else if (node->nodetype == LYS_RPC) { |
| 1043 | child_p = (struct lysc_node **)&node->module->compiled->rpcs; |
| 1044 | } else if (node->nodetype == LYS_NOTIF) { |
| 1045 | child_p = (struct lysc_node **)&node->module->compiled->notifs; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1046 | } else { |
| 1047 | child_p = &node->module->compiled->data; |
| 1048 | } |
| 1049 | if (child_p && (*child_p == node)) { |
| 1050 | /* the node is the first child */ |
| 1051 | *child_p = node->next; |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | lysc_node_free_(ctx, node); |
| 1056 | } |
| 1057 | |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 1058 | void |
| 1059 | lysc_module_free(struct lysc_module *module) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1060 | { |
| 1061 | struct ly_ctx *ctx; |
| 1062 | struct lysc_node *node, *node_next; |
| 1063 | |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 1064 | if (!module) { |
| 1065 | return; |
| 1066 | } |
| 1067 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1068 | ctx = module->mod->ctx; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1069 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1070 | LY_LIST_FOR_SAFE(module->data, node_next, node) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1071 | lysc_node_free_(ctx, node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1072 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1073 | LY_LIST_FOR_SAFE((struct lysc_node *)module->rpcs, node_next, node) { |
| 1074 | lysc_node_free_(ctx, node); |
| 1075 | } |
| 1076 | LY_LIST_FOR_SAFE((struct lysc_node *)module->notifs, node_next, node) { |
| 1077 | lysc_node_free_(ctx, node); |
| 1078 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1079 | FREE_ARRAY(ctx, module->exts, lysc_ext_instance_free); |
| 1080 | |
| 1081 | free(module); |
| 1082 | } |
| 1083 | |
| 1084 | void |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 1085 | lys_module_free(struct lys_module *module, ly_bool remove_links) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1086 | { |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 1087 | LY_ARRAY_COUNT_TYPE u; |
| 1088 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1089 | if (!module) { |
| 1090 | return; |
| 1091 | } |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 1092 | |
Michal Vasko | ee75760 | 2021-06-10 14:38:19 +0200 | [diff] [blame] | 1093 | assert(!module->implemented); |
| 1094 | assert(!module->compiled); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1095 | |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 1096 | if (remove_links) { |
| 1097 | /* remove derived identity links */ |
| 1098 | LY_ARRAY_FOR(module->identities, u) { |
| 1099 | lysc_ident_derived_unlink(&module->identities[u]); |
| 1100 | } |
| 1101 | } |
Radek Krejci | 80d281e | 2020-09-14 17:42:54 +0200 | [diff] [blame] | 1102 | FREE_ARRAY(module->ctx, module->identities, lysc_ident_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1103 | lysp_module_free(module->parsed); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1104 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1105 | LY_ARRAY_FREE(module->augmented_by); |
| 1106 | LY_ARRAY_FREE(module->deviated_by); |
| 1107 | |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1108 | lydict_remove(module->ctx, module->name); |
| 1109 | lydict_remove(module->ctx, module->revision); |
| 1110 | lydict_remove(module->ctx, module->ns); |
| 1111 | lydict_remove(module->ctx, module->prefix); |
| 1112 | lydict_remove(module->ctx, module->filepath); |
| 1113 | lydict_remove(module->ctx, module->org); |
| 1114 | lydict_remove(module->ctx, module->contact); |
| 1115 | lydict_remove(module->ctx, module->dsc); |
| 1116 | lydict_remove(module->ctx, module->ref); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1117 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1118 | free(module); |
| 1119 | } |
Michal Vasko | 33ff942 | 2020-07-03 09:50:39 +0200 | [diff] [blame] | 1120 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 1121 | LIBYANG_API_DEF void |
Radek Krejci | 0b01330 | 2021-03-29 15:22:32 +0200 | [diff] [blame] | 1122 | lyplg_ext_instance_substatements_free(struct ly_ctx *ctx, struct lysc_ext_substmt *substmts) |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1123 | { |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1124 | LY_ARRAY_COUNT_TYPE u; |
| 1125 | |
| 1126 | LY_ARRAY_FOR(substmts, u) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1127 | if (!substmts[u].storage) { |
| 1128 | continue; |
| 1129 | } |
| 1130 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1131 | switch (substmts[u].stmt) { |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1132 | case LY_STMT_ACTION: |
| 1133 | case LY_STMT_ANYDATA: |
| 1134 | case LY_STMT_ANYXML: |
| 1135 | case LY_STMT_CONTAINER: |
| 1136 | case LY_STMT_CHOICE: |
| 1137 | case LY_STMT_LEAF: |
| 1138 | case LY_STMT_LEAF_LIST: |
| 1139 | case LY_STMT_LIST: |
| 1140 | case LY_STMT_NOTIFICATION: |
| 1141 | case LY_STMT_RPC: |
| 1142 | case LY_STMT_USES: { |
| 1143 | struct lysc_node *child, *child_next; |
| 1144 | |
| 1145 | LY_LIST_FOR_SAFE(*((struct lysc_node **)substmts[u].storage), child_next, child) { |
| 1146 | lysc_node_free_(ctx, child); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1147 | } |
| 1148 | break; |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1149 | } |
| 1150 | case LY_STMT_CONFIG: |
| 1151 | case LY_STMT_STATUS: |
| 1152 | /* nothing to do */ |
| 1153 | break; |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1154 | case LY_STMT_DESCRIPTION: |
| 1155 | case LY_STMT_REFERENCE: |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1156 | case LY_STMT_UNITS: |
| 1157 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1158 | /* single item */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1159 | const char *str = *((const char **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1160 | if (!str) { |
| 1161 | break; |
| 1162 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1163 | lydict_remove(ctx, str); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1164 | } else { |
| 1165 | /* multiple items */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1166 | const char **strs = *((const char ***)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1167 | if (!strs) { |
| 1168 | break; |
| 1169 | } |
| 1170 | FREE_STRINGS(ctx, strs); |
| 1171 | } |
| 1172 | break; |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1173 | case LY_STMT_IF_FEATURE: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1174 | struct lysc_iffeature *iff = *((struct lysc_iffeature **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1175 | if (!iff) { |
| 1176 | break; |
| 1177 | } |
| 1178 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1179 | /* single item */ |
| 1180 | lysc_iffeature_free(ctx, iff); |
| 1181 | free(iff); |
| 1182 | } else { |
| 1183 | /* multiple items */ |
| 1184 | FREE_ARRAY(ctx, iff, lysc_iffeature_free); |
| 1185 | } |
| 1186 | break; |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1187 | case LY_STMT_TYPE: |
| 1188 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1189 | /* single item */ |
| 1190 | struct lysc_type *type = *((struct lysc_type **)substmts[u].storage); |
| 1191 | if (!type) { |
| 1192 | break; |
| 1193 | } |
| 1194 | lysc_type_free(ctx, type); |
| 1195 | } else { |
| 1196 | /* multiple items */ |
| 1197 | struct lysc_type **types = *((struct lysc_type ***)substmts[u].storage); |
| 1198 | if (!types) { |
| 1199 | break; |
| 1200 | } |
| 1201 | FREE_ARRAY(ctx, types, lysc_type2_free); |
| 1202 | } |
| 1203 | break; |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1204 | } |
| 1205 | |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1206 | /* TODO other statements */ |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1207 | default: |
| 1208 | LOGINT(ctx); |
| 1209 | } |
| 1210 | } |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1211 | |
| 1212 | LY_ARRAY_FREE(substmts); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1213 | } |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1214 | |
| 1215 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1216 | yang_parser_ctx_free(struct lys_yang_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1217 | { |
| 1218 | if (ctx) { |
aPiecek | 8d4e75d | 2021-06-24 14:47:06 +0200 | [diff] [blame] | 1219 | if (ctx->main_ctx == (struct lys_parser_ctx *)ctx) { |
| 1220 | ly_set_erase(&ctx->tpdfs_nodes, NULL); |
| 1221 | ly_set_erase(&ctx->grps_nodes, NULL); |
| 1222 | } |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 1223 | ly_set_rm_index(ctx->parsed_mods, ctx->parsed_mods->count - 1, NULL); |
| 1224 | if (!ctx->parsed_mods->count) { |
| 1225 | ly_set_free(ctx->parsed_mods, NULL); |
| 1226 | } |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1227 | free(ctx); |
| 1228 | } |
| 1229 | } |
| 1230 | |
| 1231 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1232 | yin_parser_ctx_free(struct lys_yin_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1233 | { |
| 1234 | if (ctx) { |
aPiecek | 8d4e75d | 2021-06-24 14:47:06 +0200 | [diff] [blame] | 1235 | if (ctx->main_ctx == (struct lys_parser_ctx *)ctx) { |
| 1236 | ly_set_erase(&ctx->tpdfs_nodes, NULL); |
| 1237 | ly_set_erase(&ctx->grps_nodes, NULL); |
| 1238 | } |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 1239 | ly_set_rm_index(ctx->parsed_mods, ctx->parsed_mods->count - 1, NULL); |
| 1240 | if (!ctx->parsed_mods->count) { |
| 1241 | ly_set_free(ctx->parsed_mods, NULL); |
| 1242 | } |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1243 | lyxml_ctx_free(ctx->xmlctx); |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1244 | free(ctx); |
| 1245 | } |
| 1246 | } |