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> |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 5 | * @brief Freeing functions for schema tree structures. |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 6 | * |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 7 | * Copyright (c) 2019 - 2022 CESNET, z.s.p.o. |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 8 | * |
| 9 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 10 | * You may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * https://opensource.org/licenses/BSD-3-Clause |
| 14 | */ |
| 15 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 16 | #include "tree_schema_free.h" |
| 17 | |
Michal Vasko | ee75760 | 2021-06-10 14:38:19 +0200 | [diff] [blame] | 18 | #include <assert.h> |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 19 | #include <stdlib.h> |
| 20 | |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 21 | #include "common.h" |
Michal Vasko | 6973015 | 2020-10-09 16:30:07 +0200 | [diff] [blame] | 22 | #include "compat.h" |
Radek Krejci | 7711410 | 2021-03-10 15:21:57 +0100 | [diff] [blame] | 23 | #include "dict.h" |
Radek Krejci | 47fab89 | 2020-11-05 17:02:41 +0100 | [diff] [blame] | 24 | #include "log.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 25 | #include "plugins_exts.h" |
| 26 | #include "plugins_types.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 27 | #include "tree.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 28 | #include "tree_data.h" |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 29 | #include "tree_data_internal.h" |
Radek Krejci | 859a15a | 2021-03-05 20:56:59 +0100 | [diff] [blame] | 30 | #include "tree_edit.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 31 | #include "tree_schema.h" |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 32 | #include "tree_schema_internal.h" |
Radek Krejci | 535ea9f | 2020-05-29 16:01:05 +0200 | [diff] [blame] | 33 | #include "xml.h" |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 34 | #include "xpath.h" |
| 35 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 36 | static void lysc_extension_free(struct lysf_ctx *ctx, struct lysc_ext **ext); |
| 37 | static void lysc_node_free_(struct lysf_ctx *ctx, struct lysc_node *node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 38 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 39 | void |
| 40 | lysp_qname_free(struct ly_ctx *ctx, struct lysp_qname *qname) |
| 41 | { |
| 42 | if (qname) { |
| 43 | lydict_remove(ctx, qname->str); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * @brief Free the parsed generic statement structure. |
| 49 | * |
| 50 | * @param[in] ctx libyang context. |
| 51 | * @param[in] grp Parsed schema statement structure to free. Note that the structure itself is not freed. |
| 52 | */ |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 53 | static void |
| 54 | lysp_stmt_free(struct ly_ctx *ctx, struct lysp_stmt *stmt) |
| 55 | { |
| 56 | struct lysp_stmt *child, *next; |
| 57 | |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 58 | lydict_remove(ctx, stmt->stmt); |
| 59 | lydict_remove(ctx, stmt->arg); |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 60 | ly_free_prefix_data(stmt->format, stmt->prefix_data); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 61 | |
| 62 | LY_LIST_FOR_SAFE(stmt->child, next, child) { |
| 63 | lysp_stmt_free(ctx, child); |
| 64 | } |
| 65 | |
| 66 | free(stmt); |
| 67 | } |
| 68 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 69 | void |
| 70 | lysp_ext_instance_free(struct lysf_ctx *ctx, struct lysp_ext_instance *ext) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 71 | { |
| 72 | struct lysp_stmt *stmt, *next; |
aPiecek | 60d9d67 | 2021-04-27 15:49:57 +0200 | [diff] [blame] | 73 | struct lysp_node *node, *next_node; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 74 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 75 | lydict_remove(ctx->ctx, ext->name); |
| 76 | lydict_remove(ctx->ctx, ext->argument); |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 77 | ly_free_prefix_data(ext->format, ext->prefix_data); |
aPiecek | 60d9d67 | 2021-04-27 15:49:57 +0200 | [diff] [blame] | 78 | LY_LIST_FOR_SAFE(ext->parsed, next_node, node) { |
| 79 | lysp_node_free(ctx, node); |
| 80 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 81 | |
| 82 | LY_LIST_FOR_SAFE(ext->child, next, stmt) { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 83 | lysp_stmt_free(ctx->ctx, stmt); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 84 | } |
| 85 | } |
| 86 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 87 | /** |
| 88 | * @brief Free the parsed import structure. |
| 89 | * |
| 90 | * @param[in] ctx Free context. |
| 91 | * @param[in] import Parsed schema import structure to free. Note that the structure itself is not freed. |
| 92 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 93 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 94 | lysp_import_free(struct lysf_ctx *ctx, struct lysp_import *import) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 95 | { |
| 96 | /* imported module is freed directly from the context's list */ |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 97 | lydict_remove(ctx->ctx, import->name); |
| 98 | lydict_remove(ctx->ctx, import->prefix); |
| 99 | lydict_remove(ctx->ctx, import->dsc); |
| 100 | lydict_remove(ctx->ctx, import->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 101 | FREE_ARRAY(ctx, import->exts, lysp_ext_instance_free); |
| 102 | } |
| 103 | |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 104 | /** |
| 105 | * @brief Common function to erase include record in main module and submodule. |
| 106 | * |
| 107 | * There is a difference since the main module is expected to have the complete list if the included submodules and |
| 108 | * the parsed submodule is shared with any include in a submodule. Therefore, the referenced submodules in the include |
| 109 | * record are freed only from main module's records. |
| 110 | * |
| 111 | * @param[in] ctx libyang context |
| 112 | * @param[in] include The include record to be erased, the record itself is not freed. |
| 113 | * @param[in] main_module Flag to get know if the include record is placed in main module so also the referenced submodule |
| 114 | * is supposed to be freed. |
| 115 | */ |
| 116 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 117 | lysp_include_free_(struct lysf_ctx *ctx, struct lysp_include *include, ly_bool main_module) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 118 | { |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 119 | if (main_module && include->submodule) { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 120 | lysp_module_free(ctx, (struct lysp_module *)include->submodule); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 121 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 122 | lydict_remove(ctx->ctx, include->name); |
| 123 | lydict_remove(ctx->ctx, include->dsc); |
| 124 | lydict_remove(ctx->ctx, include->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 125 | FREE_ARRAY(ctx, include->exts, lysp_ext_instance_free); |
| 126 | } |
| 127 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 128 | /** |
| 129 | * @brief Free the parsed include structure of a submodule. |
| 130 | * |
| 131 | * @param[in] ctx Free context. |
| 132 | * @param[in] include Parsed schema include structure to free. Note that the structure itself is not freed. |
| 133 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 134 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 135 | lysp_include_free_submodule(struct lysf_ctx *ctx, struct lysp_include *include) |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 136 | { |
Michal Vasko | a0a498b | 2021-09-22 12:17:48 +0200 | [diff] [blame] | 137 | lysp_include_free_(ctx, include, 0); |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 138 | } |
| 139 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 140 | /** |
| 141 | * @brief Free the parsed include structure of a module. |
| 142 | * |
| 143 | * @param[in] ctx Free context. |
| 144 | * @param[in] include Parsed schema include structure to free. Note that the structure itself is not freed. |
| 145 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 146 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 147 | lysp_include_free(struct lysf_ctx *ctx, struct lysp_include *include) |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 148 | { |
Michal Vasko | a0a498b | 2021-09-22 12:17:48 +0200 | [diff] [blame] | 149 | lysp_include_free_(ctx, include, 1); |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 150 | } |
| 151 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 152 | /** |
| 153 | * @brief Free the parsed revision structure. |
| 154 | * |
| 155 | * @param[in] ctx Free context. |
| 156 | * @param[in] rev Parsed schema revision structure to free. Note that the structure itself is not freed. |
| 157 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 158 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 159 | lysp_revision_free(struct lysf_ctx *ctx, struct lysp_revision *rev) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 160 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 161 | lydict_remove(ctx->ctx, rev->dsc); |
| 162 | lydict_remove(ctx->ctx, rev->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 163 | FREE_ARRAY(ctx, rev->exts, lysp_ext_instance_free); |
| 164 | } |
| 165 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 166 | /** |
| 167 | * @brief Free the parsed ext structure. |
| 168 | * |
| 169 | * @param[in] ctx Free context. |
| 170 | * @param[in] ext Parsed schema ext structure to free. Note that the structure itself is not freed. |
| 171 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 172 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 173 | lysp_ext_free(struct lysf_ctx *ctx, struct lysp_ext *ext) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 174 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 175 | lydict_remove(ctx->ctx, ext->name); |
| 176 | lydict_remove(ctx->ctx, ext->argname); |
| 177 | lydict_remove(ctx->ctx, ext->dsc); |
| 178 | lydict_remove(ctx->ctx, ext->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 179 | FREE_ARRAY(ctx, ext->exts, lysp_ext_instance_free); |
Michal Vasko | 5fe75f1 | 2020-03-02 13:52:37 +0100 | [diff] [blame] | 180 | if (ext->compiled) { |
| 181 | lysc_extension_free(ctx, &ext->compiled); |
| 182 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 183 | } |
| 184 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 185 | /** |
| 186 | * @brief Free the parsed feature structure. |
| 187 | * |
| 188 | * @param[in] ctx Free context. |
| 189 | * @param[in] feat Parsed schema feature structure to free. Note that the structure itself is not freed. |
| 190 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 191 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 192 | lysp_feature_free(struct lysf_ctx *ctx, struct lysp_feature *feat) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 193 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 194 | lydict_remove(ctx->ctx, feat->name); |
| 195 | FREE_ARRAY(ctx->ctx, feat->iffeatures, lysp_qname_free); |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 196 | FREE_ARRAY(ctx, feat->iffeatures_c, lysc_iffeature_free); |
| 197 | LY_ARRAY_FREE(feat->depfeatures); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 198 | lydict_remove(ctx->ctx, feat->dsc); |
| 199 | lydict_remove(ctx->ctx, feat->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 200 | FREE_ARRAY(ctx, feat->exts, lysp_ext_instance_free); |
| 201 | } |
| 202 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 203 | /** |
| 204 | * @brief Free the parsed identity structure. |
| 205 | * |
| 206 | * @param[in] ctx Free context. |
| 207 | * @param[in] ident Parsed schema identity structure to free. Note that the structure itself is not freed. |
| 208 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 209 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 210 | lysp_ident_free(struct lysf_ctx *ctx, struct lysp_ident *ident) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 211 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 212 | lydict_remove(ctx->ctx, ident->name); |
| 213 | FREE_ARRAY(ctx->ctx, ident->iffeatures, lysp_qname_free); |
| 214 | FREE_STRINGS(ctx->ctx, ident->bases); |
| 215 | lydict_remove(ctx->ctx, ident->dsc); |
| 216 | lydict_remove(ctx->ctx, ident->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 217 | FREE_ARRAY(ctx, ident->exts, lysp_ext_instance_free); |
| 218 | } |
| 219 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 220 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 221 | lysp_restr_free(struct lysf_ctx *ctx, struct lysp_restr *restr) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 222 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 223 | lydict_remove(ctx->ctx, restr->arg.str); |
| 224 | lydict_remove(ctx->ctx, restr->emsg); |
| 225 | lydict_remove(ctx->ctx, restr->eapptag); |
| 226 | lydict_remove(ctx->ctx, restr->dsc); |
| 227 | lydict_remove(ctx->ctx, restr->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 228 | FREE_ARRAY(ctx, restr->exts, lysp_ext_instance_free); |
| 229 | } |
| 230 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 231 | /** |
| 232 | * @brief Free the parsed type enum item. |
| 233 | * |
| 234 | * @param[in] ctx Free context. |
| 235 | * @param[in] item Parsed schema type enum item to free. Note that the structure itself is not freed. |
| 236 | */ |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 237 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 238 | lysp_type_enum_free(struct lysf_ctx *ctx, struct lysp_type_enum *item) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 239 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 240 | lydict_remove(ctx->ctx, item->name); |
| 241 | lydict_remove(ctx->ctx, item->dsc); |
| 242 | lydict_remove(ctx->ctx, item->ref); |
| 243 | FREE_ARRAY(ctx->ctx, item->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 244 | FREE_ARRAY(ctx, item->exts, lysp_ext_instance_free); |
| 245 | } |
| 246 | |
David Sedlák | 3248810 | 2019-07-15 17:44:10 +0200 | [diff] [blame] | 247 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 248 | lysp_type_free(struct lysf_ctx *ctx, struct lysp_type *type) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 249 | { |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 250 | if (!type) { |
| 251 | return; |
| 252 | } |
| 253 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 254 | lydict_remove(ctx->ctx, type->name); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 255 | FREE_MEMBER(ctx, type->range, lysp_restr_free); |
| 256 | FREE_MEMBER(ctx, type->length, lysp_restr_free); |
| 257 | FREE_ARRAY(ctx, type->patterns, lysp_restr_free); |
| 258 | FREE_ARRAY(ctx, type->enums, lysp_type_enum_free); |
| 259 | FREE_ARRAY(ctx, type->bits, lysp_type_enum_free); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 260 | lyxp_expr_free(ctx->ctx, type->path); |
| 261 | FREE_STRINGS(ctx->ctx, type->bases); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 262 | FREE_ARRAY(ctx, type->types, lysp_type_free); |
| 263 | FREE_ARRAY(ctx, type->exts, lysp_ext_instance_free); |
| 264 | if (type->compiled) { |
| 265 | lysc_type_free(ctx, type->compiled); |
| 266 | } |
| 267 | } |
| 268 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 269 | /** |
| 270 | * @brief Free the parsed typedef structure. |
| 271 | * |
| 272 | * @param[in] ctx Free context. |
| 273 | * @param[in] tpdf Parsed schema typedef structure to free. Note that the structure itself is not freed. |
| 274 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 275 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 276 | lysp_tpdf_free(struct lysf_ctx *ctx, struct lysp_tpdf *tpdf) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 277 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 278 | lydict_remove(ctx->ctx, tpdf->name); |
| 279 | lydict_remove(ctx->ctx, tpdf->units); |
| 280 | lydict_remove(ctx->ctx, tpdf->dflt.str); |
| 281 | lydict_remove(ctx->ctx, tpdf->dsc); |
| 282 | lydict_remove(ctx->ctx, tpdf->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 283 | FREE_ARRAY(ctx, tpdf->exts, lysp_ext_instance_free); |
| 284 | |
| 285 | lysp_type_free(ctx, &tpdf->type); |
| 286 | |
| 287 | } |
| 288 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 289 | /** |
| 290 | * @brief Free the parsed grouping structure. |
| 291 | * |
| 292 | * @param[in] ctx Free context. |
| 293 | * @param[in] grp Parsed schema grouping structure to free. Note that the structure itself is not freed. |
| 294 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 295 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 296 | lysp_grp_free(struct lysf_ctx *ctx, struct lysp_node_grp *grp) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 297 | { |
| 298 | struct lysp_node *node, *next; |
| 299 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 300 | FREE_ARRAY(ctx, grp->typedefs, lysp_tpdf_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 301 | LY_LIST_FOR_SAFE((struct lysp_node *)grp->groupings, next, node) { |
| 302 | lysp_node_free(ctx, node); |
| 303 | } |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 304 | LY_LIST_FOR_SAFE(grp->child, next, node) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 305 | lysp_node_free(ctx, node); |
| 306 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 307 | LY_LIST_FOR_SAFE((struct lysp_node *)grp->actions, next, node) { |
| 308 | lysp_node_free(ctx, node); |
| 309 | } |
| 310 | LY_LIST_FOR_SAFE((struct lysp_node *)grp->notifs, next, node) { |
| 311 | lysp_node_free(ctx, node); |
| 312 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 313 | } |
| 314 | |
Radek Krejci | f09e4e8 | 2019-06-14 15:08:11 +0200 | [diff] [blame] | 315 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 316 | lysp_when_free(struct lysf_ctx *ctx, struct lysp_when *when) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 317 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 318 | lydict_remove(ctx->ctx, when->cond); |
| 319 | lydict_remove(ctx->ctx, when->dsc); |
| 320 | lydict_remove(ctx->ctx, when->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 321 | FREE_ARRAY(ctx, when->exts, lysp_ext_instance_free); |
| 322 | } |
| 323 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 324 | /** |
| 325 | * @brief Free the parsed augment structure. |
| 326 | * |
| 327 | * @param[in] ctx Free context. |
| 328 | * @param[in] aug Parsed schema augment structure to free. Note that the structure itself is not freed. |
| 329 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 330 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 331 | lysp_augment_free(struct lysf_ctx *ctx, struct lysp_node_augment *aug) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 332 | { |
| 333 | struct lysp_node *node, *next; |
| 334 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 335 | LY_LIST_FOR_SAFE(aug->child, next, node) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 336 | lysp_node_free(ctx, node); |
| 337 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 338 | LY_LIST_FOR_SAFE((struct lysp_node *)aug->actions, next, node) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 339 | lysp_node_free(ctx, node); |
| 340 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 341 | LY_LIST_FOR_SAFE((struct lysp_node *)aug->notifs, next, node) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 342 | lysp_node_free(ctx, node); |
| 343 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 344 | } |
| 345 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 346 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 347 | lysp_deviate_free(struct lysf_ctx *ctx, struct lysp_deviate *d) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 348 | { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 349 | struct lysp_deviate_add *add = (struct lysp_deviate_add *)d; |
| 350 | struct lysp_deviate_rpl *rpl = (struct lysp_deviate_rpl *)d; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 351 | |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 352 | if (!d) { |
| 353 | return; |
| 354 | } |
| 355 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 356 | FREE_ARRAY(ctx, d->exts, lysp_ext_instance_free); |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 357 | switch (d->mod) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 358 | case LYS_DEV_NOT_SUPPORTED: |
| 359 | /* nothing to do */ |
| 360 | break; |
| 361 | case LYS_DEV_ADD: |
| 362 | case LYS_DEV_DELETE: /* compatible for dynamically allocated data */ |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 363 | lydict_remove(ctx->ctx, add->units); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 364 | FREE_ARRAY(ctx, add->musts, lysp_restr_free); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 365 | FREE_ARRAY(ctx->ctx, add->uniques, lysp_qname_free); |
| 366 | FREE_ARRAY(ctx->ctx, add->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 367 | break; |
| 368 | case LYS_DEV_REPLACE: |
| 369 | FREE_MEMBER(ctx, rpl->type, lysp_type_free); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 370 | lydict_remove(ctx->ctx, rpl->units); |
| 371 | lysp_qname_free(ctx->ctx, &rpl->dflt); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 372 | break; |
| 373 | default: |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 374 | LOGINT(ctx->ctx); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 375 | break; |
| 376 | } |
| 377 | } |
| 378 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 379 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 380 | lysp_deviation_free(struct lysf_ctx *ctx, struct lysp_deviation *dev) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 381 | { |
| 382 | struct lysp_deviate *next, *iter; |
| 383 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 384 | lydict_remove(ctx->ctx, dev->nodeid); |
| 385 | lydict_remove(ctx->ctx, dev->dsc); |
| 386 | lydict_remove(ctx->ctx, dev->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 387 | LY_LIST_FOR_SAFE(dev->deviates, next, iter) { |
| 388 | lysp_deviate_free(ctx, iter); |
| 389 | free(iter); |
| 390 | } |
| 391 | FREE_ARRAY(ctx, dev->exts, lysp_ext_instance_free); |
| 392 | } |
| 393 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 394 | /** |
| 395 | * @brief Free the parsed refine structure. |
| 396 | * |
| 397 | * @param[in] ctx Free context. |
| 398 | * @param[in] ref Parsed schema refine structure to free. Note that the structure itself is not freed. |
| 399 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 400 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 401 | lysp_refine_free(struct lysf_ctx *ctx, struct lysp_refine *ref) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 402 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 403 | lydict_remove(ctx->ctx, ref->nodeid); |
| 404 | lydict_remove(ctx->ctx, ref->dsc); |
| 405 | lydict_remove(ctx->ctx, ref->ref); |
| 406 | FREE_ARRAY(ctx->ctx, ref->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 407 | FREE_ARRAY(ctx, ref->musts, lysp_restr_free); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 408 | lydict_remove(ctx->ctx, ref->presence); |
| 409 | FREE_ARRAY(ctx->ctx, ref->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 410 | FREE_ARRAY(ctx, ref->exts, lysp_ext_instance_free); |
| 411 | } |
| 412 | |
Radek Krejci | 2d7a47b | 2019-05-16 13:34:10 +0200 | [diff] [blame] | 413 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 414 | lysp_node_free(struct lysf_ctx *ctx, struct lysp_node *node) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 415 | { |
| 416 | struct lysp_node *child, *next; |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 417 | struct lysp_node_container *cont; |
| 418 | struct lysp_node_leaf *leaf; |
| 419 | struct lysp_node_leaflist *llist; |
| 420 | struct lysp_node_list *list; |
| 421 | struct lysp_node_choice *choice; |
| 422 | struct lysp_node_case *cas; |
| 423 | struct lysp_node_uses *uses; |
| 424 | struct lysp_node_action *act; |
| 425 | struct lysp_node_action_inout *inout; |
| 426 | struct lysp_node_notif *notif; |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 427 | struct lysp_restr *musts = lysp_node_musts(node); |
| 428 | struct lysp_when *when = lysp_node_when(node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 429 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 430 | lydict_remove(ctx->ctx, node->name); |
| 431 | lydict_remove(ctx->ctx, node->dsc); |
| 432 | lydict_remove(ctx->ctx, node->ref); |
| 433 | FREE_ARRAY(ctx->ctx, node->iffeatures, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 434 | FREE_ARRAY(ctx, node->exts, lysp_ext_instance_free); |
| 435 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 436 | FREE_MEMBER(ctx, when, lysp_when_free); |
| 437 | FREE_ARRAY(ctx, musts, lysp_restr_free); |
| 438 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 439 | switch (node->nodetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 440 | case LYS_CONTAINER: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 441 | cont = (struct lysp_node_container *)node; |
| 442 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 443 | lydict_remove(ctx->ctx, cont->presence); |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 444 | FREE_ARRAY(ctx, cont->typedefs, lysp_tpdf_free); |
| 445 | if (cont->groupings) { |
| 446 | LY_LIST_FOR_SAFE(&cont->groupings->node, next, child) { |
| 447 | lysp_node_free(ctx, child); |
| 448 | } |
| 449 | } |
| 450 | LY_LIST_FOR_SAFE(cont->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 451 | lysp_node_free(ctx, child); |
| 452 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 453 | if (cont->actions) { |
| 454 | LY_LIST_FOR_SAFE(&cont->actions->node, next, child) { |
| 455 | lysp_node_free(ctx, child); |
| 456 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 457 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 458 | if (cont->notifs) { |
| 459 | LY_LIST_FOR_SAFE(&cont->notifs->node, next, child) { |
| 460 | lysp_node_free(ctx, child); |
| 461 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 462 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 463 | break; |
| 464 | case LYS_LEAF: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 465 | leaf = (struct lysp_node_leaf *)node; |
| 466 | |
| 467 | lysp_type_free(ctx, &leaf->type); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 468 | lydict_remove(ctx->ctx, leaf->units); |
| 469 | lydict_remove(ctx->ctx, leaf->dflt.str); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 470 | break; |
| 471 | case LYS_LEAFLIST: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 472 | llist = (struct lysp_node_leaflist *)node; |
| 473 | |
| 474 | lysp_type_free(ctx, &llist->type); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 475 | lydict_remove(ctx->ctx, llist->units); |
| 476 | FREE_ARRAY(ctx->ctx, llist->dflts, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 477 | break; |
| 478 | case LYS_LIST: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 479 | list = (struct lysp_node_list *)node; |
| 480 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 481 | lydict_remove(ctx->ctx, list->key); |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 482 | FREE_ARRAY(ctx, list->typedefs, lysp_tpdf_free); |
| 483 | if (list->groupings) { |
| 484 | LY_LIST_FOR_SAFE(&list->groupings->node, next, child) { |
| 485 | lysp_node_free(ctx, child); |
| 486 | } |
| 487 | } |
| 488 | LY_LIST_FOR_SAFE(list->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 489 | lysp_node_free(ctx, child); |
| 490 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 491 | if (list->actions) { |
| 492 | LY_LIST_FOR_SAFE(&list->actions->node, next, child) { |
| 493 | lysp_node_free(ctx, child); |
| 494 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 495 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 496 | if (list->notifs) { |
| 497 | LY_LIST_FOR_SAFE(&list->notifs->node, next, child) { |
| 498 | lysp_node_free(ctx, child); |
| 499 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 500 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 501 | FREE_ARRAY(ctx->ctx, list->uniques, lysp_qname_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 502 | break; |
| 503 | case LYS_CHOICE: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 504 | choice = (struct lysp_node_choice *)node; |
| 505 | |
| 506 | LY_LIST_FOR_SAFE(choice->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 507 | lysp_node_free(ctx, child); |
| 508 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 509 | lydict_remove(ctx->ctx, choice->dflt.str); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 510 | break; |
| 511 | case LYS_CASE: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 512 | cas = (struct lysp_node_case *)node; |
| 513 | |
| 514 | LY_LIST_FOR_SAFE(cas->child, next, child) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 515 | lysp_node_free(ctx, child); |
| 516 | } |
| 517 | break; |
| 518 | case LYS_ANYDATA: |
| 519 | case LYS_ANYXML: |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 520 | /* nothing special to do */ |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 521 | break; |
| 522 | case LYS_USES: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 523 | uses = (struct lysp_node_uses *)node; |
| 524 | |
| 525 | FREE_ARRAY(ctx, uses->refines, lysp_refine_free); |
| 526 | if (uses->augments) { |
| 527 | LY_LIST_FOR_SAFE(&uses->augments->node, next, child) { |
| 528 | lysp_node_free(ctx, child); |
| 529 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 530 | } |
| 531 | break; |
| 532 | case LYS_RPC: |
| 533 | case LYS_ACTION: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 534 | act = (struct lysp_node_action *)node; |
| 535 | |
| 536 | FREE_ARRAY(ctx, act->typedefs, lysp_tpdf_free); |
| 537 | if (act->groupings) { |
| 538 | LY_LIST_FOR_SAFE(&act->groupings->node, next, child) { |
| 539 | lysp_node_free(ctx, child); |
| 540 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 541 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 542 | if (act->input.nodetype) { |
| 543 | lysp_node_free(ctx, &act->input.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 544 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 545 | if (act->output.nodetype) { |
| 546 | lysp_node_free(ctx, &act->output.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 547 | } |
| 548 | break; |
| 549 | case LYS_INPUT: |
| 550 | case LYS_OUTPUT: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 551 | inout = (struct lysp_node_action_inout *)node; |
| 552 | |
| 553 | FREE_ARRAY(ctx, inout->typedefs, lysp_tpdf_free); |
| 554 | if (inout->groupings) { |
| 555 | LY_LIST_FOR_SAFE(&inout->groupings->node, next, child) { |
| 556 | lysp_node_free(ctx, child); |
| 557 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 558 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 559 | LY_LIST_FOR_SAFE(inout->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 560 | lysp_node_free(ctx, child); |
| 561 | } |
| 562 | /* do not free the node, it is never standalone but part of the action node */ |
| 563 | return; |
| 564 | case LYS_NOTIF: |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 565 | notif = (struct lysp_node_notif *)node; |
| 566 | |
| 567 | FREE_ARRAY(ctx, notif->typedefs, lysp_tpdf_free); |
| 568 | if (notif->groupings) { |
| 569 | LY_LIST_FOR_SAFE(¬if->groupings->node, next, child) { |
| 570 | lysp_node_free(ctx, child); |
| 571 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 572 | } |
Michal Vasko | 856ea97 | 2021-06-09 09:44:30 +0200 | [diff] [blame] | 573 | LY_LIST_FOR_SAFE(notif->child, next, child) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 574 | lysp_node_free(ctx, child); |
| 575 | } |
| 576 | break; |
| 577 | case LYS_GROUPING: |
| 578 | lysp_grp_free(ctx, (struct lysp_node_grp *)node); |
| 579 | break; |
| 580 | case LYS_AUGMENT: |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 581 | lysp_augment_free(ctx, ((struct lysp_node_augment *)node)); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 582 | break; |
| 583 | default: |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 584 | LOGINT(ctx->ctx); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | free(node); |
| 588 | } |
| 589 | |
Radek Krejci | 15f10ab | 2020-11-03 14:14:14 +0100 | [diff] [blame] | 590 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 591 | lysp_module_free(struct lysf_ctx *ctx, struct lysp_module *module) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 592 | { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 593 | struct lysp_node *node, *next; |
| 594 | |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 595 | if (!module) { |
| 596 | return; |
| 597 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 598 | |
| 599 | FREE_ARRAY(ctx, module->imports, lysp_import_free); |
Radek Krejci | 771928a | 2021-01-19 13:42:36 +0100 | [diff] [blame] | 600 | FREE_ARRAY(ctx, module->includes, module->is_submod ? lysp_include_free_submodule : lysp_include_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 601 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 602 | FREE_ARRAY(ctx, module->revs, lysp_revision_free); |
| 603 | FREE_ARRAY(ctx, module->extensions, lysp_ext_free); |
| 604 | FREE_ARRAY(ctx, module->features, lysp_feature_free); |
| 605 | FREE_ARRAY(ctx, module->identities, lysp_ident_free); |
| 606 | FREE_ARRAY(ctx, module->typedefs, lysp_tpdf_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 607 | LY_LIST_FOR_SAFE((struct lysp_node *)module->groupings, next, node) { |
| 608 | lysp_node_free(ctx, node); |
| 609 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 610 | LY_LIST_FOR_SAFE(module->data, next, node) { |
| 611 | lysp_node_free(ctx, node); |
| 612 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 613 | LY_LIST_FOR_SAFE((struct lysp_node *)module->augments, next, node) { |
| 614 | lysp_node_free(ctx, node); |
| 615 | } |
| 616 | LY_LIST_FOR_SAFE((struct lysp_node *)module->rpcs, next, node) { |
| 617 | lysp_node_free(ctx, node); |
| 618 | } |
| 619 | LY_LIST_FOR_SAFE((struct lysp_node *)module->notifs, next, node) { |
| 620 | lysp_node_free(ctx, node); |
| 621 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 622 | FREE_ARRAY(ctx, module->deviations, lysp_deviation_free); |
| 623 | FREE_ARRAY(ctx, module->exts, lysp_ext_instance_free); |
| 624 | |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 625 | if (module->is_submod) { |
| 626 | struct lysp_submodule *submod = (struct lysp_submodule *)module; |
| 627 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 628 | lydict_remove(ctx->ctx, submod->name); |
| 629 | lydict_remove(ctx->ctx, submod->filepath); |
| 630 | lydict_remove(ctx->ctx, submod->prefix); |
| 631 | lydict_remove(ctx->ctx, submod->org); |
| 632 | lydict_remove(ctx->ctx, submod->contact); |
| 633 | lydict_remove(ctx->ctx, submod->dsc); |
| 634 | lydict_remove(ctx->ctx, submod->ref); |
Michal Vasko | 5d24f6c | 2020-10-13 13:49:06 +0200 | [diff] [blame] | 635 | } |
| 636 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 637 | free(module); |
| 638 | } |
| 639 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 640 | /** |
| 641 | * @brief Free the compiled extension definition and NULL the provided pointer. |
| 642 | * |
| 643 | * @param[in] ctx Free context. |
| 644 | * @param[in,out] ext Compiled extension definition to be freed. |
| 645 | */ |
| 646 | static void |
| 647 | lysc_extension_free(struct lysf_ctx *ctx, struct lysc_ext **ext) |
Michal Vasko | 6f4cbb6 | 2020-02-28 11:15:47 +0100 | [diff] [blame] | 648 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 649 | if (ly_set_contains(&ctx->ext_set, *ext, NULL)) { |
| 650 | /* already freed and only referenced again in this module */ |
Michal Vasko | 6f4cbb6 | 2020-02-28 11:15:47 +0100 | [diff] [blame] | 651 | return; |
| 652 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 653 | |
Michal Vasko | 6224d94 | 2022-09-19 12:32:47 +0200 | [diff] [blame] | 654 | /* remember this extension to be freed, nothing to do on error */ |
| 655 | (void)ly_set_add(&ctx->ext_set, *ext, 0, NULL); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 656 | |
| 657 | /* recursive exts free */ |
Michal Vasko | 6f4cbb6 | 2020-02-28 11:15:47 +0100 | [diff] [blame] | 658 | FREE_ARRAY(ctx, (*ext)->exts, lysc_ext_instance_free); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 659 | |
Radek Krejci | 720d261 | 2021-03-03 19:44:22 +0100 | [diff] [blame] | 660 | *ext = NULL; |
Michal Vasko | 6f4cbb6 | 2020-02-28 11:15:47 +0100 | [diff] [blame] | 661 | } |
| 662 | |
| 663 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 664 | lysc_ext_instance_free(struct lysf_ctx *ctx, struct lysc_ext_instance *ext) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 665 | { |
fredgan | ebc5057 | 2019-10-31 15:39:23 +0800 | [diff] [blame] | 666 | if (ext->def && ext->def->plugin && ext->def->plugin->free) { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 667 | ext->def->plugin->free(ctx->ctx, ext); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 668 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 669 | lydict_remove(ctx->ctx, ext->argument); |
Radek Krejci | 0935f41 | 2019-08-20 16:15:18 +0200 | [diff] [blame] | 670 | FREE_ARRAY(ctx, ext->exts, lysc_ext_instance_free); |
| 671 | } |
| 672 | |
| 673 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 674 | lysc_iffeature_free(struct lysf_ctx *UNUSED(ctx), struct lysc_iffeature *iff) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 675 | { |
| 676 | LY_ARRAY_FREE(iff->features); |
| 677 | free(iff->expr); |
| 678 | } |
| 679 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 680 | /** |
| 681 | * @brief Free the compiled when structure (decrease refcount) and NULL the provided pointer. |
| 682 | * |
| 683 | * @param[in] ctx Free context. |
| 684 | * @param[in] grp Parsed schema grouping structure to free. Note that the structure itself is not freed. |
| 685 | */ |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 686 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 687 | lysc_when_free(struct lysf_ctx *ctx, struct lysc_when **w) |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 688 | { |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 689 | if (--(*w)->refcount) { |
| 690 | return; |
| 691 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 692 | lyxp_expr_free(ctx->ctx, (*w)->cond); |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 693 | ly_free_prefix_data(LY_VALUE_SCHEMA_RESOLVED, (*w)->prefixes); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 694 | lydict_remove(ctx->ctx, (*w)->dsc); |
| 695 | lydict_remove(ctx->ctx, (*w)->ref); |
Radek Krejci | 00b874b | 2019-02-12 10:54:50 +0100 | [diff] [blame] | 696 | FREE_ARRAY(ctx, (*w)->exts, lysc_ext_instance_free); |
| 697 | free(*w); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 698 | } |
| 699 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 700 | /** |
| 701 | * @brief Free the compiled must structure. |
| 702 | * |
| 703 | * @param[in] ctx Free context. |
| 704 | * @param[in,out] must Compiled must structure to be freed. |
| 705 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 706 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 707 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 708 | lysc_must_free(struct lysf_ctx *ctx, struct lysc_must *must) |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 709 | { |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 710 | if (!must) { |
| 711 | return; |
| 712 | } |
| 713 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 714 | lyxp_expr_free(ctx->ctx, must->cond); |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 715 | ly_free_prefix_data(LY_VALUE_SCHEMA_RESOLVED, must->prefixes); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 716 | lydict_remove(ctx->ctx, must->emsg); |
| 717 | lydict_remove(ctx->ctx, must->eapptag); |
| 718 | lydict_remove(ctx->ctx, must->dsc); |
| 719 | lydict_remove(ctx->ctx, must->ref); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 720 | FREE_ARRAY(ctx, must->exts, lysc_ext_instance_free); |
| 721 | } |
| 722 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 723 | /** |
| 724 | * @brief Unlink the identity from all derived identity arrays. |
| 725 | * |
| 726 | * @param[in] ident Identity to unlink. |
| 727 | */ |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 728 | static void |
| 729 | lysc_ident_derived_unlink(const struct lysc_ident *ident) |
| 730 | { |
| 731 | LY_ARRAY_COUNT_TYPE u, v, w; |
| 732 | const struct lysp_submodule *submod; |
Michal Vasko | d84b813 | 2022-03-15 10:45:44 +0100 | [diff] [blame] | 733 | const struct lysp_module *base_pmod = NULL; |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 734 | const struct lysp_ident *identp = NULL; |
Michal Vasko | d6b5d4e | 2022-03-16 09:23:32 +0100 | [diff] [blame] | 735 | const struct lys_module *mod, *iter; |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 736 | const char *base_name; |
Michal Vasko | d6b5d4e | 2022-03-16 09:23:32 +0100 | [diff] [blame] | 737 | uint32_t i; |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 738 | |
| 739 | /* find the parsed identity */ |
| 740 | LY_ARRAY_FOR(ident->module->parsed->identities, u) { |
| 741 | if (ident->module->parsed->identities[u].name == ident->name) { |
| 742 | identp = &ident->module->parsed->identities[u]; |
| 743 | base_pmod = ident->module->parsed; |
| 744 | break; |
| 745 | } |
| 746 | } |
| 747 | if (!identp) { |
| 748 | LY_ARRAY_FOR(ident->module->parsed->includes, v) { |
| 749 | submod = ident->module->parsed->includes[v].submodule; |
| 750 | LY_ARRAY_FOR(submod->identities, u) { |
| 751 | if (submod->identities[u].name == ident->name) { |
| 752 | identp = &submod->identities[u]; |
| 753 | base_pmod = (struct lysp_module *)submod; |
| 754 | break; |
| 755 | } |
| 756 | } |
| 757 | } |
| 758 | } |
| 759 | assert(identp); |
| 760 | |
| 761 | /* remove link from all the foreign bases, it may not be there if identity compilation failed */ |
| 762 | LY_ARRAY_FOR(identp->bases, u) { |
| 763 | base_name = strchr(identp->bases[u], ':'); |
| 764 | if (!base_name) { |
| 765 | continue; |
| 766 | } |
| 767 | |
| 768 | /* prefixed identity */ |
| 769 | mod = ly_resolve_prefix(ident->module->ctx, identp->bases[u], base_name - identp->bases[u], LY_VALUE_SCHEMA, |
| 770 | (void *)base_pmod); |
| 771 | if (!mod) { |
| 772 | continue; |
| 773 | } |
| 774 | ++base_name; |
| 775 | |
Michal Vasko | d6b5d4e | 2022-03-16 09:23:32 +0100 | [diff] [blame] | 776 | i = 0; |
| 777 | while ((iter = ly_ctx_get_module_iter(ident->module->ctx, &i))) { |
| 778 | if (iter == mod) { |
| 779 | break; |
| 780 | } |
| 781 | } |
| 782 | if (!iter) { |
| 783 | /* target module was freed already */ |
| 784 | continue; |
| 785 | } |
| 786 | |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 787 | /* find the compiled base */ |
| 788 | LY_ARRAY_FOR(mod->identities, v) { |
| 789 | if (!strcmp(mod->identities[v].name, base_name)) { |
| 790 | /* find the derived link */ |
| 791 | LY_ARRAY_FOR(mod->identities[v].derived, w) { |
| 792 | if (mod->identities[v].derived[w] == ident) { |
| 793 | /* remove the link */ |
| 794 | LY_ARRAY_DECREMENT(mod->identities[v].derived); |
Michal Vasko | 3fedda1 | 2022-03-16 09:23:45 +0100 | [diff] [blame] | 795 | if (!LY_ARRAY_COUNT(mod->identities[v].derived)) { |
| 796 | LY_ARRAY_FREE(mod->identities[v].derived); |
| 797 | mod->identities[v].derived = NULL; |
| 798 | } else if (w < LY_ARRAY_COUNT(mod->identities[v].derived)) { |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 799 | memmove(mod->identities[v].derived + w, mod->identities[v].derived + w + 1, |
| 800 | (LY_ARRAY_COUNT(mod->identities[v].derived) - w) * sizeof ident); |
| 801 | } |
| 802 | break; |
| 803 | } |
| 804 | } |
| 805 | break; |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | } |
| 810 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 811 | /** |
| 812 | * @brief Free the compiled identity structure. |
| 813 | * |
| 814 | * @param[in] ctx Free context. |
| 815 | * @param[in,out] ident Compiled identity structure to be freed. |
| 816 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 817 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 818 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 819 | lysc_ident_free(struct lysf_ctx *ctx, struct lysc_ident *ident) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 820 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 821 | lydict_remove(ctx->ctx, ident->name); |
| 822 | lydict_remove(ctx->ctx, ident->dsc); |
| 823 | lydict_remove(ctx->ctx, ident->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 824 | LY_ARRAY_FREE(ident->derived); |
| 825 | FREE_ARRAY(ctx, ident->exts, lysc_ext_instance_free); |
| 826 | } |
| 827 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 828 | /** |
| 829 | * @brief Free the compiled range structure. |
| 830 | * |
| 831 | * @param[in] ctx Free context. |
| 832 | * @param[in,out] range Compiled range structure to be freed. |
| 833 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 834 | */ |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 835 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 836 | lysc_range_free(struct lysf_ctx *ctx, struct lysc_range *range) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 837 | { |
| 838 | LY_ARRAY_FREE(range->parts); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 839 | lydict_remove(ctx->ctx, range->eapptag); |
| 840 | lydict_remove(ctx->ctx, range->emsg); |
| 841 | lydict_remove(ctx->ctx, range->dsc); |
| 842 | lydict_remove(ctx->ctx, range->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 843 | FREE_ARRAY(ctx, range->exts, lysc_ext_instance_free); |
| 844 | } |
| 845 | |
Michal Vasko | 51de7b7 | 2022-04-29 09:50:22 +0200 | [diff] [blame] | 846 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 847 | lysc_pattern_free(struct lysf_ctx *ctx, struct lysc_pattern **pattern) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 848 | { |
| 849 | if (--(*pattern)->refcount) { |
| 850 | return; |
| 851 | } |
Radek Krejci | 5457946 | 2019-04-30 12:47:06 +0200 | [diff] [blame] | 852 | pcre2_code_free((*pattern)->code); |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 853 | lydict_remove(ctx->ctx, (*pattern)->expr); |
| 854 | lydict_remove(ctx->ctx, (*pattern)->eapptag); |
| 855 | lydict_remove(ctx->ctx, (*pattern)->emsg); |
| 856 | lydict_remove(ctx->ctx, (*pattern)->dsc); |
| 857 | lydict_remove(ctx->ctx, (*pattern)->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 858 | FREE_ARRAY(ctx, (*pattern)->exts, lysc_ext_instance_free); |
| 859 | free(*pattern); |
| 860 | } |
| 861 | |
Michal Vasko | f4fa90d | 2021-11-11 15:05:19 +0100 | [diff] [blame] | 862 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 863 | lysc_enum_item_free(struct lysf_ctx *ctx, struct lysc_type_bitenum_item *item) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 864 | { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 865 | lydict_remove(ctx->ctx, item->name); |
| 866 | lydict_remove(ctx->ctx, item->dsc); |
| 867 | lydict_remove(ctx->ctx, item->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 868 | FREE_ARRAY(ctx, item->exts, lysc_ext_instance_free); |
| 869 | } |
| 870 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 871 | /** |
| 872 | * @brief Free the compiled type structure. |
| 873 | * |
| 874 | * @param[in] ctx Free context. |
| 875 | * @param[in,out] type Pointer to compiled type structure to be freed. |
| 876 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 877 | */ |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 878 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 879 | lysc_type2_free(struct lysf_ctx *ctx, struct lysc_type **type) |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 880 | { |
| 881 | lysc_type_free(ctx, *type); |
| 882 | } |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 883 | |
Radek Krejci | cdfecd9 | 2018-11-26 11:27:32 +0100 | [diff] [blame] | 884 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 885 | lysc_type_free(struct lysf_ctx *ctx, struct lysc_type *type) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 886 | { |
Michal Vasko | d15c7de | 2022-05-09 15:34:09 +0200 | [diff] [blame] | 887 | if (!type || (LY_ATOMIC_DEC_BARRIER(type->refcount) > 1)) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 888 | return; |
| 889 | } |
Radek Krejci | b915ac9 | 2020-08-14 23:31:04 +0200 | [diff] [blame] | 890 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 891 | switch (type->basetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 892 | case LY_TYPE_BINARY: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 893 | FREE_MEMBER(ctx, ((struct lysc_type_bin *)type)->length, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 894 | break; |
| 895 | case LY_TYPE_BITS: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 896 | 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] | 897 | break; |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 898 | case LY_TYPE_DEC64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 899 | FREE_MEMBER(ctx, ((struct lysc_type_dec *)type)->range, lysc_range_free); |
Radek Krejci | 6cba429 | 2018-11-15 17:33:29 +0100 | [diff] [blame] | 900 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 901 | case LY_TYPE_STRING: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 902 | FREE_MEMBER(ctx, ((struct lysc_type_str *)type)->length, lysc_range_free); |
| 903 | FREE_ARRAY(ctx, ((struct lysc_type_str *)type)->patterns, lysc_pattern_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 904 | break; |
| 905 | case LY_TYPE_ENUM: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 906 | FREE_ARRAY(ctx, ((struct lysc_type_enum *)type)->enums, lysc_enum_item_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 907 | break; |
| 908 | case LY_TYPE_INT8: |
| 909 | case LY_TYPE_UINT8: |
| 910 | case LY_TYPE_INT16: |
| 911 | case LY_TYPE_UINT16: |
| 912 | case LY_TYPE_INT32: |
| 913 | case LY_TYPE_UINT32: |
| 914 | case LY_TYPE_INT64: |
| 915 | case LY_TYPE_UINT64: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 916 | FREE_MEMBER(ctx, ((struct lysc_type_num *)type)->range, lysc_range_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 917 | break; |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 918 | case LY_TYPE_IDENT: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 919 | LY_ARRAY_FREE(((struct lysc_type_identityref *)type)->bases); |
Radek Krejci | 555cb5b | 2018-11-16 14:54:33 +0100 | [diff] [blame] | 920 | break; |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 921 | case LY_TYPE_UNION: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 922 | FREE_ARRAY(ctx, ((struct lysc_type_union *)type)->types, lysc_type2_free); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 923 | break; |
| 924 | case LY_TYPE_LEAFREF: |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 925 | lyxp_expr_free(ctx->ctx, ((struct lysc_type_leafref *)type)->path); |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 926 | ly_free_prefix_data(LY_VALUE_SCHEMA_RESOLVED, ((struct lysc_type_leafref *)type)->prefixes); |
Michal Vasko | d15c7de | 2022-05-09 15:34:09 +0200 | [diff] [blame] | 927 | lysc_type_free(ctx, ((struct lysc_type_leafref *)type)->realtype); |
Radek Krejci | a304538 | 2018-11-22 14:30:31 +0100 | [diff] [blame] | 928 | break; |
Radek Krejci | 16c0f82 | 2018-11-16 10:46:10 +0100 | [diff] [blame] | 929 | case LY_TYPE_INST: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 930 | case LY_TYPE_BOOL: |
| 931 | case LY_TYPE_EMPTY: |
Radek Krejci | 4369923 | 2018-11-23 14:59:46 +0100 | [diff] [blame] | 932 | case LY_TYPE_UNKNOWN: |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 933 | /* nothing to do */ |
| 934 | break; |
| 935 | } |
Michal Vasko | ba99a3e | 2020-08-18 15:50:05 +0200 | [diff] [blame] | 936 | |
| 937 | FREE_ARRAY(ctx, type->exts, lysc_ext_instance_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 938 | free(type); |
| 939 | } |
| 940 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 941 | /** |
| 942 | * @brief Free the compiled input/output structure. |
| 943 | * |
| 944 | * @param[in] ctx Free context. |
| 945 | * @param[in,out] inout Compiled inout structure to be freed. |
| 946 | * Since the structure is part of the RPC/action structure, it is not freed itself. |
| 947 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 948 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 949 | lysc_node_action_inout_free(struct lysf_ctx *ctx, struct lysc_node_action_inout *inout) |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 950 | { |
| 951 | struct lysc_node *child, *child_next; |
| 952 | |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 953 | FREE_ARRAY(ctx, inout->musts, lysc_must_free); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 954 | LY_LIST_FOR_SAFE(inout->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 955 | lysc_node_free_(ctx, child); |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 956 | } |
| 957 | } |
| 958 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 959 | /** |
| 960 | * @brief Free the compiled RPC/action structure. |
| 961 | * |
| 962 | * @param[in] ctx Free context. |
| 963 | * @param[in,out] action Compiled RPC/action structure to be freed. |
| 964 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 965 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 966 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 967 | lysc_node_action_free(struct lysf_ctx *ctx, struct lysc_node_action *action) |
Radek Krejci | f538ce5 | 2019-03-05 10:46:14 +0100 | [diff] [blame] | 968 | { |
Michal Vasko | 37a0fe6 | 2021-02-03 09:53:04 +0100 | [diff] [blame] | 969 | FREE_ARRAY(ctx, action->when, lysc_when_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 970 | if (action->input.nodetype) { |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 971 | lysc_node_free_(ctx, &action->input.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 972 | } |
| 973 | if (action->output.nodetype) { |
Michal Vasko | 14ed9cd | 2021-01-28 14:16:25 +0100 | [diff] [blame] | 974 | lysc_node_free_(ctx, &action->output.node); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 975 | } |
Radek Krejci | 6eeb58f | 2019-02-22 16:29:37 +0100 | [diff] [blame] | 976 | } |
| 977 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 978 | /** |
| 979 | * @brief Free the compiled notification structure. |
| 980 | * |
| 981 | * @param[in] ctx Free context. |
| 982 | * @param[in,out] notif Compiled notification structure to be freed. |
| 983 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 984 | */ |
Michal Vasko | 12ef536 | 2022-09-16 15:13:58 +0200 | [diff] [blame] | 985 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 986 | lysc_node_notif_free(struct lysf_ctx *ctx, struct lysc_node_notif *notif) |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 987 | { |
| 988 | struct lysc_node *child, *child_next; |
| 989 | |
Michal Vasko | 37a0fe6 | 2021-02-03 09:53:04 +0100 | [diff] [blame] | 990 | FREE_ARRAY(ctx, notif->when, lysc_when_free); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 991 | FREE_ARRAY(ctx, notif->musts, lysc_must_free); |
Radek Krejci | 01180ac | 2021-01-27 08:48:22 +0100 | [diff] [blame] | 992 | LY_LIST_FOR_SAFE(notif->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 993 | lysc_node_free_(ctx, child); |
Radek Krejci | fc11bd7 | 2019-04-11 16:00:05 +0200 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | |
Radek Krejci | f2de0ed | 2019-05-02 14:13:18 +0200 | [diff] [blame] | 997 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 998 | lysc_node_container_free(struct lysf_ctx *ctx, struct lysc_node_container *node) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 999 | { |
| 1000 | struct lysc_node *child, *child_next; |
| 1001 | |
| 1002 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1003 | lysc_node_free_(ctx, child); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1004 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1005 | LY_LIST_FOR_SAFE((struct lysc_node *)node->actions, child_next, child) { |
| 1006 | lysc_node_free_(ctx, child); |
| 1007 | } |
| 1008 | LY_LIST_FOR_SAFE((struct lysc_node *)node->notifs, child_next, child) { |
| 1009 | lysc_node_free_(ctx, child); |
| 1010 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1011 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 1012 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1013 | } |
| 1014 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1015 | /** |
| 1016 | * @brief Free the compiled leaf structure. |
| 1017 | * |
| 1018 | * @param[in] ctx Free context. |
| 1019 | * @param[in,out] node Compiled leaf structure to be freed. |
| 1020 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 1021 | */ |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1022 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1023 | lysc_node_leaf_free(struct lysf_ctx *ctx, struct lysc_node_leaf *node) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1024 | { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1025 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 58d171e | 2018-11-23 13:50:55 +0100 | [diff] [blame] | 1026 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1027 | if (node->type) { |
| 1028 | lysc_type_free(ctx, node->type); |
| 1029 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1030 | lydict_remove(ctx->ctx, node->units); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 1031 | if (node->dflt) { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1032 | node->dflt->realtype->plugin->free(ctx->ctx, node->dflt); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 1033 | lysc_type_free(ctx, (struct lysc_type *)node->dflt->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 1034 | free(node->dflt); |
| 1035 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1036 | } |
| 1037 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1038 | /** |
| 1039 | * @brief Free the compiled leaflist structure. |
| 1040 | * |
| 1041 | * @param[in] ctx Free context. |
| 1042 | * @param[in,out] node Compiled leaflist structure to be freed. |
| 1043 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 1044 | */ |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 1045 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1046 | lysc_node_leaflist_free(struct lysf_ctx *ctx, struct lysc_node_leaflist *node) |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 1047 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1048 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 1049 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1050 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 1051 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 1052 | if (node->type) { |
| 1053 | lysc_type_free(ctx, node->type); |
| 1054 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1055 | lydict_remove(ctx->ctx, node->units); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 1056 | LY_ARRAY_FOR(node->dflts, u) { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1057 | node->dflts[u]->realtype->plugin->free(ctx->ctx, node->dflts[u]); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 1058 | lysc_type_free(ctx, (struct lysc_type *)node->dflts[u]->realtype); |
Radek Krejci | a191122 | 2019-07-22 17:24:50 +0200 | [diff] [blame] | 1059 | free(node->dflts[u]); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 1060 | } |
| 1061 | LY_ARRAY_FREE(node->dflts); |
| 1062 | } |
| 1063 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1064 | /** |
| 1065 | * @brief Free the compiled list structure. |
| 1066 | * |
| 1067 | * @param[in] ctx Free context. |
| 1068 | * @param[in,out] node Compiled list structure to be freed. |
| 1069 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 1070 | */ |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1071 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1072 | lysc_node_list_free(struct lysf_ctx *ctx, struct lysc_node_list *node) |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1073 | { |
Michal Vasko | fd69e1d | 2020-07-03 11:57:17 +0200 | [diff] [blame] | 1074 | LY_ARRAY_COUNT_TYPE u; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1075 | struct lysc_node *child, *child_next; |
| 1076 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1077 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1078 | lysc_node_free_(ctx, child); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1079 | } |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1080 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1081 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
| 1082 | |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1083 | LY_ARRAY_FOR(node->uniques, u) { |
| 1084 | LY_ARRAY_FREE(node->uniques[u]); |
| 1085 | } |
| 1086 | LY_ARRAY_FREE(node->uniques); |
| 1087 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1088 | LY_LIST_FOR_SAFE((struct lysc_node *)node->actions, child_next, child) { |
| 1089 | lysc_node_free_(ctx, child); |
| 1090 | } |
| 1091 | LY_LIST_FOR_SAFE((struct lysc_node *)node->notifs, child_next, child) { |
| 1092 | lysc_node_free_(ctx, child); |
| 1093 | } |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1094 | } |
| 1095 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1096 | /** |
| 1097 | * @brief Free the compiled choice structure. |
| 1098 | * |
| 1099 | * @param[in] ctx Free context. |
| 1100 | * @param[in,out] node Compiled choice structure to be freed. |
| 1101 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 1102 | */ |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1103 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1104 | lysc_node_choice_free(struct lysf_ctx *ctx, struct lysc_node_choice *node) |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1105 | { |
| 1106 | struct lysc_node *child, *child_next; |
| 1107 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1108 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 1109 | LY_LIST_FOR_SAFE((struct lysc_node *)node->cases, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1110 | lysc_node_free_(ctx, child); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 1111 | } |
| 1112 | } |
| 1113 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1114 | /** |
| 1115 | * @brief Free the compiled case structure. |
| 1116 | * |
| 1117 | * @param[in] ctx Free context. |
| 1118 | * @param[in,out] node Compiled case structure to be freed. |
| 1119 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 1120 | */ |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 1121 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1122 | lysc_node_case_free(struct lysf_ctx *ctx, struct lysc_node_case *node) |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 1123 | { |
| 1124 | struct lysc_node *child, *child_next; |
| 1125 | |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1126 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 1127 | LY_LIST_FOR_SAFE(node->child, child_next, child) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1128 | lysc_node_free_(ctx, child); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1129 | } |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1130 | } |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1131 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1132 | /** |
| 1133 | * @brief Free the compiled anyxml/anydata structure. |
| 1134 | * |
| 1135 | * @param[in] ctx Free context. |
| 1136 | * @param[in,out] node Compiled anyxml/anydata structure to be freed. |
| 1137 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 1138 | */ |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1139 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1140 | lysc_node_anydata_free(struct lysf_ctx *ctx, struct lysc_node_anydata *node) |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1141 | { |
Radek Krejci | 9a3823e | 2021-01-27 20:26:46 +0100 | [diff] [blame] | 1142 | FREE_ARRAY(ctx, node->when, lysc_when_free); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1143 | FREE_ARRAY(ctx, node->musts, lysc_must_free); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1144 | } |
| 1145 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1146 | /** |
| 1147 | * @brief Free the compiled node structure. |
| 1148 | * |
| 1149 | * @param[in] ctx Free context. |
| 1150 | * @param[in,out] node Compiled node structure to be freed. |
| 1151 | * Since the structure is typically part of the sized array, the structure itself is not freed. |
| 1152 | */ |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1153 | static void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1154 | lysc_node_free_(struct lysf_ctx *ctx, struct lysc_node *node) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1155 | { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1156 | ly_bool inout = 0; |
| 1157 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1158 | /* common part */ |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1159 | lydict_remove(ctx->ctx, node->name); |
| 1160 | lydict_remove(ctx->ctx, node->dsc); |
| 1161 | lydict_remove(ctx->ctx, node->ref); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1162 | |
| 1163 | /* nodetype-specific part */ |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1164 | switch (node->nodetype) { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1165 | case LYS_CONTAINER: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1166 | lysc_node_container_free(ctx, (struct lysc_node_container *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1167 | break; |
| 1168 | case LYS_LEAF: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1169 | lysc_node_leaf_free(ctx, (struct lysc_node_leaf *)node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1170 | break; |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 1171 | case LYS_LEAFLIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1172 | lysc_node_leaflist_free(ctx, (struct lysc_node_leaflist *)node); |
Radek Krejci | 42452ac | 2018-11-28 17:09:52 +0100 | [diff] [blame] | 1173 | break; |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1174 | case LYS_LIST: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1175 | lysc_node_list_free(ctx, (struct lysc_node_list *)node); |
Radek Krejci | 9bb94eb | 2018-12-04 16:48:35 +0100 | [diff] [blame] | 1176 | break; |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1177 | case LYS_CHOICE: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1178 | lysc_node_choice_free(ctx, (struct lysc_node_choice *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1179 | break; |
| 1180 | case LYS_CASE: |
Michal Vasko | 20424b4 | 2020-08-31 12:29:38 +0200 | [diff] [blame] | 1181 | lysc_node_case_free(ctx, (struct lysc_node_case *)node); |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1182 | break; |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1183 | case LYS_ANYDATA: |
| 1184 | case LYS_ANYXML: |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1185 | lysc_node_anydata_free(ctx, (struct lysc_node_anydata *)node); |
Radek Krejci | 9800fb8 | 2018-12-13 14:26:23 +0100 | [diff] [blame] | 1186 | break; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1187 | case LYS_RPC: |
| 1188 | case LYS_ACTION: |
| 1189 | lysc_node_action_free(ctx, (struct lysc_node_action *)node); |
| 1190 | break; |
| 1191 | case LYS_INPUT: |
| 1192 | case LYS_OUTPUT: |
| 1193 | lysc_node_action_inout_free(ctx, (struct lysc_node_action_inout *)node); |
| 1194 | inout = 1; |
| 1195 | break; |
| 1196 | case LYS_NOTIF: |
| 1197 | lysc_node_notif_free(ctx, (struct lysc_node_notif *)node); |
| 1198 | break; |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1199 | default: |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1200 | LOGINT(ctx->ctx); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1201 | } |
| 1202 | |
Radek Krejci | 056d0a8 | 2018-12-06 16:57:25 +0100 | [diff] [blame] | 1203 | FREE_ARRAY(ctx, node->exts, lysc_ext_instance_free); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1204 | |
| 1205 | if (!inout) { |
| 1206 | free(node); |
| 1207 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1208 | } |
| 1209 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1210 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1211 | lysc_node_free(struct lysf_ctx *ctx, struct lysc_node *node, ly_bool unlink) |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1212 | { |
Michal Vasko | e02e740 | 2021-07-23 08:29:28 +0200 | [diff] [blame] | 1213 | struct lysc_node *next, *iter, **child_p; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1214 | |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1215 | if (node->nodetype & (LYS_INPUT | LYS_OUTPUT)) { |
Michal Vasko | e02e740 | 2021-07-23 08:29:28 +0200 | [diff] [blame] | 1216 | /* inouts are part of actions and cannot be unlinked/freed separately, we can only free all the children */ |
| 1217 | struct lysc_node_action_inout *inout = (struct lysc_node_action_inout *)node; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1218 | |
Michal Vasko | e02e740 | 2021-07-23 08:29:28 +0200 | [diff] [blame] | 1219 | LY_LIST_FOR_SAFE(inout->child, next, iter) { |
| 1220 | lysc_node_free_(ctx, iter); |
| 1221 | } |
| 1222 | inout->child = NULL; |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1223 | return; |
| 1224 | } |
| 1225 | |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1226 | if (unlink) { |
| 1227 | /* unlink from siblings */ |
| 1228 | if (node->prev->next) { |
| 1229 | node->prev->next = node->next; |
| 1230 | } |
| 1231 | if (node->next) { |
| 1232 | node->next->prev = node->prev; |
| 1233 | } else { |
| 1234 | /* unlinking the last node */ |
| 1235 | if (node->parent) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1236 | if (node->nodetype == LYS_ACTION) { |
| 1237 | iter = (struct lysc_node *)lysc_node_actions(node->parent); |
| 1238 | } else if (node->nodetype == LYS_NOTIF) { |
| 1239 | iter = (struct lysc_node *)lysc_node_notifs(node->parent); |
| 1240 | } else { |
Michal Vasko | 544e58a | 2021-01-28 14:33:41 +0100 | [diff] [blame] | 1241 | iter = (struct lysc_node *)lysc_node_child(node->parent); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1242 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1243 | LY_CHECK_ERR_RET(!iter, LOGINT(ctx->ctx), ); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1244 | } else if (node->nodetype == LYS_RPC) { |
| 1245 | iter = (struct lysc_node *)node->module->compiled->rpcs; |
| 1246 | } else if (node->nodetype == LYS_NOTIF) { |
| 1247 | iter = (struct lysc_node *)node->module->compiled->notifs; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1248 | } else { |
| 1249 | iter = node->module->compiled->data; |
| 1250 | } |
| 1251 | /* update the "last" pointer from the first node */ |
| 1252 | iter->prev = node->prev; |
| 1253 | } |
| 1254 | |
| 1255 | /* unlink from parent */ |
| 1256 | if (node->parent) { |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1257 | if (node->nodetype == LYS_ACTION) { |
| 1258 | child_p = (struct lysc_node **)lysc_node_actions_p(node->parent); |
| 1259 | } else if (node->nodetype == LYS_NOTIF) { |
| 1260 | child_p = (struct lysc_node **)lysc_node_notifs_p(node->parent); |
| 1261 | } else { |
Michal Vasko | 544e58a | 2021-01-28 14:33:41 +0100 | [diff] [blame] | 1262 | child_p = lysc_node_child_p(node->parent); |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1263 | } |
| 1264 | } else if (node->nodetype == LYS_RPC) { |
| 1265 | child_p = (struct lysc_node **)&node->module->compiled->rpcs; |
| 1266 | } else if (node->nodetype == LYS_NOTIF) { |
| 1267 | child_p = (struct lysc_node **)&node->module->compiled->notifs; |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1268 | } else { |
| 1269 | child_p = &node->module->compiled->data; |
| 1270 | } |
| 1271 | if (child_p && (*child_p == node)) { |
| 1272 | /* the node is the first child */ |
| 1273 | *child_p = node->next; |
| 1274 | } |
| 1275 | } |
| 1276 | |
| 1277 | lysc_node_free_(ctx, node); |
| 1278 | } |
| 1279 | |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 1280 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1281 | lysc_module_free(struct lysf_ctx *ctx, struct lysc_module *module) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1282 | { |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1283 | struct lysc_node *node, *node_next; |
| 1284 | |
Radek Krejci | 90ed21e | 2021-04-12 14:47:46 +0200 | [diff] [blame] | 1285 | if (!module) { |
| 1286 | return; |
| 1287 | } |
| 1288 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1289 | LY_LIST_FOR_SAFE(module->data, node_next, node) { |
Michal Vasko | 7b1ad1a | 2020-11-02 15:41:27 +0100 | [diff] [blame] | 1290 | lysc_node_free_(ctx, node); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1291 | } |
Radek Krejci | 2a9fc65 | 2021-01-22 17:44:34 +0100 | [diff] [blame] | 1292 | LY_LIST_FOR_SAFE((struct lysc_node *)module->rpcs, node_next, node) { |
| 1293 | lysc_node_free_(ctx, node); |
| 1294 | } |
| 1295 | LY_LIST_FOR_SAFE((struct lysc_node *)module->notifs, node_next, node) { |
| 1296 | lysc_node_free_(ctx, node); |
| 1297 | } |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1298 | FREE_ARRAY(ctx, module->exts, lysc_ext_instance_free); |
| 1299 | |
| 1300 | free(module); |
| 1301 | } |
| 1302 | |
| 1303 | void |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1304 | lys_module_free(struct lysf_ctx *ctx, struct lys_module *module, ly_bool remove_links) |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1305 | { |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 1306 | LY_ARRAY_COUNT_TYPE u; |
| 1307 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1308 | if (!module) { |
| 1309 | return; |
| 1310 | } |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 1311 | |
Michal Vasko | ee75760 | 2021-06-10 14:38:19 +0200 | [diff] [blame] | 1312 | assert(!module->implemented); |
| 1313 | assert(!module->compiled); |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1314 | |
Michal Vasko | 4f9da5e | 2022-03-14 13:11:26 +0100 | [diff] [blame] | 1315 | if (remove_links) { |
| 1316 | /* remove derived identity links */ |
| 1317 | LY_ARRAY_FOR(module->identities, u) { |
| 1318 | lysc_ident_derived_unlink(&module->identities[u]); |
| 1319 | } |
| 1320 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1321 | FREE_ARRAY(ctx, module->identities, lysc_ident_free); |
| 1322 | lysp_module_free(ctx, module->parsed); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1323 | |
Michal Vasko | 7f45cf2 | 2020-10-01 12:49:44 +0200 | [diff] [blame] | 1324 | LY_ARRAY_FREE(module->augmented_by); |
| 1325 | LY_ARRAY_FREE(module->deviated_by); |
| 1326 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1327 | lydict_remove(ctx->ctx, module->name); |
| 1328 | lydict_remove(ctx->ctx, module->revision); |
| 1329 | lydict_remove(ctx->ctx, module->ns); |
| 1330 | lydict_remove(ctx->ctx, module->prefix); |
| 1331 | lydict_remove(ctx->ctx, module->filepath); |
| 1332 | lydict_remove(ctx->ctx, module->org); |
| 1333 | lydict_remove(ctx->ctx, module->contact); |
| 1334 | lydict_remove(ctx->ctx, module->dsc); |
| 1335 | lydict_remove(ctx->ctx, module->ref); |
Radek Krejci | 0bcdaed | 2019-01-10 10:21:34 +0100 | [diff] [blame] | 1336 | |
Radek Krejci | 19a9610 | 2018-11-15 13:38:09 +0100 | [diff] [blame] | 1337 | free(module); |
| 1338 | } |
Michal Vasko | 33ff942 | 2020-07-03 09:50:39 +0200 | [diff] [blame] | 1339 | |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1340 | void |
| 1341 | lysf_ctx_erase(struct lysf_ctx *ctx) |
| 1342 | { |
| 1343 | struct lysc_ext *ext; |
| 1344 | uint32_t i; |
| 1345 | |
| 1346 | for (i = 0; i < ctx->ext_set.count; ++i) { |
| 1347 | ext = ctx->ext_set.objs[i]; |
| 1348 | |
| 1349 | lydict_remove(ctx->ctx, ext->name); |
| 1350 | lydict_remove(ctx->ctx, ext->argname); |
| 1351 | free(ext); |
| 1352 | } |
| 1353 | ly_set_erase(&ctx->ext_set, NULL); |
| 1354 | } |
| 1355 | |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 1356 | LIBYANG_API_DEF void |
Radek Krejci | 0b01330 | 2021-03-29 15:22:32 +0200 | [diff] [blame] | 1357 | lyplg_ext_instance_substatements_free(struct ly_ctx *ctx, struct lysc_ext_substmt *substmts) |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1358 | { |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1359 | LY_ARRAY_COUNT_TYPE u; |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1360 | struct lysf_ctx fctx = {.ctx = ctx}; |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1361 | |
| 1362 | LY_ARRAY_FOR(substmts, u) { |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1363 | if (!substmts[u].storage) { |
| 1364 | continue; |
| 1365 | } |
| 1366 | |
Michal Vasko | d989ba0 | 2020-08-24 10:59:24 +0200 | [diff] [blame] | 1367 | switch (substmts[u].stmt) { |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1368 | case LY_STMT_ACTION: |
| 1369 | case LY_STMT_ANYDATA: |
| 1370 | case LY_STMT_ANYXML: |
| 1371 | case LY_STMT_CONTAINER: |
| 1372 | case LY_STMT_CHOICE: |
| 1373 | case LY_STMT_LEAF: |
| 1374 | case LY_STMT_LEAF_LIST: |
| 1375 | case LY_STMT_LIST: |
| 1376 | case LY_STMT_NOTIFICATION: |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1377 | case LY_STMT_RPC: { |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1378 | struct lysc_node *child, *child_next; |
| 1379 | |
| 1380 | LY_LIST_FOR_SAFE(*((struct lysc_node **)substmts[u].storage), child_next, child) { |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1381 | lysc_node_free_(&fctx, child); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1382 | } |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1383 | *((struct lysc_node **)substmts[u].storage) = NULL; |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1384 | break; |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1385 | } |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1386 | case LY_STMT_GROUPING: { |
| 1387 | struct lysp_node_grp *grp, *grp_next; |
| 1388 | |
| 1389 | LY_LIST_FOR_SAFE(*((struct lysp_node_grp **)substmts[u].storage), grp_next, grp) { |
| 1390 | lysp_node_free(&fctx, &grp->node); |
| 1391 | } |
| 1392 | break; |
| 1393 | } |
| 1394 | case LY_STMT_USES: |
Radek Krejci | 6b88a46 | 2021-02-17 12:39:34 +0100 | [diff] [blame] | 1395 | case LY_STMT_CONFIG: |
| 1396 | case LY_STMT_STATUS: |
| 1397 | /* nothing to do */ |
| 1398 | break; |
Michal Vasko | 3ac60e5 | 2022-09-05 11:08:31 +0200 | [diff] [blame] | 1399 | case LY_STMT_CONTACT: |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1400 | case LY_STMT_DESCRIPTION: |
Michal Vasko | 3ac60e5 | 2022-09-05 11:08:31 +0200 | [diff] [blame] | 1401 | case LY_STMT_ERROR_APP_TAG: |
| 1402 | case LY_STMT_ERROR_MESSAGE: |
| 1403 | case LY_STMT_KEY: |
| 1404 | case LY_STMT_NAMESPACE: |
| 1405 | case LY_STMT_ORGANIZATION: |
| 1406 | case LY_STMT_PRESENCE: |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1407 | case LY_STMT_REFERENCE: |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1408 | case LY_STMT_UNITS: |
| 1409 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1410 | /* single item */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1411 | const char *str = *((const char **)substmts[u].storage); |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1412 | |
Michal Vasko | e180ed0 | 2021-02-05 16:31:20 +0100 | [diff] [blame] | 1413 | lydict_remove(ctx, str); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1414 | } else { |
| 1415 | /* multiple items */ |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1416 | const char **strs = *((const char ***)substmts[u].storage); |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1417 | |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1418 | FREE_STRINGS(ctx, strs); |
| 1419 | } |
| 1420 | break; |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1421 | case LY_STMT_MUST: |
| 1422 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1423 | /* single item */ |
| 1424 | struct lysc_must *must = *((struct lysc_must **)substmts[u].storage); |
| 1425 | |
| 1426 | lysc_must_free(&fctx, must); |
| 1427 | free(must); |
| 1428 | } else { |
| 1429 | /* multiple items */ |
| 1430 | struct lysc_must *musts = *((struct lysc_must **)substmts[u].storage); |
| 1431 | |
| 1432 | FREE_ARRAY(&fctx, musts, lysc_must_free); |
| 1433 | } |
| 1434 | break; |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1435 | case LY_STMT_IF_FEATURE: { |
Michal Vasko | 22df3f0 | 2020-08-24 13:29:22 +0200 | [diff] [blame] | 1436 | struct lysc_iffeature *iff = *((struct lysc_iffeature **)substmts[u].storage); |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 1437 | |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1438 | if (!iff) { |
| 1439 | break; |
| 1440 | } |
| 1441 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1442 | /* single item */ |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1443 | lysc_iffeature_free(&fctx, iff); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1444 | free(iff); |
| 1445 | } else { |
| 1446 | /* multiple items */ |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1447 | FREE_ARRAY(&fctx, iff, lysc_iffeature_free); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1448 | } |
| 1449 | break; |
| 1450 | } |
Michal Vasko | edb0fa5 | 2022-10-04 10:36:00 +0200 | [diff] [blame] | 1451 | case LY_STMT_TYPEDEF: { |
| 1452 | struct lysp_tpdf *tpdf = *((struct lysp_tpdf **)substmts[u].storage); |
| 1453 | |
| 1454 | if (!tpdf) { |
| 1455 | break; |
| 1456 | } |
| 1457 | /* always an array */ |
| 1458 | FREE_ARRAY(&fctx, tpdf, lysp_tpdf_free); |
| 1459 | break; |
| 1460 | } |
Michal Vasko | f8647fa | 2022-09-05 11:07:54 +0200 | [diff] [blame] | 1461 | case LY_STMT_TYPE: |
| 1462 | if (substmts[u].cardinality < LY_STMT_CARD_SOME) { |
| 1463 | /* single item */ |
| 1464 | struct lysc_type *type = *((struct lysc_type **)substmts[u].storage); |
| 1465 | |
| 1466 | if (!type) { |
| 1467 | break; |
| 1468 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1469 | lysc_type_free(&fctx, type); |
Michal Vasko | f8647fa | 2022-09-05 11:07:54 +0200 | [diff] [blame] | 1470 | } else { |
| 1471 | /* multiple items */ |
| 1472 | struct lysc_type **types = *((struct lysc_type ***)substmts[u].storage); |
| 1473 | |
| 1474 | if (!types) { |
| 1475 | break; |
| 1476 | } |
Michal Vasko | c636ea4 | 2022-09-16 10:20:31 +0200 | [diff] [blame] | 1477 | FREE_ARRAY(&fctx, types, lysc_type2_free); |
Michal Vasko | f8647fa | 2022-09-05 11:07:54 +0200 | [diff] [blame] | 1478 | } |
| 1479 | break; |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1480 | |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 1481 | /* TODO other statements */ |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1482 | default: |
| 1483 | LOGINT(ctx); |
| 1484 | } |
| 1485 | } |
Radek Krejci | 1b2eef8 | 2021-02-17 11:17:27 +0100 | [diff] [blame] | 1486 | |
| 1487 | LY_ARRAY_FREE(substmts); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 1488 | } |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1489 | |
| 1490 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1491 | yang_parser_ctx_free(struct lys_yang_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1492 | { |
| 1493 | if (ctx) { |
aPiecek | 8d4e75d | 2021-06-24 14:47:06 +0200 | [diff] [blame] | 1494 | if (ctx->main_ctx == (struct lys_parser_ctx *)ctx) { |
| 1495 | ly_set_erase(&ctx->tpdfs_nodes, NULL); |
| 1496 | ly_set_erase(&ctx->grps_nodes, NULL); |
| 1497 | } |
Michal Vasko | dd6d5a3 | 2022-07-14 13:54:58 +0200 | [diff] [blame] | 1498 | assert(!ctx->tpdfs_nodes.count && !ctx->grps_nodes.count); |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 1499 | ly_set_rm_index(ctx->parsed_mods, ctx->parsed_mods->count - 1, NULL); |
| 1500 | if (!ctx->parsed_mods->count) { |
| 1501 | ly_set_free(ctx->parsed_mods, NULL); |
| 1502 | } |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1503 | free(ctx); |
| 1504 | } |
| 1505 | } |
| 1506 | |
| 1507 | void |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1508 | yin_parser_ctx_free(struct lys_yin_parser_ctx *ctx) |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1509 | { |
| 1510 | if (ctx) { |
aPiecek | 8d4e75d | 2021-06-24 14:47:06 +0200 | [diff] [blame] | 1511 | if (ctx->main_ctx == (struct lys_parser_ctx *)ctx) { |
| 1512 | ly_set_erase(&ctx->tpdfs_nodes, NULL); |
| 1513 | ly_set_erase(&ctx->grps_nodes, NULL); |
| 1514 | } |
Michal Vasko | dd6d5a3 | 2022-07-14 13:54:58 +0200 | [diff] [blame] | 1515 | assert(!ctx->tpdfs_nodes.count && !ctx->grps_nodes.count); |
Michal Vasko | 8a67eff | 2021-12-07 14:04:47 +0100 | [diff] [blame] | 1516 | ly_set_rm_index(ctx->parsed_mods, ctx->parsed_mods->count - 1, NULL); |
| 1517 | if (!ctx->parsed_mods->count) { |
| 1518 | ly_set_free(ctx->parsed_mods, NULL); |
| 1519 | } |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame] | 1520 | lyxml_ctx_free(ctx->xmlctx); |
David Sedlák | ebd3acf | 2019-07-26 15:04:32 +0200 | [diff] [blame] | 1521 | free(ctx); |
| 1522 | } |
| 1523 | } |