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