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