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; |
Michal Vasko | d6b5d4e | 2022-03-16 09:23:32 +0100 | [diff] [blame] | 621 | const struct lys_module *mod, *iter; |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 622 | const char *base_name; |
Michal Vasko | d6b5d4e | 2022-03-16 09:23:32 +0100 | [diff] [blame] | 623 | uint32_t i; |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 624 | |
| 625 | /* find the parsed identity */ |
| 626 | LY_ARRAY_FOR(ident->module->parsed->identities, u) { |
| 627 | if (ident->module->parsed->identities[u].name == ident->name) { |
| 628 | identp = &ident->module->parsed->identities[u]; |
| 629 | base_pmod = ident->module->parsed; |
| 630 | break; |
| 631 | } |
| 632 | } |
| 633 | if (!identp) { |
| 634 | LY_ARRAY_FOR(ident->module->parsed->includes, v) { |
| 635 | submod = ident->module->parsed->includes[v].submodule; |
| 636 | LY_ARRAY_FOR(submod->identities, u) { |
| 637 | if (submod->identities[u].name == ident->name) { |
| 638 | identp = &submod->identities[u]; |
| 639 | base_pmod = (struct lysp_module *)submod; |
| 640 | break; |
| 641 | } |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | assert(identp); |
| 646 | |
| 647 | /* remove link from all the foreign bases, it may not be there if identity compilation failed */ |
| 648 | LY_ARRAY_FOR(identp->bases, u) { |
| 649 | base_name = strchr(identp->bases[u], ':'); |
| 650 | if (!base_name) { |
| 651 | continue; |
| 652 | } |
| 653 | |
| 654 | /* prefixed identity */ |
| 655 | mod = ly_resolve_prefix(ident->module->ctx, identp->bases[u], base_name - identp->bases[u], LY_VALUE_SCHEMA, |
| 656 | (void *)base_pmod); |
| 657 | if (!mod) { |
| 658 | continue; |
| 659 | } |
| 660 | ++base_name; |
| 661 | |
Michal Vasko | d6b5d4e | 2022-03-16 09:23:32 +0100 | [diff] [blame] | 662 | i = 0; |
| 663 | while ((iter = ly_ctx_get_module_iter(ident->module->ctx, &i))) { |
| 664 | if (iter == mod) { |
| 665 | break; |
| 666 | } |
| 667 | } |
| 668 | if (!iter) { |
| 669 | /* target module was freed already */ |
| 670 | continue; |
| 671 | } |
| 672 | |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 673 | /* find the compiled base */ |
| 674 | LY_ARRAY_FOR(mod->identities, v) { |
| 675 | if (!strcmp(mod->identities[v].name, base_name)) { |
| 676 | /* find the derived link */ |
| 677 | LY_ARRAY_FOR(mod->identities[v].derived, w) { |
| 678 | if (mod->identities[v].derived[w] == ident) { |
| 679 | /* remove the link */ |
| 680 | LY_ARRAY_DECREMENT(mod->identities[v].derived); |
Michal Vasko | 3fedda1 | 2022-03-16 09:23:45 +0100 | [diff] [blame] | 681 | if (!LY_ARRAY_COUNT(mod->identities[v].derived)) { |
| 682 | LY_ARRAY_FREE(mod->identities[v].derived); |
| 683 | mod->identities[v].derived = NULL; |
| 684 | } else if (w < LY_ARRAY_COUNT(mod->identities[v].derived)) { |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 685 | memmove(mod->identities[v].derived + w, mod->identities[v].derived + w + 1, |
| 686 | (LY_ARRAY_COUNT(mod->identities[v].derived) - w) * sizeof ident); |
| 687 | } |
| 688 | break; |
| 689 | } |
| 690 | } |
| 691 | break; |
| 692 | } |
| 693 | } |
| 694 | } |
| 695 | } |
| 696 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 697 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 698 | lysc_ident_free(struct ly_ctx *ctx, struct lysc_ident *ident) |
| 699 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 700 | lydict_remove(ctx, ident->name); |
| 701 | lydict_remove(ctx, ident->dsc); |
| 702 | lydict_remove(ctx, ident->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 703 | LY_ARRAY_FREE(ident->derived); |
| 704 | FREE_ARRAY(ctx, ident->exts, lysc_ext_instance_free); |
| 705 | } |
| 706 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 707 | static void |
| 708 | lysc_range_free(struct ly_ctx *ctx, struct lysc_range *range) |
| 709 | { |
| 710 | LY_ARRAY_FREE(range->parts); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 711 | lydict_remove(ctx, range->eapptag); |
| 712 | lydict_remove(ctx, range->emsg); |
| 713 | lydict_remove(ctx, range->dsc); |
| 714 | lydict_remove(ctx, range->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 715 | FREE_ARRAY(ctx, range->exts, lysc_ext_instance_free); |
| 716 | } |
| 717 | |
Michal Vasko | 51de7b7 | 2022-04-29 09:50:22 +0200 | [diff] [blame] | 718 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 719 | lysc_pattern_free(struct ly_ctx *ctx, struct lysc_pattern **pattern) |
| 720 | { |
| 721 | if (--(*pattern)->refcount) { |
| 722 | return; |
| 723 | } |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 724 | pcre2_code_free((*pattern)->code); |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 725 | lydict_remove(ctx, (*pattern)->expr); |
| 726 | lydict_remove(ctx, (*pattern)->eapptag); |
| 727 | lydict_remove(ctx, (*pattern)->emsg); |
| 728 | lydict_remove(ctx, (*pattern)->dsc); |
| 729 | lydict_remove(ctx, (*pattern)->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 730 | FREE_ARRAY(ctx, (*pattern)->exts, lysc_ext_instance_free); |
| 731 | free(*pattern); |
| 732 | } |
| 733 | |
Michal Vasko | f4fa90d | 2021-11-11 15:05:19 +0100 | [diff] [blame] | 734 | void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 735 | 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] | 736 | { |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 737 | lydict_remove(ctx, item->name); |
| 738 | lydict_remove(ctx, item->dsc); |
| 739 | lydict_remove(ctx, item->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 740 | FREE_ARRAY(ctx, item->exts, lysc_ext_instance_free); |
| 741 | } |
| 742 | |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 743 | static void |
| 744 | lysc_type2_free(struct ly_ctx *ctx, struct lysc_type **type) |
| 745 | { |
| 746 | lysc_type_free(ctx, *type); |
| 747 | } |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 748 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 749 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 750 | lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type) |
| 751 | { |
Michal Vasko | d15c7de | 2022-05-09 15:34:09 +0200 | [diff] [blame] | 752 | if (!type || (LY_ATOMIC_DEC_BARRIER(type->refcount) > 1)) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 753 | return; |
| 754 | } |
Radek Krejci | b915ac9 | 2020-08-14 23:31:04 +0200 | [diff] [blame] | 755 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 756 | switch (type->basetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 757 | case LY_TYPE_BINARY: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 758 | FREE_MEMBER(ctx, ((struct lysc_type_bin *)type)->length, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 759 | break; |
| 760 | case LY_TYPE_BITS: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 761 | 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] | 762 | break; |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 763 | case LY_TYPE_DEC64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 764 | FREE_MEMBER(ctx, ((struct lysc_type_dec *)type)->range, lysc_range_free); |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 765 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 766 | case LY_TYPE_STRING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 767 | FREE_MEMBER(ctx, ((struct lysc_type_str *)type)->length, lysc_range_free); |
| 768 | FREE_ARRAY(ctx, ((struct lysc_type_str *)type)->patterns, lysc_pattern_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 769 | break; |
| 770 | case LY_TYPE_ENUM: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 771 | 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] | 772 | break; |
| 773 | case LY_TYPE_INT8: |
| 774 | case LY_TYPE_UINT8: |
| 775 | case LY_TYPE_INT16: |
| 776 | case LY_TYPE_UINT16: |
| 777 | case LY_TYPE_INT32: |
| 778 | case LY_TYPE_UINT32: |
| 779 | case LY_TYPE_INT64: |
| 780 | case LY_TYPE_UINT64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 781 | FREE_MEMBER(ctx, ((struct lysc_type_num *)type)->range, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 782 | break; |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 783 | case LY_TYPE_IDENT: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 784 | LY_ARRAY_FREE(((struct lysc_type_identityref *)type)->bases); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 785 | break; |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 786 | case LY_TYPE_UNION: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 787 | FREE_ARRAY(ctx, ((struct lysc_type_union *)type)->types, lysc_type2_free); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 788 | break; |
| 789 | case LY_TYPE_LEAFREF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 790 | lyxp_expr_free(ctx, ((struct lysc_type_leafref *)type)->path); |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 791 | ly_free_prefix_data(LY_VALUE_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes); |
Michal Vasko | d15c7de | 2022-05-09 15:34:09 +0200 | [diff] [blame] | 792 | lysc_type_free(ctx, ((struct lysc_type_leafref *)type)->realtype); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 793 | break; |
Radek Krejci | 16c0f82 | 2018-11-16 10:46:10 +0100 | [diff] [blame] | 794 | case LY_TYPE_INST: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 795 | case LY_TYPE_BOOL: |
| 796 | case LY_TYPE_EMPTY: |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 797 | case LY_TYPE_UNKNOWN: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 798 | /* nothing to do */ |
| 799 | break; |
| 800 | } |
Michal Vasko | ba99a3e | 2020-08-18 15:50:05 +0200 | [diff] [blame] | 801 | |
| 802 | FREE_ARRAY(ctx, type->exts, lysc_ext_instance_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 803 | free(type); |
| 804 | } |
| 805 | |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 806 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 807 | 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] | 808 | { |
| 809 | struct lysc_node *child, *child_next; |
| 810 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 811 | FREE_ARRAY(ctx, inout->musts, lysc_must_free); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 812 | LY_LIST_FOR_SAFE(inout->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 813 | lysc_node_free_(ctx, child); |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 814 | } |
| 815 | } |
| 816 | |
| 817 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 818 | 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] | 819 | { |
Michal Vasko | 37a0fe6 | 2021-02-03 09:53:04 +0100 | [diff] [blame] | 820 | FREE_ARRAY(ctx, action->when, lysc_when_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 821 | if (action->input.nodetype) { |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 822 | lysc_node_free_(ctx, &action->input.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 823 | } |
| 824 | if (action->output.nodetype) { |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 825 | lysc_node_free_(ctx, &action->output.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 826 | } |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 827 | } |
| 828 | |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 829 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 830 | 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] | 831 | { |
| 832 | struct lysc_node *child, *child_next; |
| 833 | |
Michal Vasko | 37a0fe6 | 2021-02-03 09:53:04 +0100 | [diff] [blame] | 834 | FREE_ARRAY(ctx, notif->when, lysc_when_free); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 835 | FREE_ARRAY(ctx, notif->musts, lysc_must_free); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 836 | LY_LIST_FOR_SAFE(notif->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 837 | lysc_node_free_(ctx, child); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 838 | } |
| 839 | } |
| 840 | |
Radek Krejci | f2de0ed | 2019-05-02 14:13:18 +0200 | [diff] [blame] | 841 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 842 | lysc_node_container_free(struct ly_ctx *ctx, struct lysc_node_container *node) |
| 843 | { |
| 844 | struct lysc_node *child, *child_next; |
| 845 | |
| 846 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 847 | lysc_node_free_(ctx, child); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 848 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 849 | LY_LIST_FOR_SAFE((struct lysc_node *)node->actions, child_next, child) { |
| 850 | lysc_node_free_(ctx, child); |
| 851 | } |
| 852 | LY_LIST_FOR_SAFE((struct lysc_node *)node->notifs, child_next, child) { |
| 853 | lysc_node_free_(ctx, child); |
| 854 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 855 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 856 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | static void |
| 860 | lysc_node_leaf_free(struct ly_ctx *ctx, struct lysc_node_leaf *node) |
| 861 | { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 862 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 863 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 864 | if (node->type) { |
| 865 | lysc_type_free(ctx, node->type); |
| 866 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 867 | lydict_remove(ctx, node->units); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 868 | if (node->dflt) { |
| 869 | node->dflt->realtype->plugin->free(ctx, node->dflt); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 870 | lysc_type_free(ctx, (struct lysc_type *)node->dflt->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 871 | free(node->dflt); |
| 872 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 873 | } |
| 874 | |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 875 | static void |
| 876 | lysc_node_leaflist_free(struct ly_ctx *ctx, struct lysc_node_leaflist *node) |
| 877 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 878 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 879 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 880 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 881 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 882 | if (node->type) { |
| 883 | lysc_type_free(ctx, node->type); |
| 884 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 885 | lydict_remove(ctx, node->units); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 886 | LY_ARRAY_FOR(node->dflts, u) { |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 887 | node->dflts[u]->realtype->plugin->free(ctx, node->dflts[u]); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 888 | lysc_type_free(ctx, (struct lysc_type *)node->dflts[u]->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 889 | free(node->dflts[u]); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 890 | } |
| 891 | LY_ARRAY_FREE(node->dflts); |
| 892 | } |
| 893 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 894 | static void |
| 895 | lysc_node_list_free(struct ly_ctx *ctx, struct lysc_node_list *node) |
| 896 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 897 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 898 | struct lysc_node *child, *child_next; |
| 899 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 900 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 901 | lysc_node_free_(ctx, child); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 902 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 903 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 904 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 905 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 906 | LY_ARRAY_FOR(node->uniques, u) { |
| 907 | LY_ARRAY_FREE(node->uniques[u]); |
| 908 | } |
| 909 | LY_ARRAY_FREE(node->uniques); |
| 910 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 911 | LY_LIST_FOR_SAFE((struct lysc_node *)node->actions, child_next, child) { |
| 912 | lysc_node_free_(ctx, child); |
| 913 | } |
| 914 | LY_LIST_FOR_SAFE((struct lysc_node *)node->notifs, child_next, child) { |
| 915 | lysc_node_free_(ctx, child); |
| 916 | } |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 917 | } |
| 918 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 919 | static void |
| 920 | lysc_node_choice_free(struct ly_ctx *ctx, struct lysc_node_choice *node) |
| 921 | { |
| 922 | struct lysc_node *child, *child_next; |
| 923 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 924 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 925 | LY_LIST_FOR_SAFE((struct lysc_node *)node->cases, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 926 | lysc_node_free_(ctx, child); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 927 | } |
| 928 | } |
| 929 | |
| 930 | static void |
| 931 | lysc_node_case_free(struct ly_ctx *ctx, struct lysc_node_case *node) |
| 932 | { |
| 933 | struct lysc_node *child, *child_next; |
| 934 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 935 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 936 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 937 | lysc_node_free_(ctx, child); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 938 | } |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 939 | } |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 940 | |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 941 | static void |
| 942 | lysc_node_anydata_free(struct ly_ctx *ctx, struct lysc_node_anydata *node) |
| 943 | { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 944 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 945 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 946 | } |
| 947 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 948 | static void |
| 949 | lysc_node_free_(struct ly_ctx *ctx, struct lysc_node *node) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 950 | { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 951 | ly_bool inout = 0; |
| 952 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 953 | /* common part */ |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 954 | lydict_remove(ctx, node->name); |
| 955 | lydict_remove(ctx, node->dsc); |
| 956 | lydict_remove(ctx, node->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 957 | |
| 958 | /* nodetype-specific part */ |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 959 | switch (node->nodetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 960 | case LYS_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 961 | lysc_node_container_free(ctx, (struct lysc_node_container *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 962 | break; |
| 963 | case LYS_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 964 | lysc_node_leaf_free(ctx, (struct lysc_node_leaf *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 965 | break; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 966 | case LYS_LEAFLIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 967 | lysc_node_leaflist_free(ctx, (struct lysc_node_leaflist *)node); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 968 | break; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 969 | case LYS_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 970 | lysc_node_list_free(ctx, (struct lysc_node_list *)node); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 971 | break; |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 972 | case LYS_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 973 | lysc_node_choice_free(ctx, (struct lysc_node_choice *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 974 | break; |
| 975 | case LYS_CASE: |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 976 | lysc_node_case_free(ctx, (struct lysc_node_case *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 977 | break; |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 978 | case LYS_ANYDATA: |
| 979 | case LYS_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 980 | lysc_node_anydata_free(ctx, (struct lysc_node_anydata *)node); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 981 | break; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 982 | case LYS_RPC: |
| 983 | case LYS_ACTION: |
| 984 | lysc_node_action_free(ctx, (struct lysc_node_action *)node); |
| 985 | break; |
| 986 | case LYS_INPUT: |
| 987 | case LYS_OUTPUT: |
| 988 | lysc_node_action_inout_free(ctx, (struct lysc_node_action_inout *)node); |
| 989 | inout = 1; |
| 990 | break; |
| 991 | case LYS_NOTIF: |
| 992 | lysc_node_notif_free(ctx, (struct lysc_node_notif *)node); |
| 993 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 994 | default: |
| 995 | LOGINT(ctx); |
| 996 | } |
| 997 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 998 | FREE_ARRAY(ctx, node->exts, lysc_ext_instance_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 999 | |
| 1000 | if (!inout) { |
| 1001 | free(node); |
| 1002 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1003 | } |
| 1004 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1005 | void |
| 1006 | lysc_node_free(struct ly_ctx *ctx, struct lysc_node *node, ly_bool unlink) |
| 1007 | { |
Michal Vasko | e02e740 | 2021-07-23 08:29:28 +0200 | [diff] [blame] | 1008 | struct lysc_node *next, *iter, **child_p; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1009 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1010 | if (node->nodetype & (LYS_INPUT | LYS_OUTPUT)) { |
Michal Vasko | e02e740 | 2021-07-23 08:29:28 +0200 | [diff] [blame] | 1011 | /* inouts are part of actions and cannot be unlinked/freed separately, we can only free all the children */ |
| 1012 | struct lysc_node_action_inout *inout = (struct lysc_node_action_inout *)node; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1013 | |
Michal Vasko | e02e740 | 2021-07-23 08:29:28 +0200 | [diff] [blame] | 1014 | LY_LIST_FOR_SAFE(inout->child, next, iter) { |
| 1015 | lysc_node_free_(ctx, iter); |
| 1016 | } |
| 1017 | inout->child = NULL; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1018 | return; |
| 1019 | } |
| 1020 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1021 | if (unlink) { |
| 1022 | /* unlink from siblings */ |
| 1023 | if (node->prev->next) { |
| 1024 | node->prev->next = node->next; |
| 1025 | } |
| 1026 | if (node->next) { |
| 1027 | node->next->prev = node->prev; |
| 1028 | } else { |
| 1029 | /* unlinking the last node */ |
| 1030 | if (node->parent) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1031 | if (node->nodetype == LYS_ACTION) { |
| 1032 | iter = (struct lysc_node *)lysc_node_actions(node->parent); |
| 1033 | } else if (node->nodetype == LYS_NOTIF) { |
| 1034 | iter = (struct lysc_node *)lysc_node_notifs(node->parent); |
| 1035 | } else { |
Michal Vasko | 544e58a | 2021-01-28 14:33:41 +0100 | [diff] [blame] | 1036 | iter = (struct lysc_node *)lysc_node_child(node->parent); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1037 | } |
Michal Vasko | 539c4a6 | 2020-11-03 17:21:34 +0100 | [diff] [blame] | 1038 | LY_CHECK_ERR_RET(!iter, LOGINT(ctx), ); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1039 | } else if (node->nodetype == LYS_RPC) { |
| 1040 | iter = (struct lysc_node *)node->module->compiled->rpcs; |
| 1041 | } else if (node->nodetype == LYS_NOTIF) { |
| 1042 | iter = (struct lysc_node *)node->module->compiled->notifs; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1043 | } else { |
| 1044 | iter = node->module->compiled->data; |
| 1045 | } |
| 1046 | /* update the "last" pointer from the first node */ |
| 1047 | iter->prev = node->prev; |
| 1048 | } |
| 1049 | |
| 1050 | /* unlink from parent */ |
| 1051 | if (node->parent) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1052 | if (node->nodetype == LYS_ACTION) { |
| 1053 | child_p = (struct lysc_node **)lysc_node_actions_p(node->parent); |
| 1054 | } else if (node->nodetype == LYS_NOTIF) { |
| 1055 | child_p = (struct lysc_node **)lysc_node_notifs_p(node->parent); |
| 1056 | } else { |
Michal Vasko | 544e58a | 2021-01-28 14:33:41 +0100 | [diff] [blame] | 1057 | child_p = lysc_node_child_p(node->parent); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1058 | } |
| 1059 | } else if (node->nodetype == LYS_RPC) { |
| 1060 | child_p = (struct lysc_node **)&node->module->compiled->rpcs; |
| 1061 | } else if (node->nodetype == LYS_NOTIF) { |
| 1062 | child_p = (struct lysc_node **)&node->module->compiled->notifs; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1063 | } else { |
| 1064 | child_p = &node->module->compiled->data; |
| 1065 | } |
| 1066 | if (child_p && (*child_p == node)) { |
| 1067 | /* the node is the first child */ |
| 1068 | *child_p = node->next; |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | lysc_node_free_(ctx, node); |
| 1073 | } |
| 1074 | |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 1075 | void |
| 1076 | lysc_module_free(struct lysc_module *module) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1077 | { |
| 1078 | struct ly_ctx *ctx; |
| 1079 | struct lysc_node *node, *node_next; |
| 1080 | |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 1081 | if (!module) { |
| 1082 | return; |
| 1083 | } |
| 1084 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1085 | ctx = module->mod->ctx; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1086 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1087 | LY_LIST_FOR_SAFE(module->data, node_next, node) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1088 | lysc_node_free_(ctx, node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1089 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1090 | LY_LIST_FOR_SAFE((struct lysc_node *)module->rpcs, node_next, node) { |
| 1091 | lysc_node_free_(ctx, node); |
| 1092 | } |
| 1093 | LY_LIST_FOR_SAFE((struct lysc_node *)module->notifs, node_next, node) { |
| 1094 | lysc_node_free_(ctx, node); |
| 1095 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1096 | FREE_ARRAY(ctx, module->exts, lysc_ext_instance_free); |
| 1097 | |
| 1098 | free(module); |
| 1099 | } |
| 1100 | |
| 1101 | void |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 1102 | lys_module_free(struct lys_module *module, ly_bool remove_links) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1103 | { |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 1104 | LY_ARRAY_COUNT_TYPE u; |
| 1105 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1106 | if (!module) { |
| 1107 | return; |
| 1108 | } |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 1109 | |
Michal Vasko | ee75760 | 2021-06-10 14:38:19 +0200 | [diff] [blame] | 1110 | assert(!module->implemented); |
| 1111 | assert(!module->compiled); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1112 | |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 1113 | if (remove_links) { |
| 1114 | /* remove derived identity links */ |
| 1115 | LY_ARRAY_FOR(module->identities, u) { |
| 1116 | lysc_ident_derived_unlink(&module->identities[u]); |
| 1117 | } |
| 1118 | } |
Radek Krejci | 80d281e | 2020-09-14 17:42:54 +0200 | [diff] [blame] | 1119 | FREE_ARRAY(module->ctx, module->identities, lysc_ident_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1120 | lysp_module_free(module->parsed); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1121 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1122 | LY_ARRAY_FREE(module->augmented_by); |
| 1123 | LY_ARRAY_FREE(module->deviated_by); |
| 1124 | |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1125 | lydict_remove(module->ctx, module->name); |
| 1126 | lydict_remove(module->ctx, module->revision); |
| 1127 | lydict_remove(module->ctx, module->ns); |
| 1128 | lydict_remove(module->ctx, module->prefix); |
| 1129 | lydict_remove(module->ctx, module->filepath); |
| 1130 | lydict_remove(module->ctx, module->org); |
| 1131 | lydict_remove(module->ctx, module->contact); |
| 1132 | lydict_remove(module->ctx, module->dsc); |
| 1133 | lydict_remove(module->ctx, module->ref); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1134 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1135 | free(module); |
| 1136 | } |
Michal Vasko | 33ff942 | 2020-07-03 09:50:39 +0200 | [diff] [blame] | 1137 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 1138 | LIBYANG_API_DEF void |
Radek Krejci | 0b01330 | 2021-03-29 15:22:32 +0200 | [diff] [blame] | 1139 | 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] | 1140 | { |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1141 | LY_ARRAY_COUNT_TYPE u; |
| 1142 | |
| 1143 | LY_ARRAY_FOR(substmts, u) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1144 | if (!substmts[u].storage) { |
| 1145 | continue; |
| 1146 | } |
| 1147 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1148 | switch (substmts[u].stmt) { |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1149 | case LY_STMT_ACTION: |
| 1150 | case LY_STMT_ANYDATA: |
| 1151 | case LY_STMT_ANYXML: |
| 1152 | case LY_STMT_CONTAINER: |
| 1153 | case LY_STMT_CHOICE: |
| 1154 | case LY_STMT_LEAF: |
| 1155 | case LY_STMT_LEAF_LIST: |
| 1156 | case LY_STMT_LIST: |
| 1157 | case LY_STMT_NOTIFICATION: |
| 1158 | case LY_STMT_RPC: |
| 1159 | case LY_STMT_USES: { |
| 1160 | struct lysc_node *child, *child_next; |
| 1161 | |
| 1162 | LY_LIST_FOR_SAFE(*((struct lysc_node **)substmts[u].storage), child_next, child) { |
| 1163 | lysc_node_free_(ctx, child); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1164 | } |
| 1165 | break; |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1166 | } |
| 1167 | case LY_STMT_CONFIG: |
| 1168 | case LY_STMT_STATUS: |
| 1169 | /* nothing to do */ |
| 1170 | break; |
Michal Vasko | 3ac60e5 | 2022-09-05 11:08:31 +0200 | [diff] [blame] | 1171 | case LY_STMT_CONTACT: |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1172 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 3ac60e5 | 2022-09-05 11:08:31 +0200 | [diff] [blame] | 1173 | case LY_STMT_ERROR_APP_TAG: |
| 1174 | case LY_STMT_ERROR_MESSAGE: |
| 1175 | case LY_STMT_KEY: |
| 1176 | case LY_STMT_NAMESPACE: |
| 1177 | case LY_STMT_ORGANIZATION: |
| 1178 | case LY_STMT_PRESENCE: |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1179 | case LY_STMT_REFERENCE: |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1180 | case LY_STMT_UNITS: |
| 1181 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1182 | /* single item */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1183 | const char *str = *((const char **)substmts[u].storage); |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1184 | |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1185 | if (!str) { |
| 1186 | break; |
| 1187 | } |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1188 | lydict_remove(ctx, str); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1189 | } else { |
| 1190 | /* multiple items */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1191 | const char **strs = *((const char ***)substmts[u].storage); |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1192 | |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1193 | if (!strs) { |
| 1194 | break; |
| 1195 | } |
| 1196 | FREE_STRINGS(ctx, strs); |
| 1197 | } |
| 1198 | break; |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1199 | case LY_STMT_IF_FEATURE: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1200 | struct lysc_iffeature *iff = *((struct lysc_iffeature **)substmts[u].storage); |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1201 | |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1202 | if (!iff) { |
| 1203 | break; |
| 1204 | } |
| 1205 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1206 | /* single item */ |
| 1207 | lysc_iffeature_free(ctx, iff); |
| 1208 | free(iff); |
| 1209 | } else { |
| 1210 | /* multiple items */ |
| 1211 | FREE_ARRAY(ctx, iff, lysc_iffeature_free); |
| 1212 | } |
| 1213 | break; |
| 1214 | } |
Michal Vasko | f8647fa | 2022-09-05 11:07:54 +0200 | [diff] [blame] | 1215 | case LY_STMT_TYPE: |
| 1216 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1217 | /* single item */ |
| 1218 | struct lysc_type *type = *((struct lysc_type **)substmts[u].storage); |
| 1219 | |
| 1220 | if (!type) { |
| 1221 | break; |
| 1222 | } |
| 1223 | lysc_type_free(ctx, type); |
| 1224 | } else { |
| 1225 | /* multiple items */ |
| 1226 | struct lysc_type **types = *((struct lysc_type ***)substmts[u].storage); |
| 1227 | |
| 1228 | if (!types) { |
| 1229 | break; |
| 1230 | } |
| 1231 | FREE_ARRAY(ctx, types, lysc_type2_free); |
| 1232 | } |
| 1233 | break; |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1234 | |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1235 | /* TODO other statements */ |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1236 | default: |
| 1237 | LOGINT(ctx); |
| 1238 | } |
| 1239 | } |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1240 | |
| 1241 | LY_ARRAY_FREE(substmts); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1242 | } |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1243 | |
| 1244 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1245 | yang_parser_ctx_free(struct lys_yang_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1246 | { |
| 1247 | if (ctx) { |
aPiecek | 8d4e75d | 2021-06-24 14:47:06 +0200 | [diff] [blame] | 1248 | if (ctx->main_ctx == (struct lys_parser_ctx *)ctx) { |
| 1249 | ly_set_erase(&ctx->tpdfs_nodes, NULL); |
| 1250 | ly_set_erase(&ctx->grps_nodes, NULL); |
| 1251 | } |
Michal Vasko | dd6d5a3 | 2022-07-14 13:54:58 +0200 | [diff] [blame] | 1252 | assert(!ctx->tpdfs_nodes.count && !ctx->grps_nodes.count); |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 1253 | ly_set_rm_index(ctx->parsed_mods, ctx->parsed_mods->count - 1, NULL); |
| 1254 | if (!ctx->parsed_mods->count) { |
| 1255 | ly_set_free(ctx->parsed_mods, NULL); |
| 1256 | } |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1257 | free(ctx); |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1262 | yin_parser_ctx_free(struct lys_yin_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1263 | { |
| 1264 | if (ctx) { |
aPiecek | 8d4e75d | 2021-06-24 14:47:06 +0200 | [diff] [blame] | 1265 | if (ctx->main_ctx == (struct lys_parser_ctx *)ctx) { |
| 1266 | ly_set_erase(&ctx->tpdfs_nodes, NULL); |
| 1267 | ly_set_erase(&ctx->grps_nodes, NULL); |
| 1268 | } |
Michal Vasko | dd6d5a3 | 2022-07-14 13:54:58 +0200 | [diff] [blame] | 1269 | assert(!ctx->tpdfs_nodes.count && !ctx->grps_nodes.count); |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 1270 | ly_set_rm_index(ctx->parsed_mods, ctx->parsed_mods->count - 1, NULL); |
| 1271 | if (!ctx->parsed_mods->count) { |
| 1272 | ly_set_free(ctx->parsed_mods, NULL); |
| 1273 | } |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1274 | lyxml_ctx_free(ctx->xmlctx); |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1275 | free(ctx); |
| 1276 | } |
| 1277 | } |