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