blob: d79164b9be0bfb1e7b5ee7b0aaef1c316c3789b1 [file] [log] [blame]
Michal Vaskoc636ea42022-09-16 10:20:31 +02001/**
2 * @file tree_schema_free.h
3 * @author Michal Vasko <mvasko@cesnet.cz>
4 * @brief internal freeing functions for YANG schema trees.
5 *
6 * Copyright (c) 2015 - 2022 CESNET, z.s.p.o.
7 *
8 * This source code is licensed under BSD 3-Clause License (the "License").
9 * You may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * https://opensource.org/licenses/BSD-3-Clause
13 */
14
15#ifndef LY_TREE_SCHEMA_FREE_H_
16#define LY_TREE_SCHEMA_FREE_H_
17
18#include "set.h"
19#include "tree_schema.h"
20
Michal Vaskod0625d72022-10-06 15:02:50 +020021struct lysp_yang_ctx;
22struct lysp_yin_ctx;
Michal Vaskoc636ea42022-09-16 10:20:31 +020023
24struct lysf_ctx {
25 struct ly_ctx *ctx;
26 struct lys_module *mod;
27 struct ly_set ext_set;
28};
29
30/**
31 * @brief Macro to free [sized array](@ref sizedarrays) of items using the provided free function. The ARRAY itself is also freed,
32 * but the memory is not sanitized.
33 */
34#define FREE_ARRAY(CTX, ARRAY, FUNC) {LY_ARRAY_COUNT_TYPE c__; LY_ARRAY_FOR(ARRAY, c__){(FUNC)(CTX, &(ARRAY)[c__]);}LY_ARRAY_FREE(ARRAY);}
35
36/**
37 * @brief Macro to free the specified MEMBER of a structure using the provided free function. The memory is not sanitized.
38 */
39#define FREE_MEMBER(CTX, MEMBER, FUNC) if (MEMBER) {(FUNC)(CTX, MEMBER);free(MEMBER);}
40
41/**
42 * @brief Macro to free [sized array](@ref sizedarrays) of strings stored in the context's dictionary. The ARRAY itself is also freed,
43 * but the memory is not sanitized.
44 */
45#define FREE_STRINGS(CTX, ARRAY) {LY_ARRAY_COUNT_TYPE c__; LY_ARRAY_FOR(ARRAY, c__){lydict_remove(CTX, ARRAY[c__]);}LY_ARRAY_FREE(ARRAY);}
46
47/**
48 * @brief Free a parsed qualified name.
49 *
50 * @param[in] ctx libyang context.
51 * @param[in] qname Qualified name to free.
52 */
Michal Vasko193dacd2022-10-13 08:43:05 +020053void lysp_qname_free(const struct ly_ctx *ctx, struct lysp_qname *qname);
Michal Vaskoc636ea42022-09-16 10:20:31 +020054
55/**
56 * @brief Free the parsed extension instance structure.
57 *
58 * @param[in] ctx Free context.
59 * @param[in] ext Parsed extension instance structure to free. Note that the instance itself is not freed.
60 */
61void lysp_ext_instance_free(struct lysf_ctx *ctx, struct lysp_ext_instance *ext);
62
63/**
64 * @brief Free a parsed restriction.
65 *
66 * @param[in] ctx Free context.
67 * @param[in] restr Restriction to free.
68 */
69void lysp_restr_free(struct lysf_ctx *ctx, struct lysp_restr *restr);
70
71/**
72 * @brief Free the parsed type structure.
73 *
74 * @param[in] ctx Free context.
75 * @param[in] type Parsed schema type structure to free. Note that the type itself is not freed.
76 */
77void lysp_type_free(struct lysf_ctx *ctx, struct lysp_type *type);
78
79/**
80 * @brief Free the parsed when structure.
81 *
82 * @param[in] ctx Free context.
83 * @param[in] when Parsed schema when structure to free. Note that the structure itself is not freed.
84 */
85void lysp_when_free(struct lysf_ctx *ctx, struct lysp_when *when);
86
87/**
88 * @brief Free the parsed deviate structure.
89 *
90 * @param[in] ctx Free context.
91 * @param[in] d Parsed schema deviate structure to free. Note that the structure itself is not freed.
92 */
93void lysp_deviate_free(struct lysf_ctx *ctx, struct lysp_deviate *d);
94
95/**
96 * @brief Free the parsed deviation structure.
97 *
98 * @param[in] ctx Free context.
99 * @param[in] dev Parsed schema deviation structure to free. Note that the structure itself is not freed.
100 */
101void lysp_deviation_free(struct lysf_ctx *ctx, struct lysp_deviation *dev);
102
103/**
104 * @brief Free a parsed node.
105 *
106 * @param[in] ctx Free context.
107 * @param[in] node Node to free.
108 */
109void lysp_node_free(struct lysf_ctx *ctx, struct lysp_node *node);
110
111/**
112 * @brief Free the parsed YANG schema tree structure. Works for both modules and submodules.
113 *
114 * @param[in] ctx Free context.
115 * @param[in] module Parsed YANG schema tree structure to free.
116 */
117void lysp_module_free(struct lysf_ctx *ctx, struct lysp_module *module);
118
119/**
120 * @brief Free the compiled extension instance structure.
121 *
122 * @param[in] ctx Free context.
123 * @param[in,out] ext Compiled extension instance structure to be cleaned.
124 * Since the structure is typically part of the sized array, the structure itself is not freed.
125 */
126void lysc_ext_instance_free(struct lysf_ctx *ctx, struct lysc_ext_instance *ext);
127
128/**
129 * @brief Free the compiled if-feature structure.
130 *
131 * @param[in] ctx Free context.
132 * @param[in,out] iff Compiled if-feature structure to be cleaned.
133 * Since the structure is typically part of the sized array, the structure itself is not freed.
134 */
135void lysc_iffeature_free(struct lysf_ctx *ctx, struct lysc_iffeature *iff);
136
137/**
138 * @brief Free a compiled pattern.
139 *
140 * @param[in] ctx Free context.
141 * @param[in] pattern Pointer to the pattern to free.
142 */
143void lysc_pattern_free(struct lysf_ctx *ctx, struct lysc_pattern **pattern);
144
145/**
146 * @brief Free a bit/enum item.
147 *
148 * @param[in] ctx Free context.
149 * @param[in] item Bit/enum item to free.
150 */
151void lysc_enum_item_free(struct lysf_ctx *ctx, struct lysc_type_bitenum_item *item);
152
153/**
154 * @brief Free the compiled type structure.
155 *
156 * @param[in] ctx Free context.
157 * @param[in,out] type Compiled type structure to be freed. The structure has refcount, so it is freed only in case
158 * the value is decreased to 0.
159 */
160void lysc_type_free(struct lysf_ctx *ctx, struct lysc_type *type);
161
162/**
163 * @brief Free the compiled container node structure.
164 *
165 * Only the container-specific members are freed, for generic node free function,
166 * use ::lysc_node_free().
167 *
168 * @param[in] ctx Free context.
169 * @param[in,out] node Compiled container node structure to be freed.
170 */
171void lysc_node_container_free(struct lysf_ctx *ctx, struct lysc_node_container *node);
172
173/**
174 * @brief Free the compiled node structure.
175 *
176 * @param[in] ctx Free context.
177 * @param[in] node Compiled node structure to be freed.
178 * @param[in] unlink Whether to first unlink the node before freeing.
179 */
180void lysc_node_free(struct lysf_ctx *ctx, struct lysc_node *node, ly_bool unlink);
181
182/**
183 * @brief Free the compiled schema structure.
184 *
185 * @param[in] ctx Free context.
186 * @param[in,out] module Compiled schema module structure to free.
187 */
188void lysc_module_free(struct lysf_ctx *ctx, struct lysc_module *module);
189
190/**
191 * @brief Free the schema structure. It just frees, it does not remove the schema from its context.
192 *
193 * @param[in] ctx Free context.
194 * @param[in,out] module Schema module structure to free.
195 * @param[in] remove_links Whether to remove links in other modules to structures in this module. Not needed if
196 * the whole context is being freed.
197 */
198void lys_module_free(struct lysf_ctx *ctx, struct lys_module *module, ly_bool remove_links);
199
200/**
201 * @brief Erase free context.
202 *
203 * @param[in] ctx Free context to erase.
204 */
205void lysf_ctx_erase(struct lysf_ctx *ctx);
206
207/**
208 * @brief Free lys parser context.
209 *
210 * @param[in] ctx Context to free.
211 */
Michal Vaskod0625d72022-10-06 15:02:50 +0200212void lysp_yang_ctx_free(struct lysp_yang_ctx *ctx);
Michal Vaskoc636ea42022-09-16 10:20:31 +0200213
214/**
215 * @brief Free yin parser context
216 *
217 * @param[in] ctx Context to free.
218 */
Michal Vaskod0625d72022-10-06 15:02:50 +0200219void lysp_yin_ctx_free(struct lysp_yin_ctx *ctx);
Michal Vaskoc636ea42022-09-16 10:20:31 +0200220
221#endif /* LY_TREE_SCHEMA_FREE_H_ */