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