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