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