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 | { |
Michal Vasko | 37a0fe6 | 2021-02-03 09:53:04 +0100 | [diff] [blame] | 676 | FREE_ARRAY(ctx, action->when, lysc_when_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 677 | if (action->input.nodetype) { |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 678 | lysc_node_free_(ctx, &action->input.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 679 | } |
| 680 | if (action->output.nodetype) { |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 681 | lysc_node_free_(ctx, &action->output.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 682 | } |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 683 | } |
| 684 | |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 685 | void |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 686 | 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] | 687 | { |
| 688 | struct lysc_node *child, *child_next; |
| 689 | |
Michal Vasko | 37a0fe6 | 2021-02-03 09:53:04 +0100 | [diff] [blame] | 690 | FREE_ARRAY(ctx, notif->when, lysc_when_free); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 691 | FREE_ARRAY(ctx, notif->musts, lysc_must_free); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 692 | LY_LIST_FOR_SAFE(notif->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 693 | lysc_node_free_(ctx, child); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | |
Radek Krejci | f2de0ed | 2019-05-02 14:13:18 +0200 | [diff] [blame] | 697 | void |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 698 | lysc_node_container_free(struct ly_ctx *ctx, struct lysc_node_container *node) |
| 699 | { |
| 700 | struct lysc_node *child, *child_next; |
| 701 | |
| 702 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 703 | lysc_node_free_(ctx, child); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 704 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 705 | LY_LIST_FOR_SAFE((struct lysc_node *)node->actions, child_next, child) { |
| 706 | lysc_node_free_(ctx, child); |
| 707 | } |
| 708 | LY_LIST_FOR_SAFE((struct lysc_node *)node->notifs, child_next, child) { |
| 709 | lysc_node_free_(ctx, child); |
| 710 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 711 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 712 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | static void |
| 716 | lysc_node_leaf_free(struct ly_ctx *ctx, struct lysc_node_leaf *node) |
| 717 | { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 718 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 719 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 720 | if (node->type) { |
| 721 | lysc_type_free(ctx, node->type); |
| 722 | } |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 723 | FREE_STRING(ctx, node->units); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 724 | if (node->dflt) { |
| 725 | node->dflt->realtype->plugin->free(ctx, node->dflt); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 726 | lysc_type_free(ctx, (struct lysc_type *)node->dflt->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 727 | free(node->dflt); |
| 728 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 729 | } |
| 730 | |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 731 | static void |
| 732 | lysc_node_leaflist_free(struct ly_ctx *ctx, struct lysc_node_leaflist *node) |
| 733 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 734 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 735 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 736 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 737 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 738 | if (node->type) { |
| 739 | lysc_type_free(ctx, node->type); |
| 740 | } |
| 741 | FREE_STRING(ctx, node->units); |
| 742 | LY_ARRAY_FOR(node->dflts, u) { |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 743 | node->dflts[u]->realtype->plugin->free(ctx, node->dflts[u]); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 744 | lysc_type_free(ctx, (struct lysc_type *)node->dflts[u]->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 745 | free(node->dflts[u]); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 746 | } |
| 747 | LY_ARRAY_FREE(node->dflts); |
| 748 | } |
| 749 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 750 | static void |
| 751 | lysc_node_list_free(struct ly_ctx *ctx, struct lysc_node_list *node) |
| 752 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 753 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 754 | struct lysc_node *child, *child_next; |
| 755 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 756 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 757 | lysc_node_free_(ctx, child); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 758 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 759 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 760 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 761 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 762 | LY_ARRAY_FOR(node->uniques, u) { |
| 763 | LY_ARRAY_FREE(node->uniques[u]); |
| 764 | } |
| 765 | LY_ARRAY_FREE(node->uniques); |
| 766 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 767 | LY_LIST_FOR_SAFE((struct lysc_node *)node->actions, child_next, child) { |
| 768 | lysc_node_free_(ctx, child); |
| 769 | } |
| 770 | LY_LIST_FOR_SAFE((struct lysc_node *)node->notifs, child_next, child) { |
| 771 | lysc_node_free_(ctx, child); |
| 772 | } |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 773 | } |
| 774 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 775 | static void |
| 776 | lysc_node_choice_free(struct ly_ctx *ctx, struct lysc_node_choice *node) |
| 777 | { |
| 778 | struct lysc_node *child, *child_next; |
| 779 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 780 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 781 | LY_LIST_FOR_SAFE((struct lysc_node *)node->cases, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 782 | lysc_node_free_(ctx, child); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | |
| 786 | static void |
| 787 | lysc_node_case_free(struct ly_ctx *ctx, struct lysc_node_case *node) |
| 788 | { |
| 789 | struct lysc_node *child, *child_next; |
| 790 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 791 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 792 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 793 | lysc_node_free_(ctx, child); |
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 | } |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 796 | |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 797 | static void |
| 798 | lysc_node_anydata_free(struct ly_ctx *ctx, struct lysc_node_anydata *node) |
| 799 | { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 800 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 801 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 802 | } |
| 803 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 804 | static void |
| 805 | lysc_node_free_(struct ly_ctx *ctx, struct lysc_node *node) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 806 | { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 807 | ly_bool inout = 0; |
| 808 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 809 | /* common part */ |
| 810 | FREE_STRING(ctx, node->name); |
Radek Krejci | 12fb914 | 2019-01-08 09:45:30 +0100 | [diff] [blame] | 811 | FREE_STRING(ctx, node->dsc); |
| 812 | FREE_STRING(ctx, node->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 813 | |
| 814 | /* nodetype-specific part */ |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 815 | switch (node->nodetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 816 | case LYS_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 817 | lysc_node_container_free(ctx, (struct lysc_node_container *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 818 | break; |
| 819 | case LYS_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 820 | lysc_node_leaf_free(ctx, (struct lysc_node_leaf *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 821 | break; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 822 | case LYS_LEAFLIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 823 | lysc_node_leaflist_free(ctx, (struct lysc_node_leaflist *)node); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 824 | break; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 825 | case LYS_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 826 | lysc_node_list_free(ctx, (struct lysc_node_list *)node); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 827 | break; |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 828 | case LYS_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 829 | lysc_node_choice_free(ctx, (struct lysc_node_choice *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 830 | break; |
| 831 | case LYS_CASE: |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 832 | lysc_node_case_free(ctx, (struct lysc_node_case *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 833 | break; |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 834 | case LYS_ANYDATA: |
| 835 | case LYS_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 836 | lysc_node_anydata_free(ctx, (struct lysc_node_anydata *)node); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 837 | break; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 838 | case LYS_RPC: |
| 839 | case LYS_ACTION: |
| 840 | lysc_node_action_free(ctx, (struct lysc_node_action *)node); |
| 841 | break; |
| 842 | case LYS_INPUT: |
| 843 | case LYS_OUTPUT: |
| 844 | lysc_node_action_inout_free(ctx, (struct lysc_node_action_inout *)node); |
| 845 | inout = 1; |
| 846 | break; |
| 847 | case LYS_NOTIF: |
| 848 | lysc_node_notif_free(ctx, (struct lysc_node_notif *)node); |
| 849 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 850 | default: |
| 851 | LOGINT(ctx); |
| 852 | } |
| 853 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 854 | FREE_ARRAY(ctx, node->exts, lysc_ext_instance_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 855 | |
| 856 | if (!inout) { |
| 857 | free(node); |
| 858 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 859 | } |
| 860 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 861 | void |
| 862 | lysc_node_free(struct ly_ctx *ctx, struct lysc_node *node, ly_bool unlink) |
| 863 | { |
| 864 | struct lysc_node *iter, **child_p; |
| 865 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 866 | if (node->nodetype & (LYS_INPUT | LYS_OUTPUT)) { |
| 867 | /* nothing to do - inouts are part of actions and cannot be unlinked/freed separately */ |
| 868 | return; |
| 869 | } |
| 870 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 871 | if (unlink) { |
| 872 | /* unlink from siblings */ |
| 873 | if (node->prev->next) { |
| 874 | node->prev->next = node->next; |
| 875 | } |
| 876 | if (node->next) { |
| 877 | node->next->prev = node->prev; |
| 878 | } else { |
| 879 | /* unlinking the last node */ |
| 880 | if (node->parent) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 881 | if (node->nodetype == LYS_ACTION) { |
| 882 | iter = (struct lysc_node *)lysc_node_actions(node->parent); |
| 883 | } else if (node->nodetype == LYS_NOTIF) { |
| 884 | iter = (struct lysc_node *)lysc_node_notifs(node->parent); |
| 885 | } else { |
Michal Vasko | 544e58a | 2021-01-28 14:33:41 +0100 | [diff] [blame] | 886 | iter = (struct lysc_node *)lysc_node_child(node->parent); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 887 | } |
Michal Vasko | 539c4a6 | 2020-11-03 17:21:34 +0100 | [diff] [blame] | 888 | LY_CHECK_ERR_RET(!iter, LOGINT(ctx), ); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 889 | } else if (node->nodetype == LYS_RPC) { |
| 890 | iter = (struct lysc_node *)node->module->compiled->rpcs; |
| 891 | } else if (node->nodetype == LYS_NOTIF) { |
| 892 | iter = (struct lysc_node *)node->module->compiled->notifs; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 893 | } else { |
| 894 | iter = node->module->compiled->data; |
| 895 | } |
| 896 | /* update the "last" pointer from the first node */ |
| 897 | iter->prev = node->prev; |
| 898 | } |
| 899 | |
| 900 | /* unlink from parent */ |
| 901 | if (node->parent) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 902 | if (node->nodetype == LYS_ACTION) { |
| 903 | child_p = (struct lysc_node **)lysc_node_actions_p(node->parent); |
| 904 | } else if (node->nodetype == LYS_NOTIF) { |
| 905 | child_p = (struct lysc_node **)lysc_node_notifs_p(node->parent); |
| 906 | } else { |
Michal Vasko | 544e58a | 2021-01-28 14:33:41 +0100 | [diff] [blame] | 907 | child_p = lysc_node_child_p(node->parent); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 908 | } |
| 909 | } else if (node->nodetype == LYS_RPC) { |
| 910 | child_p = (struct lysc_node **)&node->module->compiled->rpcs; |
| 911 | } else if (node->nodetype == LYS_NOTIF) { |
| 912 | child_p = (struct lysc_node **)&node->module->compiled->notifs; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 913 | } else { |
| 914 | child_p = &node->module->compiled->data; |
| 915 | } |
| 916 | if (child_p && (*child_p == node)) { |
| 917 | /* the node is the first child */ |
| 918 | *child_p = node->next; |
| 919 | } |
| 920 | } |
| 921 | |
| 922 | lysc_node_free_(ctx, node); |
| 923 | } |
| 924 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 925 | static void |
| 926 | lysc_module_free_(struct lysc_module *module) |
| 927 | { |
| 928 | struct ly_ctx *ctx; |
| 929 | struct lysc_node *node, *node_next; |
| 930 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 931 | LY_CHECK_ARG_RET(NULL, module, ); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 932 | ctx = module->mod->ctx; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 933 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 934 | LY_LIST_FOR_SAFE(module->data, node_next, node) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 935 | lysc_node_free_(ctx, node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 936 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 937 | LY_LIST_FOR_SAFE((struct lysc_node *)module->rpcs, node_next, node) { |
| 938 | lysc_node_free_(ctx, node); |
| 939 | } |
| 940 | LY_LIST_FOR_SAFE((struct lysc_node *)module->notifs, node_next, node) { |
| 941 | lysc_node_free_(ctx, node); |
| 942 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 943 | FREE_ARRAY(ctx, module->exts, lysc_ext_instance_free); |
| 944 | |
| 945 | free(module); |
| 946 | } |
| 947 | |
| 948 | void |
| 949 | lysc_module_free(struct lysc_module *module, void (*private_destructor)(const struct lysc_node *node, void *priv)) |
| 950 | { |
Radek Krejci | 9b04289 | 2019-02-13 14:28:44 +0100 | [diff] [blame] | 951 | /* TODO use the destructor, this just suppress warning about unused parameter */ |
| 952 | (void) private_destructor; |
| 953 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 954 | if (module) { |
| 955 | lysc_module_free_(module); |
| 956 | } |
| 957 | } |
| 958 | |
| 959 | void |
| 960 | lys_module_free(struct lys_module *module, void (*private_destructor)(const struct lysc_node *node, void *priv)) |
| 961 | { |
| 962 | if (!module) { |
| 963 | return; |
| 964 | } |
| 965 | |
| 966 | lysc_module_free(module->compiled, private_destructor); |
Radek Krejci | 80d281e | 2020-09-14 17:42:54 +0200 | [diff] [blame] | 967 | FREE_ARRAY(module->ctx, module->identities, lysc_ident_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 968 | lysp_module_free(module->parsed); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 969 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 970 | LY_ARRAY_FREE(module->augmented_by); |
| 971 | LY_ARRAY_FREE(module->deviated_by); |
| 972 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 973 | FREE_STRING(module->ctx, module->name); |
Radek Krejci | 0af4629 | 2019-01-11 16:02:31 +0100 | [diff] [blame] | 974 | FREE_STRING(module->ctx, module->revision); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 975 | FREE_STRING(module->ctx, module->ns); |
| 976 | FREE_STRING(module->ctx, module->prefix); |
| 977 | FREE_STRING(module->ctx, module->filepath); |
| 978 | FREE_STRING(module->ctx, module->org); |
| 979 | FREE_STRING(module->ctx, module->contact); |
| 980 | FREE_STRING(module->ctx, module->dsc); |
| 981 | FREE_STRING(module->ctx, module->ref); |
| 982 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 983 | free(module); |
| 984 | } |
Michal Vasko | 33ff942 | 2020-07-03 09:50:39 +0200 | [diff] [blame] | 985 | |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 986 | API void |
| 987 | lysc_extension_instance_free(struct ly_ctx *ctx, struct lysc_ext_substmt *substmts) |
| 988 | { |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 989 | for (LY_ARRAY_COUNT_TYPE u = 0; substmts[u].stmt; ++u) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 990 | if (!substmts[u].storage) { |
| 991 | continue; |
| 992 | } |
| 993 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 994 | switch (substmts[u].stmt) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 995 | case LY_STMT_TYPE: |
| 996 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 997 | /* single item */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 998 | struct lysc_type *type = *((struct lysc_type **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 999 | if (!type) { |
| 1000 | break; |
| 1001 | } |
| 1002 | lysc_type_free(ctx, type); |
| 1003 | } else { |
| 1004 | /* multiple items */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1005 | struct lysc_type **types = *((struct lysc_type ***)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1006 | if (!types) { |
| 1007 | break; |
| 1008 | } |
| 1009 | FREE_ARRAY(ctx, types, lysc_type2_free); |
| 1010 | } |
| 1011 | break; |
| 1012 | case LY_STMT_UNITS: |
| 1013 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1014 | /* single item */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1015 | const char *str = *((const char **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1016 | if (!str) { |
| 1017 | break; |
| 1018 | } |
| 1019 | FREE_STRING(ctx, str); |
| 1020 | } else { |
| 1021 | /* multiple items */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1022 | const char **strs = *((const char ***)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1023 | if (!strs) { |
| 1024 | break; |
| 1025 | } |
| 1026 | FREE_STRINGS(ctx, strs); |
| 1027 | } |
| 1028 | break; |
| 1029 | case LY_STMT_STATUS: |
Radek Krejci | ad5963b | 2019-09-06 16:03:05 +0200 | [diff] [blame] | 1030 | case LY_STMT_CONFIG: |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1031 | /* nothing to do */ |
| 1032 | break; |
| 1033 | case LY_STMT_IF_FEATURE: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1034 | struct lysc_iffeature *iff = *((struct lysc_iffeature **)substmts[u].storage); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1035 | if (!iff) { |
| 1036 | break; |
| 1037 | } |
| 1038 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1039 | /* single item */ |
| 1040 | lysc_iffeature_free(ctx, iff); |
| 1041 | free(iff); |
| 1042 | } else { |
| 1043 | /* multiple items */ |
| 1044 | FREE_ARRAY(ctx, iff, lysc_iffeature_free); |
| 1045 | } |
| 1046 | break; |
| 1047 | } |
| 1048 | |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1049 | /* TODO other statements */ |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1050 | default: |
| 1051 | LOGINT(ctx); |
| 1052 | } |
| 1053 | } |
| 1054 | } |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1055 | |
| 1056 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1057 | yang_parser_ctx_free(struct lys_yang_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1058 | { |
| 1059 | if (ctx) { |
| 1060 | free(ctx); |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1065 | yin_parser_ctx_free(struct lys_yin_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1066 | { |
| 1067 | if (ctx) { |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1068 | lyxml_ctx_free(ctx->xmlctx); |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1069 | free(ctx); |
| 1070 | } |
| 1071 | } |