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