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