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 | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 29 | void lysp_grp_free(struct ly_ctx *ctx, struct lysp_node_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 | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 208 | lysp_grp_free(struct ly_ctx *ctx, struct lysp_node_grp *grp) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 209 | { |
| 210 | struct lysp_node *node, *next; |
| 211 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 212 | FREE_ARRAY(ctx, grp->typedefs, lysp_tpdf_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 213 | LY_LIST_FOR_SAFE((struct lysp_node *)grp->groupings, next, node) { |
| 214 | lysp_node_free(ctx, node); |
| 215 | } |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 216 | LY_LIST_FOR_SAFE(grp->child, next, node) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 217 | lysp_node_free(ctx, node); |
| 218 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 219 | LY_LIST_FOR_SAFE((struct lysp_node *)grp->actions, next, node) { |
| 220 | lysp_node_free(ctx, node); |
| 221 | } |
| 222 | LY_LIST_FOR_SAFE((struct lysp_node *)grp->notifs, next, node) { |
| 223 | lysp_node_free(ctx, node); |
| 224 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 225 | } |
| 226 | |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 227 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 228 | lysp_when_free(struct ly_ctx *ctx, struct lysp_when *when) |
| 229 | { |
| 230 | FREE_STRING(ctx, when->cond); |
| 231 | FREE_STRING(ctx, when->dsc); |
| 232 | FREE_STRING(ctx, when->ref); |
| 233 | FREE_ARRAY(ctx, when->exts, lysp_ext_instance_free); |
| 234 | } |
| 235 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 236 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 237 | lysp_augment_free(struct ly_ctx *ctx, struct lysp_node_augment *augment) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 238 | { |
| 239 | struct lysp_node *node, *next; |
| 240 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 241 | LY_LIST_FOR_SAFE(augment->child, next, node) { |
| 242 | lysp_node_free(ctx, node); |
| 243 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 244 | LY_LIST_FOR_SAFE((struct lysp_node *)augment->actions, next, node) { |
| 245 | lysp_node_free(ctx, node); |
| 246 | } |
| 247 | LY_LIST_FOR_SAFE((struct lysp_node *)augment->notifs, next, node) { |
| 248 | lysp_node_free(ctx, node); |
| 249 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 250 | } |
| 251 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 252 | void |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 253 | lysp_qname_free(struct ly_ctx *ctx, struct lysp_qname *qname) |
| 254 | { |
| 255 | if (qname) { |
| 256 | FREE_STRING(ctx, qname->str); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 261 | lysp_deviate_free(struct ly_ctx *ctx, struct lysp_deviate *d) |
| 262 | { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 263 | struct lysp_deviate_add *add = (struct lysp_deviate_add *)d; |
| 264 | struct lysp_deviate_rpl *rpl = (struct lysp_deviate_rpl *)d; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 265 | |
| 266 | FREE_ARRAY(ctx, d->exts, lysp_ext_instance_free); |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 267 | switch (d->mod) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 268 | case LYS_DEV_NOT_SUPPORTED: |
| 269 | /* nothing to do */ |
| 270 | break; |
| 271 | case LYS_DEV_ADD: |
| 272 | case LYS_DEV_DELETE: /* compatible for dynamically allocated data */ |
| 273 | FREE_STRING(ctx, add->units); |
| 274 | FREE_ARRAY(ctx, add->musts, lysp_restr_free); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 275 | FREE_ARRAY(ctx, add->uniques, lysp_qname_free); |
| 276 | FREE_ARRAY(ctx, add->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 277 | break; |
| 278 | case LYS_DEV_REPLACE: |
| 279 | FREE_MEMBER(ctx, rpl->type, lysp_type_free); |
| 280 | FREE_STRING(ctx, rpl->units); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 281 | lysp_qname_free(ctx, &rpl->dflt); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 282 | break; |
| 283 | default: |
| 284 | LOGINT(ctx); |
| 285 | break; |
| 286 | } |
| 287 | } |
| 288 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 289 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 290 | lysp_deviation_free(struct ly_ctx *ctx, struct lysp_deviation *dev) |
| 291 | { |
| 292 | struct lysp_deviate *next, *iter; |
| 293 | |
| 294 | FREE_STRING(ctx, dev->nodeid); |
| 295 | FREE_STRING(ctx, dev->dsc); |
| 296 | FREE_STRING(ctx, dev->ref); |
| 297 | LY_LIST_FOR_SAFE(dev->deviates, next, iter) { |
| 298 | lysp_deviate_free(ctx, iter); |
| 299 | free(iter); |
| 300 | } |
| 301 | FREE_ARRAY(ctx, dev->exts, lysp_ext_instance_free); |
| 302 | } |
| 303 | |
David Sedlák | d2d676a | 2019-07-22 11:28:19 +0200 | [diff] [blame] | 304 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 305 | lysp_refine_free(struct ly_ctx *ctx, struct lysp_refine *ref) |
| 306 | { |
| 307 | FREE_STRING(ctx, ref->nodeid); |
| 308 | FREE_STRING(ctx, ref->dsc); |
| 309 | FREE_STRING(ctx, ref->ref); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 310 | FREE_ARRAY(ctx, ref->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 311 | FREE_ARRAY(ctx, ref->musts, lysp_restr_free); |
| 312 | FREE_STRING(ctx, ref->presence); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 313 | FREE_ARRAY(ctx, ref->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 314 | FREE_ARRAY(ctx, ref->exts, lysp_ext_instance_free); |
| 315 | } |
| 316 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 317 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 318 | lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node) |
| 319 | { |
| 320 | struct lysp_node *child, *next; |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 321 | struct lysp_restr *musts = lysp_node_musts(node); |
| 322 | struct lysp_when *when = lysp_node_when(node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 323 | |
| 324 | FREE_STRING(ctx, node->name); |
| 325 | FREE_STRING(ctx, node->dsc); |
| 326 | FREE_STRING(ctx, node->ref); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 327 | FREE_ARRAY(ctx, node->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 328 | FREE_ARRAY(ctx, node->exts, lysp_ext_instance_free); |
| 329 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 330 | FREE_MEMBER(ctx, when, lysp_when_free); |
| 331 | FREE_ARRAY(ctx, musts, lysp_restr_free); |
| 332 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 333 | switch (node->nodetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 334 | case LYS_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 335 | FREE_STRING(ctx, ((struct lysp_node_container *)node)->presence); |
| 336 | FREE_ARRAY(ctx, ((struct lysp_node_container *)node)->typedefs, lysp_tpdf_free); |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 337 | LY_LIST_FOR_SAFE(&((struct lysp_node_container *)node)->groupings->node, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 338 | lysp_node_free(ctx, child); |
| 339 | } |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 340 | LY_LIST_FOR_SAFE(((struct lysp_node_container *)node)->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 341 | lysp_node_free(ctx, child); |
| 342 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 343 | LY_LIST_FOR_SAFE(&((struct lysp_node_container *)node)->actions->node, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 344 | lysp_node_free(ctx, child); |
| 345 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 346 | LY_LIST_FOR_SAFE(&((struct lysp_node_container *)node)->notifs->node, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 347 | lysp_node_free(ctx, child); |
| 348 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 349 | break; |
| 350 | case LYS_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 351 | lysp_type_free(ctx, &((struct lysp_node_leaf *)node)->type); |
| 352 | FREE_STRING(ctx, ((struct lysp_node_leaf *)node)->units); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 353 | FREE_STRING(ctx, ((struct lysp_node_leaf *)node)->dflt.str); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 354 | break; |
| 355 | case LYS_LEAFLIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 356 | lysp_type_free(ctx, &((struct lysp_node_leaflist *)node)->type); |
| 357 | FREE_STRING(ctx, ((struct lysp_node_leaflist *)node)->units); |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 358 | FREE_ARRAY(ctx, ((struct lysp_node_leaflist *)node)->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 359 | break; |
| 360 | case LYS_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 361 | FREE_STRING(ctx, ((struct lysp_node_list *)node)->key); |
| 362 | FREE_ARRAY(ctx, ((struct lysp_node_list *)node)->typedefs, lysp_tpdf_free); |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 363 | LY_LIST_FOR_SAFE(&((struct lysp_node_list *)node)->groupings->node, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 364 | lysp_node_free(ctx, child); |
| 365 | } |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 366 | LY_LIST_FOR_SAFE(((struct lysp_node_list *)node)->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 367 | lysp_node_free(ctx, child); |
| 368 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 369 | LY_LIST_FOR_SAFE(&((struct lysp_node_list *)node)->actions->node, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 370 | lysp_node_free(ctx, child); |
| 371 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 372 | LY_LIST_FOR_SAFE(&((struct lysp_node_list *)node)->notifs->node, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 373 | lysp_node_free(ctx, child); |
| 374 | } |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 375 | FREE_ARRAY(ctx, ((struct lysp_node_list *)node)->uniques, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 376 | break; |
| 377 | case LYS_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 378 | LY_LIST_FOR_SAFE(((struct lysp_node_choice *)node)->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 379 | lysp_node_free(ctx, child); |
| 380 | } |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 381 | FREE_STRING(ctx, ((struct lysp_node_choice *)node)->dflt.str); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 382 | break; |
| 383 | case LYS_CASE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 384 | LY_LIST_FOR_SAFE(((struct lysp_node_case *)node)->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 385 | lysp_node_free(ctx, child); |
| 386 | } |
| 387 | break; |
| 388 | case LYS_ANYDATA: |
| 389 | case LYS_ANYXML: |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 390 | /* nothing special to do */ |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 391 | break; |
| 392 | case LYS_USES: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 393 | FREE_ARRAY(ctx, ((struct lysp_node_uses *)node)->refines, lysp_refine_free); |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 394 | LY_LIST_FOR_SAFE(&((struct lysp_node_uses *)node)->augments->node, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 395 | lysp_node_free(ctx, child); |
| 396 | } |
| 397 | break; |
| 398 | case LYS_RPC: |
| 399 | case LYS_ACTION: |
| 400 | FREE_ARRAY(ctx, ((struct lysp_node_action *)node)->typedefs, lysp_tpdf_free); |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 401 | LY_LIST_FOR_SAFE(&((struct lysp_node_action *)node)->groupings->node, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 402 | lysp_node_free(ctx, child); |
| 403 | } |
| 404 | if (((struct lysp_node_action *)node)->input.nodetype) { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 405 | lysp_node_free(ctx, &((struct lysp_node_action *)node)->input.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 406 | } |
| 407 | if (((struct lysp_node_action *)node)->output.nodetype) { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 408 | lysp_node_free(ctx, &((struct lysp_node_action *)node)->output.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 409 | } |
| 410 | break; |
| 411 | case LYS_INPUT: |
| 412 | case LYS_OUTPUT: |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 413 | FREE_ARRAY(ctx, ((struct lysp_node_action_inout *)node)->typedefs, lysp_tpdf_free); |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 414 | LY_LIST_FOR_SAFE(&((struct lysp_node_action_inout *)node)->groupings->node, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 415 | lysp_node_free(ctx, child); |
| 416 | } |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 417 | LY_LIST_FOR_SAFE(((struct lysp_node_action_inout *)node)->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 418 | lysp_node_free(ctx, child); |
| 419 | } |
| 420 | /* do not free the node, it is never standalone but part of the action node */ |
| 421 | return; |
| 422 | case LYS_NOTIF: |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 423 | FREE_ARRAY(ctx, ((struct lysp_node_notif *)node)->typedefs, lysp_tpdf_free); |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 424 | LY_LIST_FOR_SAFE(&((struct lysp_node_notif *)node)->groupings->node, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 425 | lysp_node_free(ctx, child); |
| 426 | } |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 427 | LY_LIST_FOR_SAFE(((struct lysp_node_notif *)node)->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 428 | lysp_node_free(ctx, child); |
| 429 | } |
| 430 | break; |
| 431 | case LYS_GROUPING: |
| 432 | lysp_grp_free(ctx, (struct lysp_node_grp *)node); |
| 433 | break; |
| 434 | case LYS_AUGMENT: |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 435 | lysp_augment_free(ctx, ((struct lysp_node_augment *)node)); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 436 | break; |
| 437 | default: |
| 438 | LOGINT(ctx); |
| 439 | } |
| 440 | |
| 441 | free(node); |
| 442 | } |
| 443 | |
Radek Krejci | 15f10ab | 2020-11-03 14:14:14 +0100 | [diff] [blame] | 444 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 445 | lysp_module_free(struct lysp_module *module) |
| 446 | { |
| 447 | struct ly_ctx *ctx; |
| 448 | struct lysp_node *node, *next; |
| 449 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 450 | if (!module) { |
| 451 | return; |
| 452 | } |
| 453 | ctx = module->mod->ctx; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 454 | |
| 455 | FREE_ARRAY(ctx, module->imports, lysp_import_free); |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 456 | 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] | 457 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 458 | FREE_ARRAY(ctx, module->revs, lysp_revision_free); |
| 459 | FREE_ARRAY(ctx, module->extensions, lysp_ext_free); |
| 460 | FREE_ARRAY(ctx, module->features, lysp_feature_free); |
| 461 | FREE_ARRAY(ctx, module->identities, lysp_ident_free); |
| 462 | FREE_ARRAY(ctx, module->typedefs, lysp_tpdf_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 463 | LY_LIST_FOR_SAFE((struct lysp_node *)module->groupings, next, node) { |
| 464 | lysp_node_free(ctx, node); |
| 465 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 466 | LY_LIST_FOR_SAFE(module->data, next, node) { |
| 467 | lysp_node_free(ctx, node); |
| 468 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 469 | LY_LIST_FOR_SAFE((struct lysp_node *)module->augments, next, node) { |
| 470 | lysp_node_free(ctx, node); |
| 471 | } |
| 472 | LY_LIST_FOR_SAFE((struct lysp_node *)module->rpcs, next, node) { |
| 473 | lysp_node_free(ctx, node); |
| 474 | } |
| 475 | LY_LIST_FOR_SAFE((struct lysp_node *)module->notifs, next, node) { |
| 476 | lysp_node_free(ctx, node); |
| 477 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 478 | FREE_ARRAY(ctx, module->deviations, lysp_deviation_free); |
| 479 | FREE_ARRAY(ctx, module->exts, lysp_ext_instance_free); |
| 480 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 481 | if (module->is_submod) { |
| 482 | struct lysp_submodule *submod = (struct lysp_submodule *)module; |
| 483 | |
| 484 | FREE_STRING(ctx, submod->name); |
| 485 | FREE_STRING(ctx, submod->filepath); |
| 486 | FREE_STRING(ctx, submod->prefix); |
| 487 | FREE_STRING(ctx, submod->org); |
| 488 | FREE_STRING(ctx, submod->contact); |
| 489 | FREE_STRING(ctx, submod->dsc); |
| 490 | FREE_STRING(ctx, submod->ref); |
| 491 | } |
| 492 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 493 | free(module); |
| 494 | } |
| 495 | |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 496 | void |
Michal Vasko | 6f4cbb6 | 2020-02-28 11:15:47 +0100 | [diff] [blame] | 497 | lysc_extension_free(struct ly_ctx *ctx, struct lysc_ext **ext) |
| 498 | { |
| 499 | if (--(*ext)->refcount) { |
| 500 | return; |
| 501 | } |
| 502 | FREE_STRING(ctx, (*ext)->name); |
| 503 | FREE_STRING(ctx, (*ext)->argument); |
| 504 | FREE_ARRAY(ctx, (*ext)->exts, lysc_ext_instance_free); |
| 505 | free(*ext); |
| 506 | } |
| 507 | |
| 508 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 509 | lysc_ext_instance_free(struct ly_ctx *ctx, struct lysc_ext_instance *ext) |
| 510 | { |
fredgan | ebc5057 | 2019-10-31 15:39:23 +0800 | [diff] [blame] | 511 | if (ext->def && ext->def->plugin && ext->def->plugin->free) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 512 | ext->def->plugin->free(ctx, ext); |
| 513 | } |
Juraj Vijtiuk | 4a19ab0 | 2020-03-03 13:50:14 +0100 | [diff] [blame] | 514 | if (ext->def) { |
| 515 | lysc_extension_free(ctx, &ext->def); |
| 516 | } |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 517 | FREE_STRING(ctx, ext->argument); |
| 518 | FREE_ARRAY(ctx, ext->exts, lysc_ext_instance_free); |
| 519 | } |
| 520 | |
| 521 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 522 | lysc_iffeature_free(struct ly_ctx *UNUSED(ctx), struct lysc_iffeature *iff) |
| 523 | { |
| 524 | LY_ARRAY_FREE(iff->features); |
| 525 | free(iff->expr); |
| 526 | } |
| 527 | |
| 528 | static void |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 529 | lysc_when_free(struct ly_ctx *ctx, struct lysc_when **w) |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 530 | { |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 531 | if (--(*w)->refcount) { |
| 532 | return; |
| 533 | } |
| 534 | lyxp_expr_free(ctx, (*w)->cond); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 535 | lysc_prefixes_free((*w)->prefixes); |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 536 | FREE_STRING(ctx, (*w)->dsc); |
| 537 | FREE_STRING(ctx, (*w)->ref); |
| 538 | FREE_ARRAY(ctx, (*w)->exts, lysc_ext_instance_free); |
| 539 | free(*w); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 540 | } |
| 541 | |
Radek Krejci | ccd20f1 | 2019-02-15 14:12:27 +0100 | [diff] [blame] | 542 | void |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 543 | lysc_must_free(struct ly_ctx *ctx, struct lysc_must *must) |
| 544 | { |
| 545 | lyxp_expr_free(ctx, must->cond); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 546 | lysc_prefixes_free(must->prefixes); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 547 | FREE_STRING(ctx, must->emsg); |
| 548 | FREE_STRING(ctx, must->eapptag); |
Radek Krejci | c8b3100 | 2019-01-08 10:24:45 +0100 | [diff] [blame] | 549 | FREE_STRING(ctx, must->dsc); |
| 550 | FREE_STRING(ctx, must->ref); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 551 | FREE_ARRAY(ctx, must->exts, lysc_ext_instance_free); |
| 552 | } |
| 553 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 554 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 555 | lysc_ident_free(struct ly_ctx *ctx, struct lysc_ident *ident) |
| 556 | { |
| 557 | FREE_STRING(ctx, ident->name); |
Radek Krejci | c8b3100 | 2019-01-08 10:24:45 +0100 | [diff] [blame] | 558 | FREE_STRING(ctx, ident->dsc); |
| 559 | FREE_STRING(ctx, ident->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 560 | LY_ARRAY_FREE(ident->derived); |
| 561 | FREE_ARRAY(ctx, ident->exts, lysc_ext_instance_free); |
| 562 | } |
| 563 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 564 | static void |
| 565 | lysc_range_free(struct ly_ctx *ctx, struct lysc_range *range) |
| 566 | { |
| 567 | LY_ARRAY_FREE(range->parts); |
| 568 | FREE_STRING(ctx, range->eapptag); |
| 569 | FREE_STRING(ctx, range->emsg); |
Radek Krejci | c8b3100 | 2019-01-08 10:24:45 +0100 | [diff] [blame] | 570 | FREE_STRING(ctx, range->dsc); |
| 571 | FREE_STRING(ctx, range->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 572 | FREE_ARRAY(ctx, range->exts, lysc_ext_instance_free); |
| 573 | } |
| 574 | |
| 575 | static void |
| 576 | lysc_pattern_free(struct ly_ctx *ctx, struct lysc_pattern **pattern) |
| 577 | { |
| 578 | if (--(*pattern)->refcount) { |
| 579 | return; |
| 580 | } |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 581 | pcre2_code_free((*pattern)->code); |
| 582 | FREE_STRING(ctx, (*pattern)->expr); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 583 | FREE_STRING(ctx, (*pattern)->eapptag); |
| 584 | FREE_STRING(ctx, (*pattern)->emsg); |
Radek Krejci | c8b3100 | 2019-01-08 10:24:45 +0100 | [diff] [blame] | 585 | FREE_STRING(ctx, (*pattern)->dsc); |
| 586 | FREE_STRING(ctx, (*pattern)->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 587 | FREE_ARRAY(ctx, (*pattern)->exts, lysc_ext_instance_free); |
| 588 | free(*pattern); |
| 589 | } |
| 590 | |
| 591 | static void |
Radek Krejci | 693262f | 2019-04-29 15:23:20 +0200 | [diff] [blame] | 592 | 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] | 593 | { |
| 594 | FREE_STRING(ctx, item->name); |
Radek Krejci | c8b3100 | 2019-01-08 10:24:45 +0100 | [diff] [blame] | 595 | FREE_STRING(ctx, item->dsc); |
| 596 | FREE_STRING(ctx, item->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 597 | FREE_ARRAY(ctx, item->exts, lysc_ext_instance_free); |
| 598 | } |
| 599 | |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 600 | static void |
| 601 | lysc_type2_free(struct ly_ctx *ctx, struct lysc_type **type) |
| 602 | { |
| 603 | lysc_type_free(ctx, *type); |
| 604 | } |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 605 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 606 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 607 | lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type) |
| 608 | { |
| 609 | if (--type->refcount) { |
| 610 | return; |
| 611 | } |
Radek Krejci | b915ac9 | 2020-08-14 23:31:04 +0200 | [diff] [blame] | 612 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 613 | switch (type->basetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 614 | case LY_TYPE_BINARY: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 615 | FREE_MEMBER(ctx, ((struct lysc_type_bin *)type)->length, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 616 | break; |
| 617 | case LY_TYPE_BITS: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 618 | 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] | 619 | break; |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 620 | case LY_TYPE_DEC64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 621 | FREE_MEMBER(ctx, ((struct lysc_type_dec *)type)->range, lysc_range_free); |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 622 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 623 | case LY_TYPE_STRING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 624 | FREE_MEMBER(ctx, ((struct lysc_type_str *)type)->length, lysc_range_free); |
| 625 | FREE_ARRAY(ctx, ((struct lysc_type_str *)type)->patterns, lysc_pattern_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 626 | break; |
| 627 | case LY_TYPE_ENUM: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 628 | 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] | 629 | break; |
| 630 | case LY_TYPE_INT8: |
| 631 | case LY_TYPE_UINT8: |
| 632 | case LY_TYPE_INT16: |
| 633 | case LY_TYPE_UINT16: |
| 634 | case LY_TYPE_INT32: |
| 635 | case LY_TYPE_UINT32: |
| 636 | case LY_TYPE_INT64: |
| 637 | case LY_TYPE_UINT64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 638 | FREE_MEMBER(ctx, ((struct lysc_type_num *)type)->range, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 639 | break; |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 640 | case LY_TYPE_IDENT: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 641 | LY_ARRAY_FREE(((struct lysc_type_identityref *)type)->bases); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 642 | break; |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 643 | case LY_TYPE_UNION: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 644 | FREE_ARRAY(ctx, ((struct lysc_type_union *)type)->types, lysc_type2_free); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 645 | break; |
| 646 | case LY_TYPE_LEAFREF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 647 | lyxp_expr_free(ctx, ((struct lysc_type_leafref *)type)->path); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 648 | lysc_prefixes_free(((struct lysc_type_leafref *)type)->prefixes); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 649 | break; |
Radek Krejci | 16c0f82 | 2018-11-16 10:46:10 +0100 | [diff] [blame] | 650 | case LY_TYPE_INST: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 651 | case LY_TYPE_BOOL: |
| 652 | case LY_TYPE_EMPTY: |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 653 | case LY_TYPE_UNKNOWN: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 654 | /* nothing to do */ |
| 655 | break; |
| 656 | } |
Michal Vasko | ba99a3e | 2020-08-18 15:50:05 +0200 | [diff] [blame] | 657 | |
| 658 | FREE_ARRAY(ctx, type->exts, lysc_ext_instance_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 659 | free(type); |
| 660 | } |
| 661 | |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 662 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 663 | 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] | 664 | { |
| 665 | struct lysc_node *child, *child_next; |
| 666 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 667 | FREE_ARRAY(ctx, inout->musts, lysc_must_free); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 668 | LY_LIST_FOR_SAFE(inout->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 669 | lysc_node_free_(ctx, child); |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | |
| 673 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 674 | 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] | 675 | { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 676 | if (action->input.nodetype) { |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame^] | 677 | lysc_node_free_(ctx, &action->input.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 678 | } |
| 679 | if (action->output.nodetype) { |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame^] | 680 | lysc_node_free_(ctx, &action->output.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 681 | } |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 682 | } |
| 683 | |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 684 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 685 | 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] | 686 | { |
| 687 | struct lysc_node *child, *child_next; |
| 688 | |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 689 | FREE_ARRAY(ctx, notif->musts, lysc_must_free); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 690 | LY_LIST_FOR_SAFE(notif->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 691 | lysc_node_free_(ctx, child); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 692 | } |
| 693 | } |
| 694 | |
Radek Krejci | f2de0ed | 2019-05-02 14:13:18 +0200 | [diff] [blame] | 695 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 696 | lysc_node_container_free(struct ly_ctx *ctx, struct lysc_node_container *node) |
| 697 | { |
| 698 | struct lysc_node *child, *child_next; |
| 699 | |
| 700 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 701 | lysc_node_free_(ctx, child); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 702 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 703 | LY_LIST_FOR_SAFE((struct lysc_node *)node->actions, child_next, child) { |
| 704 | lysc_node_free_(ctx, child); |
| 705 | } |
| 706 | LY_LIST_FOR_SAFE((struct lysc_node *)node->notifs, child_next, child) { |
| 707 | lysc_node_free_(ctx, child); |
| 708 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 709 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 710 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 711 | } |
| 712 | |
| 713 | static void |
| 714 | lysc_node_leaf_free(struct ly_ctx *ctx, struct lysc_node_leaf *node) |
| 715 | { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 716 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 717 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 718 | if (node->type) { |
| 719 | lysc_type_free(ctx, node->type); |
| 720 | } |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 721 | FREE_STRING(ctx, node->units); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 722 | if (node->dflt) { |
| 723 | node->dflt->realtype->plugin->free(ctx, node->dflt); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 724 | lysc_type_free(ctx, (struct lysc_type *)node->dflt->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 725 | free(node->dflt); |
| 726 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 727 | } |
| 728 | |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 729 | static void |
| 730 | lysc_node_leaflist_free(struct ly_ctx *ctx, struct lysc_node_leaflist *node) |
| 731 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 732 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 733 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 734 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 735 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 736 | if (node->type) { |
| 737 | lysc_type_free(ctx, node->type); |
| 738 | } |
| 739 | FREE_STRING(ctx, node->units); |
| 740 | LY_ARRAY_FOR(node->dflts, u) { |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 741 | node->dflts[u]->realtype->plugin->free(ctx, node->dflts[u]); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 742 | lysc_type_free(ctx, (struct lysc_type *)node->dflts[u]->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 743 | free(node->dflts[u]); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 744 | } |
| 745 | LY_ARRAY_FREE(node->dflts); |
| 746 | } |
| 747 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 748 | static void |
| 749 | lysc_node_list_free(struct ly_ctx *ctx, struct lysc_node_list *node) |
| 750 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 751 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 752 | struct lysc_node *child, *child_next; |
| 753 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 754 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 755 | lysc_node_free_(ctx, child); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 756 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 757 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 758 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 759 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 760 | LY_ARRAY_FOR(node->uniques, u) { |
| 761 | LY_ARRAY_FREE(node->uniques[u]); |
| 762 | } |
| 763 | LY_ARRAY_FREE(node->uniques); |
| 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 | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 771 | } |
| 772 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 773 | static void |
| 774 | lysc_node_choice_free(struct ly_ctx *ctx, struct lysc_node_choice *node) |
| 775 | { |
| 776 | struct lysc_node *child, *child_next; |
| 777 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 778 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 779 | LY_LIST_FOR_SAFE((struct lysc_node *)node->cases, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 780 | lysc_node_free_(ctx, child); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | |
| 784 | static void |
| 785 | lysc_node_case_free(struct ly_ctx *ctx, struct lysc_node_case *node) |
| 786 | { |
| 787 | struct lysc_node *child, *child_next; |
| 788 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 789 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 790 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 791 | lysc_node_free_(ctx, child); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 792 | } |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 793 | } |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 794 | |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 795 | static void |
| 796 | lysc_node_anydata_free(struct ly_ctx *ctx, struct lysc_node_anydata *node) |
| 797 | { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 798 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 799 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 800 | } |
| 801 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 802 | static void |
| 803 | lysc_node_free_(struct ly_ctx *ctx, struct lysc_node *node) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 804 | { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 805 | ly_bool inout = 0; |
| 806 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 807 | /* common part */ |
| 808 | FREE_STRING(ctx, node->name); |
Radek Krejci | 12fb914 | 2019-01-08 09:45:30 +0100 | [diff] [blame] | 809 | FREE_STRING(ctx, node->dsc); |
| 810 | FREE_STRING(ctx, node->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 811 | |
| 812 | /* nodetype-specific part */ |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 813 | switch (node->nodetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 814 | case LYS_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 815 | lysc_node_container_free(ctx, (struct lysc_node_container *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 816 | break; |
| 817 | case LYS_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 818 | lysc_node_leaf_free(ctx, (struct lysc_node_leaf *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 819 | break; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 820 | case LYS_LEAFLIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 821 | lysc_node_leaflist_free(ctx, (struct lysc_node_leaflist *)node); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 822 | break; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 823 | case LYS_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 824 | lysc_node_list_free(ctx, (struct lysc_node_list *)node); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 825 | break; |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 826 | case LYS_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 827 | lysc_node_choice_free(ctx, (struct lysc_node_choice *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 828 | break; |
| 829 | case LYS_CASE: |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 830 | lysc_node_case_free(ctx, (struct lysc_node_case *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 831 | break; |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 832 | case LYS_ANYDATA: |
| 833 | case LYS_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 834 | lysc_node_anydata_free(ctx, (struct lysc_node_anydata *)node); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 835 | break; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 836 | case LYS_RPC: |
| 837 | case LYS_ACTION: |
| 838 | lysc_node_action_free(ctx, (struct lysc_node_action *)node); |
| 839 | break; |
| 840 | case LYS_INPUT: |
| 841 | case LYS_OUTPUT: |
| 842 | lysc_node_action_inout_free(ctx, (struct lysc_node_action_inout *)node); |
| 843 | inout = 1; |
| 844 | break; |
| 845 | case LYS_NOTIF: |
| 846 | lysc_node_notif_free(ctx, (struct lysc_node_notif *)node); |
| 847 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 848 | default: |
| 849 | LOGINT(ctx); |
| 850 | } |
| 851 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 852 | FREE_ARRAY(ctx, node->exts, lysc_ext_instance_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 853 | |
| 854 | if (!inout) { |
| 855 | free(node); |
| 856 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 857 | } |
| 858 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 859 | void |
| 860 | lysc_node_free(struct ly_ctx *ctx, struct lysc_node *node, ly_bool unlink) |
| 861 | { |
| 862 | struct lysc_node *iter, **child_p; |
| 863 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 864 | if (node->nodetype & (LYS_INPUT | LYS_OUTPUT)) { |
| 865 | /* nothing to do - inouts are part of actions and cannot be unlinked/freed separately */ |
| 866 | return; |
| 867 | } |
| 868 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 869 | if (unlink) { |
| 870 | /* unlink from siblings */ |
| 871 | if (node->prev->next) { |
| 872 | node->prev->next = node->next; |
| 873 | } |
| 874 | if (node->next) { |
| 875 | node->next->prev = node->prev; |
| 876 | } else { |
| 877 | /* unlinking the last node */ |
| 878 | if (node->parent) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 879 | if (node->nodetype == LYS_ACTION) { |
| 880 | iter = (struct lysc_node *)lysc_node_actions(node->parent); |
| 881 | } else if (node->nodetype == LYS_NOTIF) { |
| 882 | iter = (struct lysc_node *)lysc_node_notifs(node->parent); |
| 883 | } else { |
Michal Vasko | d1e53b9 | 2021-01-28 13:11:06 +0100 | [diff] [blame] | 884 | iter = (struct lysc_node *)lysc_node_children(node->parent, node->flags & LYS_IS_OUTPUT); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 885 | } |
Michal Vasko | 539c4a6 | 2020-11-03 17:21:34 +0100 | [diff] [blame] | 886 | LY_CHECK_ERR_RET(!iter, LOGINT(ctx), ); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 887 | } else if (node->nodetype == LYS_RPC) { |
| 888 | iter = (struct lysc_node *)node->module->compiled->rpcs; |
| 889 | } else if (node->nodetype == LYS_NOTIF) { |
| 890 | iter = (struct lysc_node *)node->module->compiled->notifs; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 891 | } else { |
| 892 | iter = node->module->compiled->data; |
| 893 | } |
| 894 | /* update the "last" pointer from the first node */ |
| 895 | iter->prev = node->prev; |
| 896 | } |
| 897 | |
| 898 | /* unlink from parent */ |
| 899 | if (node->parent) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 900 | if (node->nodetype == LYS_ACTION) { |
| 901 | child_p = (struct lysc_node **)lysc_node_actions_p(node->parent); |
| 902 | } else if (node->nodetype == LYS_NOTIF) { |
| 903 | child_p = (struct lysc_node **)lysc_node_notifs_p(node->parent); |
| 904 | } else { |
Michal Vasko | d1e53b9 | 2021-01-28 13:11:06 +0100 | [diff] [blame] | 905 | child_p = lysc_node_children_p(node->parent, node->flags & LYS_IS_OUTPUT); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 906 | } |
| 907 | } else if (node->nodetype == LYS_RPC) { |
| 908 | child_p = (struct lysc_node **)&node->module->compiled->rpcs; |
| 909 | } else if (node->nodetype == LYS_NOTIF) { |
| 910 | child_p = (struct lysc_node **)&node->module->compiled->notifs; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 911 | } else { |
| 912 | child_p = &node->module->compiled->data; |
| 913 | } |
| 914 | if (child_p && (*child_p == node)) { |
| 915 | /* the node is the first child */ |
| 916 | *child_p = node->next; |
| 917 | } |
| 918 | } |
| 919 | |
| 920 | lysc_node_free_(ctx, node); |
| 921 | } |
| 922 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 923 | static void |
| 924 | lysc_module_free_(struct lysc_module *module) |
| 925 | { |
| 926 | struct ly_ctx *ctx; |
| 927 | struct lysc_node *node, *node_next; |
| 928 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 929 | LY_CHECK_ARG_RET(NULL, module, ); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 930 | ctx = module->mod->ctx; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 931 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 932 | LY_LIST_FOR_SAFE(module->data, node_next, node) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 933 | lysc_node_free_(ctx, node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 934 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 935 | LY_LIST_FOR_SAFE((struct lysc_node *)module->rpcs, node_next, node) { |
| 936 | lysc_node_free_(ctx, node); |
| 937 | } |
| 938 | LY_LIST_FOR_SAFE((struct lysc_node *)module->notifs, node_next, node) { |
| 939 | lysc_node_free_(ctx, node); |
| 940 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 941 | FREE_ARRAY(ctx, module->exts, lysc_ext_instance_free); |
| 942 | |
| 943 | free(module); |
| 944 | } |
| 945 | |
| 946 | void |
| 947 | lysc_module_free(struct lysc_module *module, void (*private_destructor)(const struct lysc_node *node, void *priv)) |
| 948 | { |
Radek Krejci | 9b04289 | 2019-02-13 14:28:44 +0100 | [diff] [blame] | 949 | /* TODO use the destructor, this just suppress warning about unused parameter */ |
| 950 | (void) private_destructor; |
| 951 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 952 | if (module) { |
| 953 | lysc_module_free_(module); |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | void |
| 958 | lys_module_free(struct lys_module *module, void (*private_destructor)(const struct lysc_node *node, void *priv)) |
| 959 | { |
| 960 | if (!module) { |
| 961 | return; |
| 962 | } |
| 963 | |
| 964 | lysc_module_free(module->compiled, private_destructor); |
Radek Krejci | 80d281e | 2020-09-14 17:42:54 +0200 | [diff] [blame] | 965 | FREE_ARRAY(module->ctx, module->identities, lysc_ident_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 966 | lysp_module_free(module->parsed); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 967 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 968 | LY_ARRAY_FREE(module->augmented_by); |
| 969 | LY_ARRAY_FREE(module->deviated_by); |
| 970 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 971 | FREE_STRING(module->ctx, module->name); |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 972 | FREE_STRING(module->ctx, module->revision); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 973 | FREE_STRING(module->ctx, module->ns); |
| 974 | FREE_STRING(module->ctx, module->prefix); |
| 975 | FREE_STRING(module->ctx, module->filepath); |
| 976 | FREE_STRING(module->ctx, module->org); |
| 977 | FREE_STRING(module->ctx, module->contact); |
| 978 | FREE_STRING(module->ctx, module->dsc); |
| 979 | FREE_STRING(module->ctx, module->ref); |
| 980 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 981 | free(module); |
| 982 | } |
Michal Vasko | 33ff942 | 2020-07-03 09:50:39 +0200 | [diff] [blame] | 983 | |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 984 | API void |
| 985 | lysc_extension_instance_free(struct ly_ctx *ctx, struct lysc_ext_substmt *substmts) |
| 986 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 987 | for (LY_ARRAY_COUNT_TYPE u = 0; substmts[u].stmt; ++u) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 988 | if (!substmts[u].storage) { |
| 989 | continue; |
| 990 | } |
| 991 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 992 | switch (substmts[u].stmt) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 993 | case LY_STMT_TYPE: |
| 994 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 995 | /* single item */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 996 | struct lysc_type *type = *((struct lysc_type **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 997 | if (!type) { |
| 998 | break; |
| 999 | } |
| 1000 | lysc_type_free(ctx, type); |
| 1001 | } else { |
| 1002 | /* multiple items */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1003 | struct lysc_type **types = *((struct lysc_type ***)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1004 | if (!types) { |
| 1005 | break; |
| 1006 | } |
| 1007 | FREE_ARRAY(ctx, types, lysc_type2_free); |
| 1008 | } |
| 1009 | break; |
| 1010 | case LY_STMT_UNITS: |
| 1011 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1012 | /* single item */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1013 | const char *str = *((const char **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1014 | if (!str) { |
| 1015 | break; |
| 1016 | } |
| 1017 | FREE_STRING(ctx, str); |
| 1018 | } else { |
| 1019 | /* multiple items */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1020 | const char **strs = *((const char ***)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1021 | if (!strs) { |
| 1022 | break; |
| 1023 | } |
| 1024 | FREE_STRINGS(ctx, strs); |
| 1025 | } |
| 1026 | break; |
| 1027 | case LY_STMT_STATUS: |
Radek Krejci | ad5963b | 2019-09-06 16:03:05 +0200 | [diff] [blame] | 1028 | case LY_STMT_CONFIG: |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1029 | /* nothing to do */ |
| 1030 | break; |
| 1031 | case LY_STMT_IF_FEATURE: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1032 | struct lysc_iffeature *iff = *((struct lysc_iffeature **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1033 | if (!iff) { |
| 1034 | break; |
| 1035 | } |
| 1036 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1037 | /* single item */ |
| 1038 | lysc_iffeature_free(ctx, iff); |
| 1039 | free(iff); |
| 1040 | } else { |
| 1041 | /* multiple items */ |
| 1042 | FREE_ARRAY(ctx, iff, lysc_iffeature_free); |
| 1043 | } |
| 1044 | break; |
| 1045 | } |
| 1046 | |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1047 | /* TODO other statements */ |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1048 | default: |
| 1049 | LOGINT(ctx); |
| 1050 | } |
| 1051 | } |
| 1052 | } |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1053 | |
| 1054 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1055 | yang_parser_ctx_free(struct lys_yang_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1056 | { |
| 1057 | if (ctx) { |
| 1058 | free(ctx); |
| 1059 | } |
| 1060 | } |
| 1061 | |
| 1062 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1063 | yin_parser_ctx_free(struct lys_yin_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1064 | { |
| 1065 | if (ctx) { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1066 | lyxml_ctx_free(ctx->xmlctx); |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1067 | free(ctx); |
| 1068 | } |
| 1069 | } |