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 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 15 | #include <stdlib.h> |
| 16 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 17 | #include "common.h" |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 18 | #include "compat.h" |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 19 | #include "log.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 20 | #include "plugins_exts.h" |
| 21 | #include "plugins_types.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 22 | #include "tree.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 23 | #include "tree_data.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 24 | #include "tree_schema.h" |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 25 | #include "tree_schema_internal.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 26 | #include "xml.h" |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 27 | #include "xpath.h" |
| 28 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 29 | void lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp); |
Michal Vasko | 5fe75f1 | 2020-03-02 13:52:37 +0100 | [diff] [blame] | 30 | void lysc_extension_free(struct ly_ctx *ctx, struct lysc_ext **ext); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 31 | 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] | 32 | |
| 33 | static void |
| 34 | lysp_stmt_free(struct ly_ctx *ctx, struct lysp_stmt *stmt) |
| 35 | { |
| 36 | struct lysp_stmt *child, *next; |
| 37 | |
| 38 | FREE_STRING(ctx, stmt->stmt); |
| 39 | FREE_STRING(ctx, stmt->arg); |
| 40 | |
| 41 | LY_LIST_FOR_SAFE(stmt->child, next, child) { |
| 42 | lysp_stmt_free(ctx, child); |
| 43 | } |
| 44 | |
| 45 | free(stmt); |
| 46 | } |
| 47 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 48 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 49 | lysp_ext_instance_free(struct ly_ctx *ctx, struct lysp_ext_instance *ext) |
| 50 | { |
| 51 | struct lysp_stmt *stmt, *next; |
| 52 | |
| 53 | FREE_STRING(ctx, ext->name); |
| 54 | FREE_STRING(ctx, ext->argument); |
| 55 | |
| 56 | LY_LIST_FOR_SAFE(ext->child, next, stmt) { |
| 57 | lysp_stmt_free(ctx, stmt); |
| 58 | } |
| 59 | } |
| 60 | |
David Sedlák | 298ff6d | 2019-07-26 14:29:03 +0200 | [diff] [blame] | 61 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 62 | lysp_import_free(struct ly_ctx *ctx, struct lysp_import *import) |
| 63 | { |
| 64 | /* imported module is freed directly from the context's list */ |
| 65 | FREE_STRING(ctx, import->name); |
| 66 | FREE_STRING(ctx, import->prefix); |
| 67 | FREE_STRING(ctx, import->dsc); |
| 68 | FREE_STRING(ctx, import->ref); |
| 69 | FREE_ARRAY(ctx, import->exts, lysp_ext_instance_free); |
| 70 | } |
| 71 | |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame^] | 72 | /** |
| 73 | * @brief Common function to erase include record in main module and submodule. |
| 74 | * |
| 75 | * There is a difference since the main module is expected to have the complete list if the included submodules and |
| 76 | * the parsed submodule is shared with any include in a submodule. Therefore, the referenced submodules in the include |
| 77 | * record are freed only from main module's records. |
| 78 | * |
| 79 | * @param[in] ctx libyang context |
| 80 | * @param[in] include The include record to be erased, the record itself is not freed. |
| 81 | * @param[in] main_module Flag to get know if the include record is placed in main module so also the referenced submodule |
| 82 | * is supposed to be freed. |
| 83 | */ |
| 84 | static void |
| 85 | 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] | 86 | { |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame^] | 87 | if (main_module && include->submodule) { |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 88 | lysp_module_free((struct lysp_module *)include->submodule); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 89 | } |
| 90 | FREE_STRING(ctx, include->name); |
| 91 | FREE_STRING(ctx, include->dsc); |
| 92 | FREE_STRING(ctx, include->ref); |
| 93 | FREE_ARRAY(ctx, include->exts, lysp_ext_instance_free); |
| 94 | } |
| 95 | |
David Sedlák | aa854b0 | 2019-07-22 14:17:10 +0200 | [diff] [blame] | 96 | void |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame^] | 97 | lysp_include_free_submodule(struct ly_ctx *ctx, struct lysp_include *include) |
| 98 | { |
| 99 | return lysp_include_free_(ctx, include, 0); |
| 100 | } |
| 101 | |
| 102 | void |
| 103 | lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include) |
| 104 | { |
| 105 | return lysp_include_free_(ctx, include, 1); |
| 106 | } |
| 107 | |
| 108 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 109 | lysp_revision_free(struct ly_ctx *ctx, struct lysp_revision *rev) |
| 110 | { |
| 111 | FREE_STRING(ctx, rev->dsc); |
| 112 | FREE_STRING(ctx, rev->ref); |
| 113 | FREE_ARRAY(ctx, rev->exts, lysp_ext_instance_free); |
| 114 | } |
| 115 | |
David Sedlák | 986cb41 | 2019-07-04 13:10:11 +0200 | [diff] [blame] | 116 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 117 | lysp_ext_free(struct ly_ctx *ctx, struct lysp_ext *ext) |
| 118 | { |
| 119 | FREE_STRING(ctx, ext->name); |
| 120 | FREE_STRING(ctx, ext->argument); |
| 121 | FREE_STRING(ctx, ext->dsc); |
| 122 | FREE_STRING(ctx, ext->ref); |
| 123 | FREE_ARRAY(ctx, ext->exts, lysp_ext_instance_free); |
Michal Vasko | 5fe75f1 | 2020-03-02 13:52:37 +0100 | [diff] [blame] | 124 | if (ext->compiled) { |
| 125 | lysc_extension_free(ctx, &ext->compiled); |
| 126 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 127 | } |
| 128 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 129 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 130 | lysp_feature_free(struct ly_ctx *ctx, struct lysp_feature *feat) |
| 131 | { |
| 132 | FREE_STRING(ctx, feat->name); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 133 | FREE_ARRAY(ctx, feat->iffeatures, lysp_qname_free); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 134 | FREE_ARRAY(ctx, feat->iffeatures_c, lysc_iffeature_free); |
| 135 | LY_ARRAY_FREE(feat->depfeatures); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 136 | FREE_STRING(ctx, feat->dsc); |
| 137 | FREE_STRING(ctx, feat->ref); |
| 138 | FREE_ARRAY(ctx, feat->exts, lysp_ext_instance_free); |
| 139 | } |
| 140 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 141 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 142 | lysp_ident_free(struct ly_ctx *ctx, struct lysp_ident *ident) |
| 143 | { |
| 144 | FREE_STRING(ctx, ident->name); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 145 | FREE_ARRAY(ctx, ident->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 146 | FREE_STRINGS(ctx, ident->bases); |
| 147 | FREE_STRING(ctx, ident->dsc); |
| 148 | FREE_STRING(ctx, ident->ref); |
| 149 | FREE_ARRAY(ctx, ident->exts, lysp_ext_instance_free); |
| 150 | } |
| 151 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 152 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 153 | lysp_restr_free(struct ly_ctx *ctx, struct lysp_restr *restr) |
| 154 | { |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 155 | FREE_STRING(ctx, restr->arg.str); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 156 | FREE_STRING(ctx, restr->emsg); |
| 157 | FREE_STRING(ctx, restr->eapptag); |
| 158 | FREE_STRING(ctx, restr->dsc); |
| 159 | FREE_STRING(ctx, restr->ref); |
| 160 | FREE_ARRAY(ctx, restr->exts, lysp_ext_instance_free); |
| 161 | } |
| 162 | |
| 163 | static void |
| 164 | lysp_type_enum_free(struct ly_ctx *ctx, struct lysp_type_enum *item) |
| 165 | { |
| 166 | FREE_STRING(ctx, item->name); |
| 167 | FREE_STRING(ctx, item->dsc); |
| 168 | FREE_STRING(ctx, item->ref); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 169 | FREE_ARRAY(ctx, item->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 170 | FREE_ARRAY(ctx, item->exts, lysp_ext_instance_free); |
| 171 | } |
| 172 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 173 | void lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type); |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 174 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 175 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 176 | lysp_type_free(struct ly_ctx *ctx, struct lysp_type *type) |
| 177 | { |
| 178 | FREE_STRING(ctx, type->name); |
| 179 | FREE_MEMBER(ctx, type->range, lysp_restr_free); |
| 180 | FREE_MEMBER(ctx, type->length, lysp_restr_free); |
| 181 | FREE_ARRAY(ctx, type->patterns, lysp_restr_free); |
| 182 | FREE_ARRAY(ctx, type->enums, lysp_type_enum_free); |
| 183 | FREE_ARRAY(ctx, type->bits, lysp_type_enum_free); |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 184 | lyxp_expr_free(ctx, type->path); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 185 | FREE_STRINGS(ctx, type->bases); |
| 186 | FREE_ARRAY(ctx, type->types, lysp_type_free); |
| 187 | FREE_ARRAY(ctx, type->exts, lysp_ext_instance_free); |
| 188 | if (type->compiled) { |
| 189 | lysc_type_free(ctx, type->compiled); |
| 190 | } |
| 191 | } |
| 192 | |
David Sedlák | 04e17b2 | 2019-07-19 15:29:48 +0200 | [diff] [blame] | 193 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 194 | lysp_tpdf_free(struct ly_ctx *ctx, struct lysp_tpdf *tpdf) |
| 195 | { |
| 196 | FREE_STRING(ctx, tpdf->name); |
| 197 | FREE_STRING(ctx, tpdf->units); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 198 | FREE_STRING(ctx, tpdf->dflt.str); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 199 | FREE_STRING(ctx, tpdf->dsc); |
| 200 | FREE_STRING(ctx, tpdf->ref); |
| 201 | FREE_ARRAY(ctx, tpdf->exts, lysp_ext_instance_free); |
| 202 | |
| 203 | lysp_type_free(ctx, &tpdf->type); |
| 204 | |
| 205 | } |
| 206 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 207 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 208 | lysp_action_inout_free(struct ly_ctx *ctx, struct lysp_action_inout *inout) |
| 209 | { |
| 210 | struct lysp_node *node, *next; |
| 211 | |
| 212 | FREE_ARRAY(ctx, inout->musts, lysp_restr_free); |
| 213 | FREE_ARRAY(ctx, inout->typedefs, lysp_tpdf_free); |
| 214 | FREE_ARRAY(ctx, inout->groupings, lysp_grp_free); |
| 215 | LY_LIST_FOR_SAFE(inout->data, next, node) { |
| 216 | lysp_node_free(ctx, node); |
| 217 | } |
| 218 | FREE_ARRAY(ctx, inout->exts, lysp_ext_instance_free); |
| 219 | |
| 220 | } |
| 221 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 222 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 223 | lysp_action_free(struct ly_ctx *ctx, struct lysp_action *action) |
| 224 | { |
| 225 | FREE_STRING(ctx, action->name); |
| 226 | FREE_STRING(ctx, action->dsc); |
| 227 | FREE_STRING(ctx, action->ref); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 228 | FREE_ARRAY(ctx, action->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 229 | FREE_ARRAY(ctx, action->typedefs, lysp_tpdf_free); |
| 230 | FREE_ARRAY(ctx, action->groupings, lysp_grp_free); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 231 | lysp_action_inout_free(ctx, &action->input); |
| 232 | lysp_action_inout_free(ctx, &action->output); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 233 | FREE_ARRAY(ctx, action->exts, lysp_ext_instance_free); |
| 234 | } |
| 235 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 236 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 237 | lysp_notif_free(struct ly_ctx *ctx, struct lysp_notif *notif) |
| 238 | { |
| 239 | struct lysp_node *node, *next; |
| 240 | |
| 241 | FREE_STRING(ctx, notif->name); |
| 242 | FREE_STRING(ctx, notif->dsc); |
| 243 | FREE_STRING(ctx, notif->ref); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 244 | FREE_ARRAY(ctx, notif->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 245 | FREE_ARRAY(ctx, notif->musts, lysp_restr_free); |
| 246 | FREE_ARRAY(ctx, notif->typedefs, lysp_tpdf_free); |
| 247 | FREE_ARRAY(ctx, notif->groupings, lysp_grp_free); |
| 248 | LY_LIST_FOR_SAFE(notif->data, next, node) { |
| 249 | lysp_node_free(ctx, node); |
| 250 | } |
| 251 | FREE_ARRAY(ctx, notif->exts, lysp_ext_instance_free); |
| 252 | } |
| 253 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 254 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 255 | lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp) |
| 256 | { |
| 257 | struct lysp_node *node, *next; |
| 258 | |
| 259 | FREE_STRING(ctx, grp->name); |
| 260 | FREE_STRING(ctx, grp->dsc); |
| 261 | FREE_STRING(ctx, grp->ref); |
| 262 | FREE_ARRAY(ctx, grp->typedefs, lysp_tpdf_free); |
| 263 | FREE_ARRAY(ctx, grp->groupings, lysp_grp_free); |
| 264 | LY_LIST_FOR_SAFE(grp->data, next, node) { |
| 265 | lysp_node_free(ctx, node); |
| 266 | } |
| 267 | FREE_ARRAY(ctx, grp->actions, lysp_action_free); |
| 268 | FREE_ARRAY(ctx, grp->notifs, lysp_notif_free); |
| 269 | FREE_ARRAY(ctx, grp->exts, lysp_ext_instance_free); |
| 270 | } |
| 271 | |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 272 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 273 | lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when) |
| 274 | { |
| 275 | FREE_STRING(ctx, when->cond); |
| 276 | FREE_STRING(ctx, when->dsc); |
| 277 | FREE_STRING(ctx, when->ref); |
| 278 | FREE_ARRAY(ctx, when->exts, lysp_ext_instance_free); |
| 279 | } |
| 280 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 281 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 282 | lysp_augment_free(struct ly_ctx *ctx, struct lysp_augment *augment) |
| 283 | { |
| 284 | struct lysp_node *node, *next; |
| 285 | |
| 286 | FREE_STRING(ctx, augment->nodeid); |
| 287 | FREE_STRING(ctx, augment->dsc); |
| 288 | FREE_STRING(ctx, augment->ref); |
| 289 | FREE_MEMBER(ctx, augment->when, lysp_when_free); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 290 | FREE_ARRAY(ctx, augment->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 291 | LY_LIST_FOR_SAFE(augment->child, next, node) { |
| 292 | lysp_node_free(ctx, node); |
| 293 | } |
| 294 | FREE_ARRAY(ctx, augment->actions, lysp_action_free); |
| 295 | FREE_ARRAY(ctx, augment->notifs, lysp_notif_free); |
| 296 | FREE_ARRAY(ctx, augment->exts, lysp_ext_instance_free); |
| 297 | } |
| 298 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 299 | void |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 300 | lysp_qname_free(struct ly_ctx *ctx, struct lysp_qname *qname) |
| 301 | { |
| 302 | if (qname) { |
| 303 | FREE_STRING(ctx, qname->str); |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 308 | lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d) |
| 309 | { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 310 | struct lysp_deviate_add *add = (struct lysp_deviate_add *)d; |
| 311 | struct lysp_deviate_rpl *rpl = (struct lysp_deviate_rpl *)d; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 312 | |
| 313 | FREE_ARRAY(ctx, d->exts, lysp_ext_instance_free); |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 314 | switch (d->mod) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 315 | case LYS_DEV_NOT_SUPPORTED: |
| 316 | /* nothing to do */ |
| 317 | break; |
| 318 | case LYS_DEV_ADD: |
| 319 | case LYS_DEV_DELETE: /* compatible for dynamically allocated data */ |
| 320 | FREE_STRING(ctx, add->units); |
| 321 | FREE_ARRAY(ctx, add->musts, lysp_restr_free); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 322 | FREE_ARRAY(ctx, add->uniques, lysp_qname_free); |
| 323 | FREE_ARRAY(ctx, add->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 324 | break; |
| 325 | case LYS_DEV_REPLACE: |
| 326 | FREE_MEMBER(ctx, rpl->type, lysp_type_free); |
| 327 | FREE_STRING(ctx, rpl->units); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 328 | lysp_qname_free(ctx, &rpl->dflt); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 329 | break; |
| 330 | default: |
| 331 | LOGINT(ctx); |
| 332 | break; |
| 333 | } |
| 334 | } |
| 335 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 336 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 337 | lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev) |
| 338 | { |
| 339 | struct lysp_deviate *next, *iter; |
| 340 | |
| 341 | FREE_STRING(ctx, dev->nodeid); |
| 342 | FREE_STRING(ctx, dev->dsc); |
| 343 | FREE_STRING(ctx, dev->ref); |
| 344 | LY_LIST_FOR_SAFE(dev->deviates, next, iter) { |
| 345 | lysp_deviate_free(ctx, iter); |
| 346 | free(iter); |
| 347 | } |
| 348 | FREE_ARRAY(ctx, dev->exts, lysp_ext_instance_free); |
| 349 | } |
| 350 | |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 351 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 352 | lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref) |
| 353 | { |
| 354 | FREE_STRING(ctx, ref->nodeid); |
| 355 | FREE_STRING(ctx, ref->dsc); |
| 356 | FREE_STRING(ctx, ref->ref); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 357 | FREE_ARRAY(ctx, ref->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 358 | FREE_ARRAY(ctx, ref->musts, lysp_restr_free); |
| 359 | FREE_STRING(ctx, ref->presence); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 360 | FREE_ARRAY(ctx, ref->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 361 | FREE_ARRAY(ctx, ref->exts, lysp_ext_instance_free); |
| 362 | } |
| 363 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 364 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 365 | lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node) |
| 366 | { |
| 367 | struct lysp_node *child, *next; |
| 368 | |
| 369 | FREE_STRING(ctx, node->name); |
| 370 | FREE_STRING(ctx, node->dsc); |
| 371 | FREE_STRING(ctx, node->ref); |
| 372 | FREE_MEMBER(ctx, node->when, lysp_when_free); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 373 | FREE_ARRAY(ctx, node->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 374 | FREE_ARRAY(ctx, node->exts, lysp_ext_instance_free); |
| 375 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 376 | switch (node->nodetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 377 | case LYS_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 378 | FREE_ARRAY(ctx, ((struct lysp_node_container *)node)->musts, lysp_restr_free); |
| 379 | FREE_STRING(ctx, ((struct lysp_node_container *)node)->presence); |
| 380 | FREE_ARRAY(ctx, ((struct lysp_node_container *)node)->typedefs, lysp_tpdf_free); |
| 381 | FREE_ARRAY(ctx, ((struct lysp_node_container *)node)->groupings, lysp_grp_free); |
| 382 | LY_LIST_FOR_SAFE(((struct lysp_node_container *)node)->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 383 | lysp_node_free(ctx, child); |
| 384 | } |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 385 | FREE_ARRAY(ctx, ((struct lysp_node_container *)node)->actions, lysp_action_free); |
| 386 | FREE_ARRAY(ctx, ((struct lysp_node_container *)node)->notifs, lysp_notif_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 387 | break; |
| 388 | case LYS_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 389 | FREE_ARRAY(ctx, ((struct lysp_node_leaf *)node)->musts, lysp_restr_free); |
| 390 | lysp_type_free(ctx, &((struct lysp_node_leaf *)node)->type); |
| 391 | FREE_STRING(ctx, ((struct lysp_node_leaf *)node)->units); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 392 | FREE_STRING(ctx, ((struct lysp_node_leaf *)node)->dflt.str); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 393 | break; |
| 394 | case LYS_LEAFLIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 395 | FREE_ARRAY(ctx, ((struct lysp_node_leaflist *)node)->musts, lysp_restr_free); |
| 396 | lysp_type_free(ctx, &((struct lysp_node_leaflist *)node)->type); |
| 397 | FREE_STRING(ctx, ((struct lysp_node_leaflist *)node)->units); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 398 | FREE_ARRAY(ctx, ((struct lysp_node_leaflist *)node)->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 399 | break; |
| 400 | case LYS_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 401 | FREE_ARRAY(ctx, ((struct lysp_node_list *)node)->musts, lysp_restr_free); |
| 402 | FREE_STRING(ctx, ((struct lysp_node_list *)node)->key); |
| 403 | FREE_ARRAY(ctx, ((struct lysp_node_list *)node)->typedefs, lysp_tpdf_free); |
| 404 | FREE_ARRAY(ctx, ((struct lysp_node_list *)node)->groupings, lysp_grp_free); |
| 405 | LY_LIST_FOR_SAFE(((struct lysp_node_list *)node)->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 406 | lysp_node_free(ctx, child); |
| 407 | } |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 408 | FREE_ARRAY(ctx, ((struct lysp_node_list *)node)->actions, lysp_action_free); |
| 409 | FREE_ARRAY(ctx, ((struct lysp_node_list *)node)->notifs, lysp_notif_free); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 410 | FREE_ARRAY(ctx, ((struct lysp_node_list *)node)->uniques, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 411 | break; |
| 412 | case LYS_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 413 | LY_LIST_FOR_SAFE(((struct lysp_node_choice *)node)->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 414 | lysp_node_free(ctx, child); |
| 415 | } |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 416 | FREE_STRING(ctx, ((struct lysp_node_choice *)node)->dflt.str); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 417 | break; |
| 418 | case LYS_CASE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 419 | LY_LIST_FOR_SAFE(((struct lysp_node_case *)node)->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 420 | lysp_node_free(ctx, child); |
| 421 | } |
| 422 | break; |
| 423 | case LYS_ANYDATA: |
| 424 | case LYS_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 425 | FREE_ARRAY(ctx, ((struct lysp_node_anydata *)node)->musts, lysp_restr_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 426 | break; |
| 427 | case LYS_USES: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 428 | FREE_ARRAY(ctx, ((struct lysp_node_uses *)node)->refines, lysp_refine_free); |
| 429 | FREE_ARRAY(ctx, ((struct lysp_node_uses *)node)->augments, lysp_augment_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 430 | break; |
| 431 | default: |
| 432 | LOGINT(ctx); |
| 433 | } |
| 434 | |
| 435 | free(node); |
| 436 | } |
| 437 | |
Radek Krejci | 15f10ab | 2020-11-03 14:14:14 +0100 | [diff] [blame] | 438 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 439 | lysp_module_free(struct lysp_module *module) |
| 440 | { |
| 441 | struct ly_ctx *ctx; |
| 442 | struct lysp_node *node, *next; |
| 443 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 444 | if (!module) { |
| 445 | return; |
| 446 | } |
| 447 | ctx = module->mod->ctx; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 448 | |
| 449 | FREE_ARRAY(ctx, module->imports, lysp_import_free); |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame^] | 450 | 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] | 451 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 452 | FREE_ARRAY(ctx, module->revs, lysp_revision_free); |
| 453 | FREE_ARRAY(ctx, module->extensions, lysp_ext_free); |
| 454 | FREE_ARRAY(ctx, module->features, lysp_feature_free); |
| 455 | FREE_ARRAY(ctx, module->identities, lysp_ident_free); |
| 456 | FREE_ARRAY(ctx, module->typedefs, lysp_tpdf_free); |
| 457 | FREE_ARRAY(ctx, module->groupings, lysp_grp_free); |
| 458 | LY_LIST_FOR_SAFE(module->data, next, node) { |
| 459 | lysp_node_free(ctx, node); |
| 460 | } |
| 461 | FREE_ARRAY(ctx, module->augments, lysp_augment_free); |
| 462 | FREE_ARRAY(ctx, module->rpcs, lysp_action_free); |
| 463 | FREE_ARRAY(ctx, module->notifs, lysp_notif_free); |
| 464 | FREE_ARRAY(ctx, module->deviations, lysp_deviation_free); |
| 465 | FREE_ARRAY(ctx, module->exts, lysp_ext_instance_free); |
| 466 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 467 | if (module->is_submod) { |
| 468 | struct lysp_submodule *submod = (struct lysp_submodule *)module; |
| 469 | |
| 470 | FREE_STRING(ctx, submod->name); |
| 471 | FREE_STRING(ctx, submod->filepath); |
| 472 | FREE_STRING(ctx, submod->prefix); |
| 473 | FREE_STRING(ctx, submod->org); |
| 474 | FREE_STRING(ctx, submod->contact); |
| 475 | FREE_STRING(ctx, submod->dsc); |
| 476 | FREE_STRING(ctx, submod->ref); |
| 477 | } |
| 478 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 479 | free(module); |
| 480 | } |
| 481 | |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 482 | void |
Michal Vasko | 6f4cbb6 | 2020-02-28 11:15:47 +0100 | [diff] [blame] | 483 | lysc_extension_free(struct ly_ctx *ctx, struct lysc_ext **ext) |
| 484 | { |
| 485 | if (--(*ext)->refcount) { |
| 486 | return; |
| 487 | } |
| 488 | FREE_STRING(ctx, (*ext)->name); |
| 489 | FREE_STRING(ctx, (*ext)->argument); |
| 490 | FREE_ARRAY(ctx, (*ext)->exts, lysc_ext_instance_free); |
| 491 | free(*ext); |
| 492 | } |
| 493 | |
| 494 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 495 | lysc_ext_instance_free(struct ly_ctx *ctx, struct lysc_ext_instance *ext) |
| 496 | { |
fredgan | ebc5057 | 2019-10-31 15:39:23 +0800 | [diff] [blame] | 497 | if (ext->def && ext->def->plugin && ext->def->plugin->free) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 498 | ext->def->plugin->free(ctx, ext); |
| 499 | } |
Juraj Vijtiuk | 4a19ab0 | 2020-03-03 13:50:14 +0100 | [diff] [blame] | 500 | if (ext->def) { |
| 501 | lysc_extension_free(ctx, &ext->def); |
| 502 | } |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 503 | FREE_STRING(ctx, ext->argument); |
| 504 | FREE_ARRAY(ctx, ext->exts, lysc_ext_instance_free); |
| 505 | } |
| 506 | |
| 507 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 508 | lysc_iffeature_free(struct ly_ctx *UNUSED(ctx), struct lysc_iffeature *iff) |
| 509 | { |
| 510 | LY_ARRAY_FREE(iff->features); |
| 511 | free(iff->expr); |
| 512 | } |
| 513 | |
| 514 | static void |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 515 | lysc_when_free(struct ly_ctx *ctx, struct lysc_when **w) |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 516 | { |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 517 | if (--(*w)->refcount) { |
| 518 | return; |
| 519 | } |
| 520 | lyxp_expr_free(ctx, (*w)->cond); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 521 | lysc_prefixes_free((*w)->prefixes); |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 522 | FREE_STRING(ctx, (*w)->dsc); |
| 523 | FREE_STRING(ctx, (*w)->ref); |
| 524 | FREE_ARRAY(ctx, (*w)->exts, lysc_ext_instance_free); |
| 525 | free(*w); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 526 | } |
| 527 | |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 528 | void |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 529 | lysc_must_free(struct ly_ctx *ctx, struct lysc_must *must) |
| 530 | { |
| 531 | lyxp_expr_free(ctx, must->cond); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 532 | lysc_prefixes_free(must->prefixes); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 533 | FREE_STRING(ctx, must->emsg); |
| 534 | FREE_STRING(ctx, must->eapptag); |
Radek Krejci | c8b3100 | 2019-01-08 10:24:45 +0100 | [diff] [blame] | 535 | FREE_STRING(ctx, must->dsc); |
| 536 | FREE_STRING(ctx, must->ref); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 537 | FREE_ARRAY(ctx, must->exts, lysc_ext_instance_free); |
| 538 | } |
| 539 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 540 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 541 | lysc_ident_free(struct ly_ctx *ctx, struct lysc_ident *ident) |
| 542 | { |
| 543 | FREE_STRING(ctx, ident->name); |
Radek Krejci | c8b3100 | 2019-01-08 10:24:45 +0100 | [diff] [blame] | 544 | FREE_STRING(ctx, ident->dsc); |
| 545 | FREE_STRING(ctx, ident->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 546 | LY_ARRAY_FREE(ident->derived); |
| 547 | FREE_ARRAY(ctx, ident->exts, lysc_ext_instance_free); |
| 548 | } |
| 549 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 550 | static void |
| 551 | lysc_range_free(struct ly_ctx *ctx, struct lysc_range *range) |
| 552 | { |
| 553 | LY_ARRAY_FREE(range->parts); |
| 554 | FREE_STRING(ctx, range->eapptag); |
| 555 | FREE_STRING(ctx, range->emsg); |
Radek Krejci | c8b3100 | 2019-01-08 10:24:45 +0100 | [diff] [blame] | 556 | FREE_STRING(ctx, range->dsc); |
| 557 | FREE_STRING(ctx, range->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 558 | FREE_ARRAY(ctx, range->exts, lysc_ext_instance_free); |
| 559 | } |
| 560 | |
| 561 | static void |
| 562 | lysc_pattern_free(struct ly_ctx *ctx, struct lysc_pattern **pattern) |
| 563 | { |
| 564 | if (--(*pattern)->refcount) { |
| 565 | return; |
| 566 | } |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 567 | pcre2_code_free((*pattern)->code); |
| 568 | FREE_STRING(ctx, (*pattern)->expr); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 569 | FREE_STRING(ctx, (*pattern)->eapptag); |
| 570 | FREE_STRING(ctx, (*pattern)->emsg); |
Radek Krejci | c8b3100 | 2019-01-08 10:24:45 +0100 | [diff] [blame] | 571 | FREE_STRING(ctx, (*pattern)->dsc); |
| 572 | FREE_STRING(ctx, (*pattern)->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 573 | FREE_ARRAY(ctx, (*pattern)->exts, lysc_ext_instance_free); |
| 574 | free(*pattern); |
| 575 | } |
| 576 | |
| 577 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 578 | 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] | 579 | { |
| 580 | FREE_STRING(ctx, item->name); |
Radek Krejci | c8b3100 | 2019-01-08 10:24:45 +0100 | [diff] [blame] | 581 | FREE_STRING(ctx, item->dsc); |
| 582 | FREE_STRING(ctx, item->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 583 | FREE_ARRAY(ctx, item->exts, lysc_ext_instance_free); |
| 584 | } |
| 585 | |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 586 | static void |
| 587 | lysc_type2_free(struct ly_ctx *ctx, struct lysc_type **type) |
| 588 | { |
| 589 | lysc_type_free(ctx, *type); |
| 590 | } |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 591 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 592 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 593 | lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type) |
| 594 | { |
| 595 | if (--type->refcount) { |
| 596 | return; |
| 597 | } |
Radek Krejci | b915ac9 | 2020-08-14 23:31:04 +0200 | [diff] [blame] | 598 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 599 | switch (type->basetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 600 | case LY_TYPE_BINARY: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 601 | FREE_MEMBER(ctx, ((struct lysc_type_bin *)type)->length, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 602 | break; |
| 603 | case LY_TYPE_BITS: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 604 | 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] | 605 | break; |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 606 | case LY_TYPE_DEC64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 607 | FREE_MEMBER(ctx, ((struct lysc_type_dec *)type)->range, lysc_range_free); |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 608 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 609 | case LY_TYPE_STRING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 610 | FREE_MEMBER(ctx, ((struct lysc_type_str *)type)->length, lysc_range_free); |
| 611 | FREE_ARRAY(ctx, ((struct lysc_type_str *)type)->patterns, lysc_pattern_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 612 | break; |
| 613 | case LY_TYPE_ENUM: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 614 | 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] | 615 | break; |
| 616 | case LY_TYPE_INT8: |
| 617 | case LY_TYPE_UINT8: |
| 618 | case LY_TYPE_INT16: |
| 619 | case LY_TYPE_UINT16: |
| 620 | case LY_TYPE_INT32: |
| 621 | case LY_TYPE_UINT32: |
| 622 | case LY_TYPE_INT64: |
| 623 | case LY_TYPE_UINT64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 624 | FREE_MEMBER(ctx, ((struct lysc_type_num *)type)->range, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 625 | break; |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 626 | case LY_TYPE_IDENT: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 627 | LY_ARRAY_FREE(((struct lysc_type_identityref *)type)->bases); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 628 | break; |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 629 | case LY_TYPE_UNION: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 630 | FREE_ARRAY(ctx, ((struct lysc_type_union *)type)->types, lysc_type2_free); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 631 | break; |
| 632 | case LY_TYPE_LEAFREF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 633 | lyxp_expr_free(ctx, ((struct lysc_type_leafref *)type)->path); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 634 | lysc_prefixes_free(((struct lysc_type_leafref *)type)->prefixes); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 635 | break; |
Radek Krejci | 16c0f82 | 2018-11-16 10:46:10 +0100 | [diff] [blame] | 636 | case LY_TYPE_INST: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 637 | case LY_TYPE_BOOL: |
| 638 | case LY_TYPE_EMPTY: |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 639 | case LY_TYPE_UNKNOWN: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 640 | /* nothing to do */ |
| 641 | break; |
| 642 | } |
Michal Vasko | ba99a3e | 2020-08-18 15:50:05 +0200 | [diff] [blame] | 643 | |
| 644 | FREE_ARRAY(ctx, type->exts, lysc_ext_instance_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 645 | free(type); |
| 646 | } |
| 647 | |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 648 | void |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 649 | lysc_action_inout_free(struct ly_ctx *ctx, struct lysc_action_inout *inout) |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 650 | { |
| 651 | struct lysc_node *child, *child_next; |
| 652 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 653 | FREE_ARRAY(ctx, inout->musts, lysc_must_free); |
| 654 | LY_LIST_FOR_SAFE(inout->data, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 655 | lysc_node_free_(ctx, child); |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 656 | } |
| 657 | } |
| 658 | |
| 659 | void |
| 660 | lysc_action_free(struct ly_ctx *ctx, struct lysc_action *action) |
| 661 | { |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 662 | FREE_STRING(ctx, action->name); |
| 663 | FREE_STRING(ctx, action->dsc); |
| 664 | FREE_STRING(ctx, action->ref); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 665 | FREE_ARRAY(ctx, action->exts, lysc_ext_instance_free); |
Michal Vasko | ceab6dd | 2020-10-09 16:53:36 +0200 | [diff] [blame] | 666 | FREE_ARRAY(ctx, action->when, lysc_when_free); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 667 | FREE_ARRAY(ctx, action->input_exts, lysc_ext_instance_free); |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 668 | lysc_action_inout_free(ctx, &action->input); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 669 | FREE_ARRAY(ctx, action->output_exts, lysc_ext_instance_free); |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 670 | lysc_action_inout_free(ctx, &action->output); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 671 | } |
| 672 | |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 673 | void |
| 674 | lysc_notif_free(struct ly_ctx *ctx, struct lysc_notif *notif) |
| 675 | { |
| 676 | struct lysc_node *child, *child_next; |
| 677 | |
| 678 | FREE_STRING(ctx, notif->name); |
| 679 | FREE_STRING(ctx, notif->dsc); |
| 680 | FREE_STRING(ctx, notif->ref); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 681 | FREE_ARRAY(ctx, notif->exts, lysc_ext_instance_free); |
Michal Vasko | ceab6dd | 2020-10-09 16:53:36 +0200 | [diff] [blame] | 682 | FREE_ARRAY(ctx, notif->when, lysc_when_free); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 683 | FREE_ARRAY(ctx, notif->musts, lysc_must_free); |
| 684 | LY_LIST_FOR_SAFE(notif->data, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 685 | lysc_node_free_(ctx, child); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 686 | } |
| 687 | } |
| 688 | |
Radek Krejci | f2de0ed | 2019-05-02 14:13:18 +0200 | [diff] [blame] | 689 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 690 | lysc_node_container_free(struct ly_ctx *ctx, struct lysc_node_container *node) |
| 691 | { |
| 692 | struct lysc_node *child, *child_next; |
| 693 | |
| 694 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 695 | lysc_node_free_(ctx, child); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 696 | } |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 697 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 698 | FREE_ARRAY(ctx, node->actions, lysc_action_free); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 699 | FREE_ARRAY(ctx, node->notifs, lysc_notif_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 700 | } |
| 701 | |
| 702 | static void |
| 703 | lysc_node_leaf_free(struct ly_ctx *ctx, struct lysc_node_leaf *node) |
| 704 | { |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 705 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 706 | if (node->type) { |
| 707 | lysc_type_free(ctx, node->type); |
| 708 | } |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 709 | FREE_STRING(ctx, node->units); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 710 | if (node->dflt) { |
| 711 | node->dflt->realtype->plugin->free(ctx, node->dflt); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 712 | lysc_type_free(ctx, (struct lysc_type *)node->dflt->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 713 | free(node->dflt); |
| 714 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 715 | } |
| 716 | |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 717 | static void |
| 718 | lysc_node_leaflist_free(struct ly_ctx *ctx, struct lysc_node_leaflist *node) |
| 719 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 720 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 721 | |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 722 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 723 | if (node->type) { |
| 724 | lysc_type_free(ctx, node->type); |
| 725 | } |
| 726 | FREE_STRING(ctx, node->units); |
| 727 | LY_ARRAY_FOR(node->dflts, u) { |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 728 | node->dflts[u]->realtype->plugin->free(ctx, node->dflts[u]); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 729 | lysc_type_free(ctx, (struct lysc_type *)node->dflts[u]->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 730 | free(node->dflts[u]); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 731 | } |
| 732 | LY_ARRAY_FREE(node->dflts); |
| 733 | } |
| 734 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 735 | static void |
| 736 | lysc_node_list_free(struct ly_ctx *ctx, struct lysc_node_list *node) |
| 737 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 738 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 739 | struct lysc_node *child, *child_next; |
| 740 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 741 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 742 | lysc_node_free_(ctx, child); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 743 | } |
| 744 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 745 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 746 | LY_ARRAY_FOR(node->uniques, u) { |
| 747 | LY_ARRAY_FREE(node->uniques[u]); |
| 748 | } |
| 749 | LY_ARRAY_FREE(node->uniques); |
| 750 | |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 751 | FREE_ARRAY(ctx, node->actions, lysc_action_free); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 752 | FREE_ARRAY(ctx, node->notifs, lysc_notif_free); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 753 | } |
| 754 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 755 | static void |
| 756 | lysc_node_choice_free(struct ly_ctx *ctx, struct lysc_node_choice *node) |
| 757 | { |
| 758 | struct lysc_node *child, *child_next; |
| 759 | |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 760 | LY_LIST_FOR_SAFE((struct lysc_node *)node->cases, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 761 | lysc_node_free_(ctx, child); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | |
| 765 | static void |
| 766 | lysc_node_case_free(struct ly_ctx *ctx, struct lysc_node_case *node) |
| 767 | { |
| 768 | struct lysc_node *child, *child_next; |
| 769 | |
| 770 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 771 | lysc_node_free_(ctx, child); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 772 | } |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 773 | } |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 774 | |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 775 | static void |
| 776 | lysc_node_anydata_free(struct ly_ctx *ctx, struct lysc_node_anydata *node) |
| 777 | { |
| 778 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 779 | } |
| 780 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 781 | static void |
| 782 | lysc_node_free_(struct ly_ctx *ctx, struct lysc_node *node) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 783 | { |
| 784 | /* common part */ |
| 785 | FREE_STRING(ctx, node->name); |
Radek Krejci | 12fb914 | 2019-01-08 09:45:30 +0100 | [diff] [blame] | 786 | FREE_STRING(ctx, node->dsc); |
| 787 | FREE_STRING(ctx, node->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 788 | |
| 789 | /* nodetype-specific part */ |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 790 | switch (node->nodetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 791 | case LYS_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 792 | lysc_node_container_free(ctx, (struct lysc_node_container *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 793 | break; |
| 794 | case LYS_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 795 | lysc_node_leaf_free(ctx, (struct lysc_node_leaf *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 796 | break; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 797 | case LYS_LEAFLIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 798 | lysc_node_leaflist_free(ctx, (struct lysc_node_leaflist *)node); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 799 | break; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 800 | case LYS_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 801 | lysc_node_list_free(ctx, (struct lysc_node_list *)node); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 802 | break; |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 803 | case LYS_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 804 | lysc_node_choice_free(ctx, (struct lysc_node_choice *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 805 | break; |
| 806 | case LYS_CASE: |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 807 | lysc_node_case_free(ctx, (struct lysc_node_case *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 808 | break; |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 809 | case LYS_ANYDATA: |
| 810 | case LYS_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 811 | lysc_node_anydata_free(ctx, (struct lysc_node_anydata *)node); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 812 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 813 | default: |
| 814 | LOGINT(ctx); |
| 815 | } |
| 816 | |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 817 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 818 | FREE_ARRAY(ctx, node->exts, lysc_ext_instance_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 819 | free(node); |
| 820 | } |
| 821 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 822 | void |
| 823 | lysc_node_free(struct ly_ctx *ctx, struct lysc_node *node, ly_bool unlink) |
| 824 | { |
| 825 | struct lysc_node *iter, **child_p; |
| 826 | |
| 827 | if (unlink) { |
| 828 | /* unlink from siblings */ |
| 829 | if (node->prev->next) { |
| 830 | node->prev->next = node->next; |
| 831 | } |
| 832 | if (node->next) { |
| 833 | node->next->prev = node->prev; |
| 834 | } else { |
| 835 | /* unlinking the last node */ |
| 836 | if (node->parent) { |
| 837 | iter = (struct lysc_node *)lysc_node_children(node->parent, node->flags & LYS_CONFIG_MASK); |
Michal Vasko | 539c4a6 | 2020-11-03 17:21:34 +0100 | [diff] [blame] | 838 | LY_CHECK_ERR_RET(!iter, LOGINT(ctx), ); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 839 | } else { |
| 840 | iter = node->module->compiled->data; |
| 841 | } |
| 842 | /* update the "last" pointer from the first node */ |
| 843 | iter->prev = node->prev; |
| 844 | } |
| 845 | |
| 846 | /* unlink from parent */ |
| 847 | if (node->parent) { |
| 848 | child_p = lysc_node_children_p(node->parent, node->flags & LYS_CONFIG_MASK); |
| 849 | } else { |
| 850 | child_p = &node->module->compiled->data; |
| 851 | } |
| 852 | if (child_p && (*child_p == node)) { |
| 853 | /* the node is the first child */ |
| 854 | *child_p = node->next; |
| 855 | } |
| 856 | } |
| 857 | |
| 858 | lysc_node_free_(ctx, node); |
| 859 | } |
| 860 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 861 | static void |
| 862 | lysc_module_free_(struct lysc_module *module) |
| 863 | { |
| 864 | struct ly_ctx *ctx; |
| 865 | struct lysc_node *node, *node_next; |
| 866 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 867 | LY_CHECK_ARG_RET(NULL, module, ); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 868 | ctx = module->mod->ctx; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 869 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 870 | LY_LIST_FOR_SAFE(module->data, node_next, node) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 871 | lysc_node_free_(ctx, node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 872 | } |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 873 | FREE_ARRAY(ctx, module->rpcs, lysc_action_free); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 874 | FREE_ARRAY(ctx, module->notifs, lysc_notif_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 875 | FREE_ARRAY(ctx, module->exts, lysc_ext_instance_free); |
| 876 | |
| 877 | free(module); |
| 878 | } |
| 879 | |
| 880 | void |
| 881 | lysc_module_free(struct lysc_module *module, void (*private_destructor)(const struct lysc_node *node, void *priv)) |
| 882 | { |
Radek Krejci | 9b04289 | 2019-02-13 14:28:44 +0100 | [diff] [blame] | 883 | /* TODO use the destructor, this just suppress warning about unused parameter */ |
| 884 | (void) private_destructor; |
| 885 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 886 | if (module) { |
| 887 | lysc_module_free_(module); |
| 888 | } |
| 889 | } |
| 890 | |
| 891 | void |
| 892 | lys_module_free(struct lys_module *module, void (*private_destructor)(const struct lysc_node *node, void *priv)) |
| 893 | { |
| 894 | if (!module) { |
| 895 | return; |
| 896 | } |
| 897 | |
| 898 | lysc_module_free(module->compiled, private_destructor); |
Radek Krejci | 80d281e | 2020-09-14 17:42:54 +0200 | [diff] [blame] | 899 | FREE_ARRAY(module->ctx, module->identities, lysc_ident_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 900 | lysp_module_free(module->parsed); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 901 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 902 | LY_ARRAY_FREE(module->augmented_by); |
| 903 | LY_ARRAY_FREE(module->deviated_by); |
| 904 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 905 | FREE_STRING(module->ctx, module->name); |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 906 | FREE_STRING(module->ctx, module->revision); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 907 | FREE_STRING(module->ctx, module->ns); |
| 908 | FREE_STRING(module->ctx, module->prefix); |
| 909 | FREE_STRING(module->ctx, module->filepath); |
| 910 | FREE_STRING(module->ctx, module->org); |
| 911 | FREE_STRING(module->ctx, module->contact); |
| 912 | FREE_STRING(module->ctx, module->dsc); |
| 913 | FREE_STRING(module->ctx, module->ref); |
| 914 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 915 | free(module); |
| 916 | } |
Michal Vasko | 33ff942 | 2020-07-03 09:50:39 +0200 | [diff] [blame] | 917 | |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 918 | API void |
| 919 | lysc_extension_instance_free(struct ly_ctx *ctx, struct lysc_ext_substmt *substmts) |
| 920 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 921 | for (LY_ARRAY_COUNT_TYPE u = 0; substmts[u].stmt; ++u) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 922 | if (!substmts[u].storage) { |
| 923 | continue; |
| 924 | } |
| 925 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 926 | switch (substmts[u].stmt) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 927 | case LY_STMT_TYPE: |
| 928 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 929 | /* single item */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 930 | struct lysc_type *type = *((struct lysc_type **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 931 | if (!type) { |
| 932 | break; |
| 933 | } |
| 934 | lysc_type_free(ctx, type); |
| 935 | } else { |
| 936 | /* multiple items */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 937 | struct lysc_type **types = *((struct lysc_type ***)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 938 | if (!types) { |
| 939 | break; |
| 940 | } |
| 941 | FREE_ARRAY(ctx, types, lysc_type2_free); |
| 942 | } |
| 943 | break; |
| 944 | case LY_STMT_UNITS: |
| 945 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 946 | /* single item */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 947 | const char *str = *((const char **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 948 | if (!str) { |
| 949 | break; |
| 950 | } |
| 951 | FREE_STRING(ctx, str); |
| 952 | } else { |
| 953 | /* multiple items */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 954 | const char **strs = *((const char ***)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 955 | if (!strs) { |
| 956 | break; |
| 957 | } |
| 958 | FREE_STRINGS(ctx, strs); |
| 959 | } |
| 960 | break; |
| 961 | case LY_STMT_STATUS: |
Radek Krejci | ad5963b | 2019-09-06 16:03:05 +0200 | [diff] [blame] | 962 | case LY_STMT_CONFIG: |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 963 | /* nothing to do */ |
| 964 | break; |
| 965 | case LY_STMT_IF_FEATURE: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 966 | struct lysc_iffeature *iff = *((struct lysc_iffeature **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 967 | if (!iff) { |
| 968 | break; |
| 969 | } |
| 970 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 971 | /* single item */ |
| 972 | lysc_iffeature_free(ctx, iff); |
| 973 | free(iff); |
| 974 | } else { |
| 975 | /* multiple items */ |
| 976 | FREE_ARRAY(ctx, iff, lysc_iffeature_free); |
| 977 | } |
| 978 | break; |
| 979 | } |
| 980 | |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 981 | /* TODO other statements */ |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 982 | default: |
| 983 | LOGINT(ctx); |
| 984 | } |
| 985 | } |
| 986 | } |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 987 | |
| 988 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 989 | yang_parser_ctx_free(struct lys_yang_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 990 | { |
| 991 | if (ctx) { |
| 992 | free(ctx); |
| 993 | } |
| 994 | } |
| 995 | |
| 996 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 997 | yin_parser_ctx_free(struct lys_yin_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 998 | { |
| 999 | if (ctx) { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1000 | lyxml_ctx_free(ctx->xmlctx); |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1001 | free(ctx); |
| 1002 | } |
| 1003 | } |