blob: deaf20c88de5a717b32584c3b47af672d56f9350 [file] [log] [blame]
Radek Krejci19a96102018-11-15 13:38:09 +01001/**
Radek Krejcie7b95092019-05-15 11:03:07 +02002 * @file tree_schema_free.c
Radek Krejci19a96102018-11-15 13:38:09 +01003 * @author Radek Krejci <rkrejci@cesnet.cz>
Radek Krejcie7b95092019-05-15 11:03:07 +02004 * @brief Freeing functions for schema tree structures.
Radek Krejci19a96102018-11-15 13:38:09 +01005 *
Radek Krejcie7b95092019-05-15 11:03:07 +02006 * Copyright (c) 2019 CESNET, z.s.p.o.
Radek Krejci19a96102018-11-15 13:38:09 +01007 *
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 Krejcie7b95092019-05-15 11:03:07 +020017#include <stdlib.h>
18
19#include "dict.h"
20#include "tree.h"
21#include "tree_schema.h"
Radek Krejci19a96102018-11-15 13:38:09 +010022#include "tree_schema_internal.h"
Radek Krejcia1911222019-07-22 17:24:50 +020023#include "plugins_types.h"
Radek Krejci19a96102018-11-15 13:38:09 +010024#include "xpath.h"
25
Radek Krejci2d7a47b2019-05-16 13:34:10 +020026void lysp_grp_free(struct ly_ctx *ctx, struct lysp_grp *grp);
27void lysp_node_free(struct ly_ctx *ctx, struct lysp_node *node);
Radek Krejci19a96102018-11-15 13:38:09 +010028
29static void
30lysp_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 Krejci2d7a47b2019-05-16 13:34:10 +020044void
Radek Krejci19a96102018-11-15 13:38:09 +010045lysp_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ák298ff6d2019-07-26 14:29:03 +020057void
Radek Krejci19a96102018-11-15 13:38:09 +010058lysp_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ák0c2bab92019-07-22 15:33:19 +020068void
Radek Krejci19a96102018-11-15 13:38:09 +010069lysp_include_free(struct ly_ctx *ctx, struct lysp_include *include)
70{
71 if (include->submodule) {
Radek Krejci0bcdaed2019-01-10 10:21:34 +010072 lysp_submodule_free(ctx, include->submodule);
Radek Krejci19a96102018-11-15 13:38:09 +010073 }
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ákaa854b02019-07-22 14:17:10 +020080void
Radek Krejci19a96102018-11-15 13:38:09 +010081lysp_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ák986cb412019-07-04 13:10:11 +020088void
Radek Krejci19a96102018-11-15 13:38:09 +010089lysp_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 Krejci2d7a47b2019-05-16 13:34:10 +020098void
Radek Krejci19a96102018-11-15 13:38:09 +010099lysp_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 Krejci2d7a47b2019-05-16 13:34:10 +0200108void
Radek Krejci19a96102018-11-15 13:38:09 +0100109lysp_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
119static void
120lysp_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
130static void
131lysp_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 Krejcicdfecd92018-11-26 11:27:32 +0100140void lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type);
David Sedlák32488102019-07-15 17:44:10 +0200141void
Radek Krejci19a96102018-11-15 13:38:09 +0100142lysp_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ák04e17b22019-07-19 15:29:48 +0200159void
Radek Krejci19a96102018-11-15 13:38:09 +0100160lysp_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 Krejcif538ce52019-03-05 10:46:14 +0100173void
Radek Krejci19a96102018-11-15 13:38:09 +0100174lysp_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 Krejci2d7a47b2019-05-16 13:34:10 +0200188void
Radek Krejci19a96102018-11-15 13:38:09 +0100189lysp_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 Krejci6eeb58f2019-02-22 16:29:37 +0100197 lysp_action_inout_free(ctx, &action->input);
198 lysp_action_inout_free(ctx, &action->output);
Radek Krejci19a96102018-11-15 13:38:09 +0100199 FREE_ARRAY(ctx, action->exts, lysp_ext_instance_free);
200}
201
Radek Krejci2d7a47b2019-05-16 13:34:10 +0200202void
Radek Krejci19a96102018-11-15 13:38:09 +0100203lysp_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 Krejci2d7a47b2019-05-16 13:34:10 +0200220void
Radek Krejci19a96102018-11-15 13:38:09 +0100221lysp_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 Krejcif09e4e82019-06-14 15:08:11 +0200238void
Radek Krejci19a96102018-11-15 13:38:09 +0100239lysp_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 Krejci2d7a47b2019-05-16 13:34:10 +0200247void
Radek Krejci19a96102018-11-15 13:38:09 +0100248lysp_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 Krejci2d7a47b2019-05-16 13:34:10 +0200265void
Radek Krejci19a96102018-11-15 13:38:09 +0100266lysp_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 Krejci2d7a47b2019-05-16 13:34:10 +0200294void
Radek Krejci19a96102018-11-15 13:38:09 +0100295lysp_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ákd2d676a2019-07-22 11:28:19 +0200309void
Radek Krejci19a96102018-11-15 13:38:09 +0100310lysp_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 Krejci2d7a47b2019-05-16 13:34:10 +0200322void
Radek Krejci19a96102018-11-15 13:38:09 +0100323lysp_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 Krejci0bcdaed2019-01-10 10:21:34 +0100396void
397lysp_submodule_free(struct ly_ctx *ctx, struct lysp_submodule *submod)
398{
399 struct lysp_node *node, *next;
400
Radek Krejci40544fa2019-01-11 09:38:37 +0100401 if (!submod) {
402 return;
403 }
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100404
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 Krejci19a96102018-11-15 13:38:09 +0100435API void
436lysp_module_free(struct lysp_module *module)
437{
438 struct ly_ctx *ctx;
439 struct lysp_node *node, *next;
440
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100441 if (!module) {
442 return;
443 }
444 ctx = module->mod->ctx;
Radek Krejci19a96102018-11-15 13:38:09 +0100445
446 FREE_ARRAY(ctx, module->imports, lysp_import_free);
447 FREE_ARRAY(ctx, module->includes, lysp_include_free);
448
Radek Krejci19a96102018-11-15 13:38:09 +0100449 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 Krejci0af46292019-01-11 16:02:31 +0100467void
Michal Vasko6f4cbb62020-02-28 11:15:47 +0100468lysc_extension_free(struct ly_ctx *ctx, struct lysc_ext **ext)
469{
470 if (--(*ext)->refcount) {
471 return;
472 }
473 FREE_STRING(ctx, (*ext)->name);
474 FREE_STRING(ctx, (*ext)->argument);
475 FREE_ARRAY(ctx, (*ext)->exts, lysc_ext_instance_free);
476 free(*ext);
477}
478
479void
Radek Krejci19a96102018-11-15 13:38:09 +0100480lysc_ext_instance_free(struct ly_ctx *ctx, struct lysc_ext_instance *ext)
481{
fredganebc50572019-10-31 15:39:23 +0800482 if (ext->def && ext->def->plugin && ext->def->plugin->free) {
Radek Krejci38d85362019-09-05 16:26:38 +0200483 ext->def->plugin->free(ctx, ext);
484 }
Michal Vasko6f4cbb62020-02-28 11:15:47 +0100485 lysc_extension_free(ctx, &ext->def);
Radek Krejci0935f412019-08-20 16:15:18 +0200486 FREE_STRING(ctx, ext->argument);
487 FREE_ARRAY(ctx, ext->exts, lysc_ext_instance_free);
488}
489
490void
Radek Krejci19a96102018-11-15 13:38:09 +0100491lysc_iffeature_free(struct ly_ctx *UNUSED(ctx), struct lysc_iffeature *iff)
492{
493 LY_ARRAY_FREE(iff->features);
494 free(iff->expr);
495}
496
497static void
Radek Krejci00b874b2019-02-12 10:54:50 +0100498lysc_when_free(struct ly_ctx *ctx, struct lysc_when **w)
Radek Krejci58d171e2018-11-23 13:50:55 +0100499{
Radek Krejci00b874b2019-02-12 10:54:50 +0100500 if (--(*w)->refcount) {
501 return;
502 }
503 lyxp_expr_free(ctx, (*w)->cond);
504 FREE_STRING(ctx, (*w)->dsc);
505 FREE_STRING(ctx, (*w)->ref);
506 FREE_ARRAY(ctx, (*w)->exts, lysc_ext_instance_free);
507 free(*w);
Radek Krejci58d171e2018-11-23 13:50:55 +0100508}
509
Radek Krejciccd20f12019-02-15 14:12:27 +0100510void
Radek Krejci58d171e2018-11-23 13:50:55 +0100511lysc_must_free(struct ly_ctx *ctx, struct lysc_must *must)
512{
513 lyxp_expr_free(ctx, must->cond);
514 FREE_STRING(ctx, must->emsg);
515 FREE_STRING(ctx, must->eapptag);
Radek Krejcic8b31002019-01-08 10:24:45 +0100516 FREE_STRING(ctx, must->dsc);
517 FREE_STRING(ctx, must->ref);
Radek Krejci58d171e2018-11-23 13:50:55 +0100518 FREE_ARRAY(ctx, must->exts, lysc_ext_instance_free);
519}
520
521static void
Radek Krejci19a96102018-11-15 13:38:09 +0100522lysc_import_free(struct ly_ctx *ctx, struct lysc_import *import)
523{
524 /* imported module is freed directly from the context's list */
525 FREE_STRING(ctx, import->prefix);
526 FREE_ARRAY(ctx, import->exts, lysc_ext_instance_free);
527}
528
529static void
530lysc_ident_free(struct ly_ctx *ctx, struct lysc_ident *ident)
531{
532 FREE_STRING(ctx, ident->name);
Radek Krejcic8b31002019-01-08 10:24:45 +0100533 FREE_STRING(ctx, ident->dsc);
534 FREE_STRING(ctx, ident->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100535 FREE_ARRAY(ctx, ident->iffeatures, lysc_iffeature_free);
536 LY_ARRAY_FREE(ident->derived);
537 FREE_ARRAY(ctx, ident->exts, lysc_ext_instance_free);
538}
539
Radek Krejci2d7a47b2019-05-16 13:34:10 +0200540void
Radek Krejci19a96102018-11-15 13:38:09 +0100541lysc_feature_free(struct ly_ctx *ctx, struct lysc_feature *feat)
542{
543 FREE_STRING(ctx, feat->name);
Radek Krejcic8b31002019-01-08 10:24:45 +0100544 FREE_STRING(ctx, feat->dsc);
545 FREE_STRING(ctx, feat->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100546 FREE_ARRAY(ctx, feat->iffeatures, lysc_iffeature_free);
547 LY_ARRAY_FREE(feat->depfeatures);
548 FREE_ARRAY(ctx, feat->exts, lysc_ext_instance_free);
549}
550
551static void
552lysc_range_free(struct ly_ctx *ctx, struct lysc_range *range)
553{
554 LY_ARRAY_FREE(range->parts);
555 FREE_STRING(ctx, range->eapptag);
556 FREE_STRING(ctx, range->emsg);
Radek Krejcic8b31002019-01-08 10:24:45 +0100557 FREE_STRING(ctx, range->dsc);
558 FREE_STRING(ctx, range->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100559 FREE_ARRAY(ctx, range->exts, lysc_ext_instance_free);
560}
561
562static void
563lysc_pattern_free(struct ly_ctx *ctx, struct lysc_pattern **pattern)
564{
565 if (--(*pattern)->refcount) {
566 return;
567 }
Radek Krejci54579462019-04-30 12:47:06 +0200568 pcre2_code_free((*pattern)->code);
569 FREE_STRING(ctx, (*pattern)->expr);
Radek Krejci19a96102018-11-15 13:38:09 +0100570 FREE_STRING(ctx, (*pattern)->eapptag);
571 FREE_STRING(ctx, (*pattern)->emsg);
Radek Krejcic8b31002019-01-08 10:24:45 +0100572 FREE_STRING(ctx, (*pattern)->dsc);
573 FREE_STRING(ctx, (*pattern)->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100574 FREE_ARRAY(ctx, (*pattern)->exts, lysc_ext_instance_free);
575 free(*pattern);
576}
577
578static void
Radek Krejci693262f2019-04-29 15:23:20 +0200579lysc_enum_item_free(struct ly_ctx *ctx, struct lysc_type_bitenum_item *item)
Radek Krejci19a96102018-11-15 13:38:09 +0100580{
581 FREE_STRING(ctx, item->name);
Radek Krejcic8b31002019-01-08 10:24:45 +0100582 FREE_STRING(ctx, item->dsc);
583 FREE_STRING(ctx, item->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100584 FREE_ARRAY(ctx, item->iffeatures, lysc_iffeature_free);
585 FREE_ARRAY(ctx, item->exts, lysc_ext_instance_free);
586}
587
Radek Krejcia3045382018-11-22 14:30:31 +0100588static void
589lysc_type2_free(struct ly_ctx *ctx, struct lysc_type **type)
590{
591 lysc_type_free(ctx, *type);
592}
Radek Krejcicdfecd92018-11-26 11:27:32 +0100593void
Radek Krejci19a96102018-11-15 13:38:09 +0100594lysc_type_free(struct ly_ctx *ctx, struct lysc_type *type)
595{
596 if (--type->refcount) {
597 return;
598 }
599 switch(type->basetype) {
600 case LY_TYPE_BINARY:
601 FREE_MEMBER(ctx, ((struct lysc_type_bin*)type)->length, lysc_range_free);
602 break;
603 case LY_TYPE_BITS:
Radek Krejci693262f2019-04-29 15:23:20 +0200604 FREE_ARRAY(ctx, (struct lysc_type_bitenum_item*)((struct lysc_type_bits*)type)->bits, lysc_enum_item_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100605 break;
Radek Krejci6cba4292018-11-15 17:33:29 +0100606 case LY_TYPE_DEC64:
607 FREE_MEMBER(ctx, ((struct lysc_type_dec*)type)->range, lysc_range_free);
608 break;
Radek Krejci19a96102018-11-15 13:38:09 +0100609 case LY_TYPE_STRING:
610 FREE_MEMBER(ctx, ((struct lysc_type_str*)type)->length, lysc_range_free);
611 FREE_ARRAY(ctx, ((struct lysc_type_str*)type)->patterns, lysc_pattern_free);
612 break;
613 case LY_TYPE_ENUM:
614 FREE_ARRAY(ctx, ((struct lysc_type_enum*)type)->enums, lysc_enum_item_free);
615 break;
616 case LY_TYPE_INT8:
617 case LY_TYPE_UINT8:
618 case LY_TYPE_INT16:
619 case LY_TYPE_UINT16:
620 case LY_TYPE_INT32:
621 case LY_TYPE_UINT32:
622 case LY_TYPE_INT64:
623 case LY_TYPE_UINT64:
624 FREE_MEMBER(ctx, ((struct lysc_type_num*)type)->range, lysc_range_free);
625 break;
Radek Krejci555cb5b2018-11-16 14:54:33 +0100626 case LY_TYPE_IDENT:
627 LY_ARRAY_FREE(((struct lysc_type_identityref*)type)->bases);
628 break;
Radek Krejcia3045382018-11-22 14:30:31 +0100629 case LY_TYPE_UNION:
630 FREE_ARRAY(ctx, ((struct lysc_type_union*)type)->types, lysc_type2_free);
631 break;
632 case LY_TYPE_LEAFREF:
633 FREE_STRING(ctx, ((struct lysc_type_leafref*)type)->path);
634 break;
Radek Krejci16c0f822018-11-16 10:46:10 +0100635 case LY_TYPE_INST:
Radek Krejci19a96102018-11-15 13:38:09 +0100636 case LY_TYPE_BOOL:
637 case LY_TYPE_EMPTY:
Radek Krejci43699232018-11-23 14:59:46 +0100638 case LY_TYPE_UNKNOWN:
Radek Krejci19a96102018-11-15 13:38:09 +0100639 /* nothing to do */
640 break;
641 }
642 FREE_ARRAY(ctx, type->exts, lysc_ext_instance_free);
Radek Krejcia1911222019-07-22 17:24:50 +0200643 if (type->dflt) {
644 type->plugin->free(ctx, type->dflt);
645 lysc_type_free(ctx, type->dflt->realtype);
646 free(type->dflt);
647 }
Radek Krejci19a96102018-11-15 13:38:09 +0100648 free(type);
649}
650
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100651void
Radek Krejcif538ce52019-03-05 10:46:14 +0100652lysc_action_inout_free(struct ly_ctx *ctx, struct lysc_action_inout *inout)
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100653{
654 struct lysc_node *child, *child_next;
655
Radek Krejcif538ce52019-03-05 10:46:14 +0100656 FREE_ARRAY(ctx, inout->musts, lysc_must_free);
657 LY_LIST_FOR_SAFE(inout->data, child_next, child) {
658 lysc_node_free(ctx, child);
659 }
660}
661
662void
663lysc_action_free(struct ly_ctx *ctx, struct lysc_action *action)
664{
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100665 FREE_STRING(ctx, action->name);
666 FREE_STRING(ctx, action->dsc);
667 FREE_STRING(ctx, action->ref);
668 FREE_ARRAY(ctx, action->iffeatures, lysc_iffeature_free);
669 FREE_ARRAY(ctx, action->exts, lysc_ext_instance_free);
Radek Krejcifc11bd72019-04-11 16:00:05 +0200670 FREE_ARRAY(ctx, action->input_exts, lysc_ext_instance_free);
Radek Krejcif538ce52019-03-05 10:46:14 +0100671 lysc_action_inout_free(ctx, &action->input);
Radek Krejcifc11bd72019-04-11 16:00:05 +0200672 FREE_ARRAY(ctx, action->output_exts, lysc_ext_instance_free);
Radek Krejcif538ce52019-03-05 10:46:14 +0100673 lysc_action_inout_free(ctx, &action->output);
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100674}
675
Radek Krejcifc11bd72019-04-11 16:00:05 +0200676void
677lysc_notif_free(struct ly_ctx *ctx, struct lysc_notif *notif)
678{
679 struct lysc_node *child, *child_next;
680
681 FREE_STRING(ctx, notif->name);
682 FREE_STRING(ctx, notif->dsc);
683 FREE_STRING(ctx, notif->ref);
684 FREE_ARRAY(ctx, notif->iffeatures, lysc_iffeature_free);
685 FREE_ARRAY(ctx, notif->exts, lysc_ext_instance_free);
686 FREE_ARRAY(ctx, notif->musts, lysc_must_free);
687 LY_LIST_FOR_SAFE(notif->data, child_next, child) {
688 lysc_node_free(ctx, child);
689 }
690}
691
Radek Krejcif2de0ed2019-05-02 14:13:18 +0200692void
Radek Krejci19a96102018-11-15 13:38:09 +0100693lysc_node_container_free(struct ly_ctx *ctx, struct lysc_node_container *node)
694{
695 struct lysc_node *child, *child_next;
696
697 LY_LIST_FOR_SAFE(node->child, child_next, child) {
698 lysc_node_free(ctx, child);
699 }
Radek Krejci58d171e2018-11-23 13:50:55 +0100700 FREE_ARRAY(ctx, node->musts, lysc_must_free);
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100701 FREE_ARRAY(ctx, node->actions, lysc_action_free);
Radek Krejcifc11bd72019-04-11 16:00:05 +0200702 FREE_ARRAY(ctx, node->notifs, lysc_notif_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100703}
704
705static void
706lysc_node_leaf_free(struct ly_ctx *ctx, struct lysc_node_leaf *node)
707{
Radek Krejci58d171e2018-11-23 13:50:55 +0100708 FREE_ARRAY(ctx, node->musts, lysc_must_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100709 if (node->type) {
710 lysc_type_free(ctx, node->type);
711 }
Radek Krejci58d171e2018-11-23 13:50:55 +0100712 FREE_STRING(ctx, node->units);
Radek Krejcia1911222019-07-22 17:24:50 +0200713 if (node->dflt) {
714 node->dflt->realtype->plugin->free(ctx, node->dflt);
715 lysc_type_free(ctx, node->dflt->realtype);
716 free(node->dflt);
717 }
Radek Krejci19a96102018-11-15 13:38:09 +0100718}
719
Radek Krejci42452ac2018-11-28 17:09:52 +0100720static void
721lysc_node_leaflist_free(struct ly_ctx *ctx, struct lysc_node_leaflist *node)
722{
723 unsigned int u;
724
Radek Krejci42452ac2018-11-28 17:09:52 +0100725 FREE_ARRAY(ctx, node->musts, lysc_must_free);
726 if (node->type) {
727 lysc_type_free(ctx, node->type);
728 }
729 FREE_STRING(ctx, node->units);
730 LY_ARRAY_FOR(node->dflts, u) {
Radek Krejcia1911222019-07-22 17:24:50 +0200731 node->dflts[u]->realtype->plugin->free(ctx, node->dflts[u]);
732 lysc_type_free(ctx, node->dflts[u]->realtype);
733 free(node->dflts[u]);
Radek Krejci42452ac2018-11-28 17:09:52 +0100734 }
735 LY_ARRAY_FREE(node->dflts);
Radek Krejcid0ef1af2019-07-23 12:22:05 +0200736 LY_ARRAY_FREE(node->dflts_mods);
Radek Krejci42452ac2018-11-28 17:09:52 +0100737}
738
Radek Krejci9bb94eb2018-12-04 16:48:35 +0100739static void
740lysc_node_list_free(struct ly_ctx *ctx, struct lysc_node_list *node)
741{
742 unsigned int u;
743 struct lysc_node *child, *child_next;
744
Radek Krejci9bb94eb2018-12-04 16:48:35 +0100745 LY_LIST_FOR_SAFE(node->child, child_next, child) {
746 lysc_node_free(ctx, child);
747 }
748 FREE_ARRAY(ctx, node->musts, lysc_must_free);
749
Radek Krejci9bb94eb2018-12-04 16:48:35 +0100750 LY_ARRAY_FOR(node->uniques, u) {
751 LY_ARRAY_FREE(node->uniques[u]);
752 }
753 LY_ARRAY_FREE(node->uniques);
754
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100755 FREE_ARRAY(ctx, node->actions, lysc_action_free);
Radek Krejcifc11bd72019-04-11 16:00:05 +0200756 FREE_ARRAY(ctx, node->notifs, lysc_notif_free);
Radek Krejci9bb94eb2018-12-04 16:48:35 +0100757}
758
Radek Krejci056d0a82018-12-06 16:57:25 +0100759static void
760lysc_node_choice_free(struct ly_ctx *ctx, struct lysc_node_choice *node)
761{
762 struct lysc_node *child, *child_next;
763
Radek Krejci056d0a82018-12-06 16:57:25 +0100764 if (node->cases) {
765 LY_LIST_FOR_SAFE(node->cases->child, child_next, child) {
766 lysc_node_free(ctx, child);
767 }
768 LY_LIST_FOR_SAFE((struct lysc_node*)node->cases, child_next, child) {
769 lysc_node_free(ctx, child);
770 }
771 }
Radek Krejci9800fb82018-12-13 14:26:23 +0100772}
Radek Krejci056d0a82018-12-06 16:57:25 +0100773
Radek Krejci9800fb82018-12-13 14:26:23 +0100774static void
775lysc_node_anydata_free(struct ly_ctx *ctx, struct lysc_node_anydata *node)
776{
777 FREE_ARRAY(ctx, node->musts, lysc_must_free);
Radek Krejci056d0a82018-12-06 16:57:25 +0100778}
779
Radek Krejci19a96102018-11-15 13:38:09 +0100780void
781lysc_node_free(struct ly_ctx *ctx, struct lysc_node *node)
782{
783 /* common part */
784 FREE_STRING(ctx, node->name);
Radek Krejci12fb9142019-01-08 09:45:30 +0100785 FREE_STRING(ctx, node->dsc);
786 FREE_STRING(ctx, node->ref);
Radek Krejci19a96102018-11-15 13:38:09 +0100787
788 /* nodetype-specific part */
789 switch(node->nodetype) {
790 case LYS_CONTAINER:
791 lysc_node_container_free(ctx, (struct lysc_node_container*)node);
792 break;
793 case LYS_LEAF:
794 lysc_node_leaf_free(ctx, (struct lysc_node_leaf*)node);
795 break;
Radek Krejci42452ac2018-11-28 17:09:52 +0100796 case LYS_LEAFLIST:
797 lysc_node_leaflist_free(ctx, (struct lysc_node_leaflist*)node);
798 break;
Radek Krejci9bb94eb2018-12-04 16:48:35 +0100799 case LYS_LIST:
800 lysc_node_list_free(ctx, (struct lysc_node_list*)node);
801 break;
Radek Krejci056d0a82018-12-06 16:57:25 +0100802 case LYS_CHOICE:
803 lysc_node_choice_free(ctx, (struct lysc_node_choice*)node);
804 break;
805 case LYS_CASE:
806 /* nothing specific */
807 break;
Radek Krejci9800fb82018-12-13 14:26:23 +0100808 case LYS_ANYDATA:
809 case LYS_ANYXML:
810 lysc_node_anydata_free(ctx, (struct lysc_node_anydata*)node);
811 break;
Radek Krejci19a96102018-11-15 13:38:09 +0100812 default:
813 LOGINT(ctx);
814 }
815
Radek Krejci00b874b2019-02-12 10:54:50 +0100816 FREE_ARRAY(ctx, node->when, lysc_when_free);
Radek Krejci056d0a82018-12-06 16:57:25 +0100817 FREE_ARRAY(ctx, node->iffeatures, lysc_iffeature_free);
818 FREE_ARRAY(ctx, node->exts, lysc_ext_instance_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100819 free(node);
820}
821
822static void
823lysc_module_free_(struct lysc_module *module)
824{
825 struct ly_ctx *ctx;
826 struct lysc_node *node, *node_next;
827
828 LY_CHECK_ARG_RET(NULL, module,);
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100829 ctx = module->mod->ctx;
Radek Krejci19a96102018-11-15 13:38:09 +0100830
Radek Krejci19a96102018-11-15 13:38:09 +0100831 FREE_ARRAY(ctx, module->imports, lysc_import_free);
832 FREE_ARRAY(ctx, module->features, lysc_feature_free);
833 FREE_ARRAY(ctx, module->identities, lysc_ident_free);
834
835 LY_LIST_FOR_SAFE(module->data, node_next, node) {
836 lysc_node_free(ctx, node);
837 }
Radek Krejci6eeb58f2019-02-22 16:29:37 +0100838 FREE_ARRAY(ctx, module->rpcs, lysc_action_free);
Radek Krejcifc11bd72019-04-11 16:00:05 +0200839 FREE_ARRAY(ctx, module->notifs, lysc_notif_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100840
Radek Krejci0935f412019-08-20 16:15:18 +0200841 FREE_ARRAY(ctx, module->extensions, lysc_extension_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100842 FREE_ARRAY(ctx, module->exts, lysc_ext_instance_free);
843
844 free(module);
845}
846
847void
848lysc_module_free(struct lysc_module *module, void (*private_destructor)(const struct lysc_node *node, void *priv))
849{
Radek Krejci9b042892019-02-13 14:28:44 +0100850 /* TODO use the destructor, this just suppress warning about unused parameter */
851 (void) private_destructor;
852
Radek Krejci19a96102018-11-15 13:38:09 +0100853 if (module) {
854 lysc_module_free_(module);
855 }
856}
857
858void
859lys_module_free(struct lys_module *module, void (*private_destructor)(const struct lysc_node *node, void *priv))
860{
861 if (!module) {
862 return;
863 }
864
865 lysc_module_free(module->compiled, private_destructor);
Radek Krejci0af46292019-01-11 16:02:31 +0100866 FREE_ARRAY(module->ctx, module->off_features, lysc_feature_free);
Radek Krejci0935f412019-08-20 16:15:18 +0200867 FREE_ARRAY(module->ctx, module->off_extensions, lysc_extension_free);
Radek Krejci19a96102018-11-15 13:38:09 +0100868 lysp_module_free(module->parsed);
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100869
870 FREE_STRING(module->ctx, module->name);
Radek Krejci0af46292019-01-11 16:02:31 +0100871 FREE_STRING(module->ctx, module->revision);
Radek Krejci0bcdaed2019-01-10 10:21:34 +0100872 FREE_STRING(module->ctx, module->ns);
873 FREE_STRING(module->ctx, module->prefix);
874 FREE_STRING(module->ctx, module->filepath);
875 FREE_STRING(module->ctx, module->org);
876 FREE_STRING(module->ctx, module->contact);
877 FREE_STRING(module->ctx, module->dsc);
878 FREE_STRING(module->ctx, module->ref);
879
Radek Krejci19a96102018-11-15 13:38:09 +0100880 free(module);
881}
Radek Krejci38d85362019-09-05 16:26:38 +0200882API void
883lysc_extension_instance_free(struct ly_ctx *ctx, struct lysc_ext_substmt *substmts)
884{
885 for (unsigned int u = 0; substmts[u].stmt; ++u) {
886 if (!substmts[u].storage) {
887 continue;
888 }
889
890 switch(substmts[u].stmt) {
891 case LY_STMT_TYPE:
892 if (substmts[u].cardinality < LY_STMT_CARD_SOME) {
893 /* single item */
894 struct lysc_type *type = *((struct lysc_type**)substmts[u].storage);
895 if (!type) {
896 break;
897 }
898 lysc_type_free(ctx, type);
899 } else {
900 /* multiple items */
901 struct lysc_type **types = *((struct lysc_type***)substmts[u].storage);
902 if (!types) {
903 break;
904 }
905 FREE_ARRAY(ctx, types, lysc_type2_free);
906 }
907 break;
908 case LY_STMT_UNITS:
909 if (substmts[u].cardinality < LY_STMT_CARD_SOME) {
910 /* single item */
911 const char *str = *((const char**)substmts[u].storage);
912 if (!str) {
913 break;
914 }
915 FREE_STRING(ctx, str);
916 } else {
917 /* multiple items */
918 const char **strs = *((const char***)substmts[u].storage);
919 if (!strs) {
920 break;
921 }
922 FREE_STRINGS(ctx, strs);
923 }
924 break;
925 case LY_STMT_STATUS:
Radek Krejciad5963b2019-09-06 16:03:05 +0200926 case LY_STMT_CONFIG:
Radek Krejci38d85362019-09-05 16:26:38 +0200927 /* nothing to do */
928 break;
929 case LY_STMT_IF_FEATURE: {
930 struct lysc_iffeature *iff = *((struct lysc_iffeature**)substmts[u].storage);
931 if (!iff) {
932 break;
933 }
934 if (substmts[u].cardinality < LY_STMT_CARD_SOME) {
935 /* single item */
936 lysc_iffeature_free(ctx, iff);
937 free(iff);
938 } else {
939 /* multiple items */
940 FREE_ARRAY(ctx, iff, lysc_iffeature_free);
941 }
942 break;
943 }
944
945 /* TODO other statements */
946 default:
947 LOGINT(ctx);
948 }
949 }
950}
David Sedlákebd3acf2019-07-26 15:04:32 +0200951
952void
953lys_parser_ctx_free(struct lys_parser_ctx *ctx)
954{
955 if (ctx) {
956 free(ctx);
957 }
958}
959
960void
961yin_parser_ctx_free(struct yin_parser_ctx *ctx)
962{
963 if (ctx) {
964 lyxml_context_clear(&ctx->xml_ctx);
965 free(ctx);
966 }
967}