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