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