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