blob: 92412e2958676067c406f4b590cbc3497404d63f [file] [log] [blame]
Radek Krejcif0e1ba52020-05-22 15:14:35 +02001/**
2 * @file parser_internal.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
Michal Vaskod027f382023-02-10 09:13:25 +01004 * @author Michal Vasko <mvasko@cesnet.cz>
Radek Krejcif0e1ba52020-05-22 15:14:35 +02005 * @brief Internal structures and functions for libyang parsers
6 *
Michal Vaskod027f382023-02-10 09:13:25 +01007 * Copyright (c) 2020 - 2023 CESNET, z.s.p.o.
Radek Krejcif0e1ba52020-05-22 15:14:35 +02008 *
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
16#ifndef LY_PARSER_INTERNAL_H_
17#define LY_PARSER_INTERNAL_H_
18
Michal Vaskoe0665742021-02-11 11:08:44 +010019#include "parser_data.h"
aPiecek704f8e92021-08-25 13:35:05 +020020#include "set.h"
Radek Krejcif0e1ba52020-05-22 15:14:35 +020021
Radek Krejci1798aae2020-07-14 13:26:06 +020022struct lyd_ctx;
Michal Vaskoafac7822020-10-20 14:22:26 +020023struct ly_in;
Michal Vasko193dacd2022-10-13 08:43:05 +020024struct lysp_ext_substmt;
25struct lysp_stmt;
Michal Vaskod0625d72022-10-06 15:02:50 +020026struct lysp_yang_ctx;
27struct lysp_yin_ctx;
28struct lysp_ctx;
Michal Vaskoc8a230d2020-08-14 12:17:10 +020029
Radek Krejci1798aae2020-07-14 13:26:06 +020030/**
Michal Vaskod027f382023-02-10 09:13:25 +010031 * @brief Check data parser error taking into account multi-error validation.
32 *
33 * @param[in] r Local return value.
34 * @param[in] err_cmd Command to perform on any error.
35 * @param[in] lydctx Data parser context.
36 * @param[in] label Label to go to on fatal error.
37 */
38#define LY_DPARSER_ERR_GOTO(r, err_cmd, lydctx, label) \
39 if (r) { \
40 err_cmd; \
Michal Vasko50da8cd2023-03-10 08:38:59 +010041 if ((r != LY_EVALID) || !lydctx || !(lydctx->val_opts & LYD_VALIDATE_MULTI_ERROR) || \
42 (ly_vecode(((struct lyd_ctx *)lydctx)->data_ctx->ctx) == LYVE_SYNTAX)) { \
Michal Vaskod027f382023-02-10 09:13:25 +010043 goto label; \
44 } \
45 }
46
47/**
Radek Krejci84d7fd72021-07-14 18:32:21 +020048 * @brief Callback for ::lyd_ctx to free the structure
Radek Krejci1798aae2020-07-14 13:26:06 +020049 *
50 * @param[in] ctx Data parser context to free.
51 */
52typedef void (*lyd_ctx_free_clb)(struct lyd_ctx *ctx);
53
54/**
Michal Vaskoe0665742021-02-11 11:08:44 +010055 * @brief Internal data parser flags.
56 */
57#define LYD_INTOPT_RPC 0x01 /**< RPC request is being parsed. */
58#define LYD_INTOPT_ACTION 0x02 /**< Action request is being parsed. */
59#define LYD_INTOPT_REPLY 0x04 /**< RPC/action reply is being parsed. */
60#define LYD_INTOPT_NOTIF 0x08 /**< Notification is being parsed. */
Michal Vasko02ed9d82021-07-15 14:58:04 +020061#define LYD_INTOPT_ANY 0x10 /**< Anydata/anyxml content is being parsed, there can be anything. */
62#define LYD_INTOPT_WITH_SIBLINGS 0x20 /**< Parse the whole input with any siblings. */
63#define LYD_INTOPT_NO_SIBLINGS 0x40 /**< If there are any siblings, return an error. */
Michal Vasko4a1e3e82023-09-05 08:45:01 +020064#define LYD_INTOPT_EVENTTIME 0x80 /**< Parse notification eventTime node. */
Michal Vaskoe0665742021-02-11 11:08:44 +010065
66/**
Radek Krejci1798aae2020-07-14 13:26:06 +020067 * @brief Internal (common) context for YANG data parsers.
Radek Krejci4f2e3e52021-03-30 14:20:28 +020068 *
Radek Krejci84d7fd72021-07-14 18:32:21 +020069 * Covers ::lyd_xml_ctx, ::lyd_json_ctx and ::lyd_lyb_ctx.
Radek Krejci1798aae2020-07-14 13:26:06 +020070 */
71struct lyd_ctx {
Radek Krejcif16e2542021-02-17 15:39:23 +010072 const struct lysc_ext_instance *ext; /**< extension instance possibly changing document root context of the data being parsed */
Michal Vaskoe0665742021-02-11 11:08:44 +010073 uint32_t parse_opts; /**< various @ref dataparseroptions. */
74 uint32_t val_opts; /**< various @ref datavalidationoptions. */
75 uint32_t int_opts; /**< internal parser options */
Radek Krejci1798aae2020-07-14 13:26:06 +020076 uint32_t path_len; /**< used bytes in the path buffer */
Michal Vasko26bbb272022-08-02 14:54:33 +020077
Radek Krejci1798aae2020-07-14 13:26:06 +020078#define LYD_PARSER_BUFSIZE 4078
79 char path[LYD_PARSER_BUFSIZE]; /**< buffer for the generated path */
Michal Vaskoc43c8ab2021-03-05 13:32:44 +010080 struct ly_set node_when; /**< set of nodes with "when" conditions */
Michal Vasko32711382020-12-03 14:14:31 +010081 struct ly_set node_types; /**< set of nodes validated with LY_EINCOMPLETE result */
82 struct ly_set meta_types; /**< set of metadata validated with LY_EINCOMPLETE result */
Michal Vasko135719f2022-08-25 12:18:17 +020083 struct ly_set ext_node; /**< set of nodes with extension instances to validate */
84 struct ly_set ext_val; /**< set of nested subtrees parsed by extensions to validate */
Radek Krejci1798aae2020-07-14 13:26:06 +020085 struct lyd_node *op_node; /**< if an RPC/action/notification is being parsed, store the pointer to it */
86
87 /* callbacks */
Radek Krejci0bff0b12020-08-15 18:37:50 +020088 lyd_ctx_free_clb free; /**< destructor */
Radek Krejci1798aae2020-07-14 13:26:06 +020089
90 struct {
Radek Krejci0bff0b12020-08-15 18:37:50 +020091 const struct ly_ctx *ctx; /**< libyang context */
92 uint64_t line; /**< current line */
93 struct ly_in *in; /**< input structure */
94 } *data_ctx; /**< generic pointer supposed to map to and access (common part of) XML/JSON/... parser contexts */
Radek Krejci1798aae2020-07-14 13:26:06 +020095};
96
Radek Krejci7931b192020-06-25 17:05:03 +020097/**
Michal Vasko03fbaed2021-07-15 09:18:32 +020098 * @brief Internal context for XML data parser.
99 */
100struct lyd_xml_ctx {
101 const struct lysc_ext_instance *ext;
102 uint32_t parse_opts;
103 uint32_t val_opts;
104 uint32_t int_opts;
105 uint32_t path_len;
106 char path[LYD_PARSER_BUFSIZE];
107 struct ly_set node_when;
Michal Vasko03fbaed2021-07-15 09:18:32 +0200108 struct ly_set node_types;
109 struct ly_set meta_types;
Michal Vasko135719f2022-08-25 12:18:17 +0200110 struct ly_set ext_node;
Michal Vaskoddd76592022-01-17 13:34:48 +0100111 struct ly_set ext_val;
Michal Vasko03fbaed2021-07-15 09:18:32 +0200112 struct lyd_node *op_node;
113
114 /* callbacks */
115 lyd_ctx_free_clb free;
116
117 struct lyxml_ctx *xmlctx; /**< XML context */
118};
119
120/**
121 * @brief Internal context for JSON data parser.
122 */
123struct lyd_json_ctx {
124 const struct lysc_ext_instance *ext;
125 uint32_t parse_opts;
126 uint32_t val_opts;
127 uint32_t int_opts;
128 uint32_t path_len;
129 char path[LYD_PARSER_BUFSIZE];
130 struct ly_set node_when;
Michal Vasko03fbaed2021-07-15 09:18:32 +0200131 struct ly_set node_types;
132 struct ly_set meta_types;
Michal Vasko135719f2022-08-25 12:18:17 +0200133 struct ly_set ext_node;
Michal Vaskoddd76592022-01-17 13:34:48 +0100134 struct ly_set ext_val;
Michal Vasko03fbaed2021-07-15 09:18:32 +0200135 struct lyd_node *op_node;
136
137 /* callbacks */
138 lyd_ctx_free_clb free;
139
Michal Vasko80623c52023-04-28 14:22:06 +0200140 struct lyjson_ctx *jsonctx; /**< JSON context */
141 const struct lysc_node *any_schema; /**< parent anyxml/anydata schema node if parsing nested data tree */
Michal Vasko03fbaed2021-07-15 09:18:32 +0200142};
143
144/**
145 * @brief Internal context for LYB data parser/printer.
146 */
147struct lyd_lyb_ctx {
148 const struct lysc_ext_instance *ext;
Michal Vasko26bbb272022-08-02 14:54:33 +0200149
Michal Vasko03fbaed2021-07-15 09:18:32 +0200150 union {
151 struct {
152 uint32_t parse_opts;
153 uint32_t val_opts;
154 };
155 uint32_t print_options;
156 };
157 uint32_t int_opts;
158 uint32_t path_len;
159 char path[LYD_PARSER_BUFSIZE];
160 struct ly_set node_when;
Michal Vasko03fbaed2021-07-15 09:18:32 +0200161 struct ly_set node_types;
162 struct ly_set meta_types;
Michal Vasko135719f2022-08-25 12:18:17 +0200163 struct ly_set ext_node;
Michal Vaskoddd76592022-01-17 13:34:48 +0100164 struct ly_set ext_val;
Michal Vasko03fbaed2021-07-15 09:18:32 +0200165 struct lyd_node *op_node;
166
167 /* callbacks */
168 lyd_ctx_free_clb free;
169
170 struct lylyb_ctx *lybctx; /* LYB context */
171};
172
173/**
Michal Vaskoddd76592022-01-17 13:34:48 +0100174 * @brief Parsed extension instance data to validate.
175 */
176struct lyd_ctx_ext_val {
177 struct lysc_ext_instance *ext;
178 struct lyd_node *sibling;
179};
180
181/**
Michal Vasko135719f2022-08-25 12:18:17 +0200182 * @brief Parsed data node with extension instance to validate.
183 */
184struct lyd_ctx_ext_node {
185 struct lysc_ext_instance *ext;
186 struct lyd_node *node;
187};
188
189/**
Radek Krejci84d7fd72021-07-14 18:32:21 +0200190 * @brief Common part to supplement the specific ::lyd_ctx_free_clb callbacks.
Radek Krejci1798aae2020-07-14 13:26:06 +0200191 */
Michal Vaskoddd76592022-01-17 13:34:48 +0100192void lyd_ctx_free(struct lyd_ctx *ctx);
Radek Krejci1798aae2020-07-14 13:26:06 +0200193
194/**
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200195 * @brief Parse submodule from YANG data.
Radek Krejci84d7fd72021-07-14 18:32:21 +0200196 * @param[in,out] context Parser context.
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200197 * @param[in] ly_ctx Context of YANG schemas.
198 * @param[in] main_ctx Parser context of main module.
Michal Vasko63f3d842020-07-08 10:10:14 +0200199 * @param[in] in Input structure.
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200200 * @param[out] submod Pointer to the parsed submodule structure.
201 * @return LY_ERR value - LY_SUCCESS, LY_EINVAL or LY_EVALID.
202 */
Michal Vaskod0625d72022-10-06 15:02:50 +0200203LY_ERR yang_parse_submodule(struct lysp_yang_ctx **context, struct ly_ctx *ly_ctx, struct lysp_ctx *main_ctx,
Radek Krejci0f969882020-08-21 16:56:47 +0200204 struct ly_in *in, struct lysp_submodule **submod);
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200205
206/**
207 * @brief Parse module from YANG data.
Radek Krejci84d7fd72021-07-14 18:32:21 +0200208 * @param[in] context Parser context.
Michal Vasko63f3d842020-07-08 10:10:14 +0200209 * @param[in] in Input structure.
210 * @param[in,out] mod Prepared module structure where the parsed information, including the parsed
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200211 * module structure, will be filled in.
Michal Vasko405cc9e2020-12-01 12:01:27 +0100212 * @return LY_ERR values.
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200213 */
Michal Vaskod0625d72022-10-06 15:02:50 +0200214LY_ERR yang_parse_module(struct lysp_yang_ctx **context, struct ly_in *in, struct lys_module *mod);
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200215
216/**
217 * @brief Parse module from YIN data.
218 *
219 * @param[in,out] yin_ctx Context created during parsing, is used to finalize lysp_model after it's completly parsed.
Michal Vasko63f3d842020-07-08 10:10:14 +0200220 * @param[in] in Input structure.
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200221 * @param[in,out] mod Prepared module structure where the parsed information, including the parsed
222 * module structure, will be filled in.
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200223 * @return LY_ERR values.
224 */
Michal Vaskod0625d72022-10-06 15:02:50 +0200225LY_ERR yin_parse_module(struct lysp_yin_ctx **yin_ctx, struct ly_in *in, struct lys_module *mod);
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200226
227/**
228 * @brief Parse submodule from YIN data.
229 *
230 * @param[in,out] yin_ctx Context created during parsing, is used to finalize lysp_model after it's completly parsed.
231 * @param[in] ctx Libyang context.
232 * @param[in] main_ctx Parser context of main module.
Michal Vasko63f3d842020-07-08 10:10:14 +0200233 * @param[in] in Input structure.
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200234 * @param[in,out] submod Submodule structure where the parsed information, will be filled in.
235 * @return LY_ERR values.
236 */
Michal Vaskod0625d72022-10-06 15:02:50 +0200237LY_ERR yin_parse_submodule(struct lysp_yin_ctx **yin_ctx, struct ly_ctx *ctx, struct lysp_ctx *main_ctx,
Radek Krejci0f969882020-08-21 16:56:47 +0200238 struct ly_in *in, struct lysp_submodule **submod);
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200239
Radek Krejci1798aae2020-07-14 13:26:06 +0200240/**
Michal Vaskoe0665742021-02-11 11:08:44 +0100241 * @brief Parse XML string as a YANG data tree.
Michal Vaskoafac7822020-10-20 14:22:26 +0200242 *
Michal Vaskoe0665742021-02-11 11:08:44 +0100243 * @param[in] ctx libyang context.
aPiecekb0445f22021-06-24 11:34:07 +0200244 * @param[in] ext Optional extension instance to parse data following the schema tree specified in the extension instance
Michal Vaskoe0665742021-02-11 11:08:44 +0100245 * @param[in] parent Parent to connect the parsed nodes to, if any.
246 * @param[in,out] first_p Pointer to the first top-level parsed node, used only if @p parent is NULL.
Michal Vaskoafac7822020-10-20 14:22:26 +0200247 * @param[in] in Input structure.
Michal Vaskoe0665742021-02-11 11:08:44 +0100248 * @param[in] parse_opts Options for parser, see @ref dataparseroptions.
249 * @param[in] val_opts Options for the validation phase, see @ref datavalidationoptions.
Michal Vaskoe3ed7dc2022-11-30 11:39:44 +0100250 * @param[in] int_opts Internal data parser options.
Michal Vaskoe0665742021-02-11 11:08:44 +0100251 * @param[out] parsed Set to add all the parsed siblings into.
Michal Vaskoddd76592022-01-17 13:34:48 +0100252 * @param[out] subtree_sibling Set if ::LYD_PARSE_SUBTREE is used and another subtree is following in @p in.
Michal Vaskoafac7822020-10-20 14:22:26 +0200253 * @param[out] lydctx_p Data parser context to finish validation.
254 * @return LY_ERR value.
255 */
Radek Krejcif16e2542021-02-17 15:39:23 +0100256LY_ERR lyd_parse_xml(const struct ly_ctx *ctx, const struct lysc_ext_instance *ext, struct lyd_node *parent,
Michal Vaskoe3ed7dc2022-11-30 11:39:44 +0100257 struct lyd_node **first_p, struct ly_in *in, uint32_t parse_opts, uint32_t val_opts, uint32_t int_opts,
258 struct ly_set *parsed, ly_bool *subtree_sibling, struct lyd_ctx **lydctx_p);
259
260/**
261 * @brief Parse XML string as a NETCONF message.
262 *
263 * @param[in] ctx libyang context.
264 * @param[in] ext Optional extension instance to parse data following the schema tree specified in the extension instance
265 * @param[in] parent Parent to connect the parsed nodes to, if any.
266 * @param[in,out] first_p Pointer to the first top-level parsed node, used only if @p parent is NULL.
267 * @param[in] in Input structure.
268 * @param[in] parse_opts Options for parser, see @ref dataparseroptions.
269 * @param[in] val_opts Options for the validation phase, see @ref datavalidationoptions.
270 * @param[in] data_type Expected NETCONF data type of the data.
271 * @param[out] envp Individual parsed envelopes tree, may be returned possibly even on an error.
272 * @param[out] parsed Set to add all the parsed siblings into.
273 * @param[out] subtree_sibling Set if ::LYD_PARSE_SUBTREE is used and another subtree is following in @p in.
274 * @param[out] lydctx_p Data parser context to finish validation.
275 * @return LY_ERR value.
276 */
277LY_ERR lyd_parse_xml_netconf(const struct ly_ctx *ctx, const struct lysc_ext_instance *ext, struct lyd_node *parent,
Radek Krejcif16e2542021-02-17 15:39:23 +0100278 struct lyd_node **first_p, struct ly_in *in, uint32_t parse_opts, uint32_t val_opts, enum lyd_type data_type,
Michal Vaskoe3ed7dc2022-11-30 11:39:44 +0100279 struct lyd_node **envp, struct ly_set *parsed, struct lyd_ctx **lydctx_p);
Michal Vaskoafac7822020-10-20 14:22:26 +0200280
281/**
Michal Vaskoe0665742021-02-11 11:08:44 +0100282 * @brief Parse JSON string as a YANG data tree.
Michal Vaskoafac7822020-10-20 14:22:26 +0200283 *
Michal Vaskoafac7822020-10-20 14:22:26 +0200284 * @param[in] ctx libyang context.
aPiecekb0445f22021-06-24 11:34:07 +0200285 * @param[in] ext Optional extension instance to parse data following the schema tree specified in the extension instance
Michal Vaskoe0665742021-02-11 11:08:44 +0100286 * @param[in] parent Parent to connect the parsed nodes to, if any.
287 * @param[in,out] first_p Pointer to the first top-level parsed node, used only if @p parent is NULL.
Michal Vaskoafac7822020-10-20 14:22:26 +0200288 * @param[in] in Input structure.
Michal Vaskoe0665742021-02-11 11:08:44 +0100289 * @param[in] parse_opts Options for parser, see @ref dataparseroptions.
290 * @param[in] val_opts Options for the validation phase, see @ref datavalidationoptions.
Michal Vaskoe3ed7dc2022-11-30 11:39:44 +0100291 * @param[in] int_opts Internal data parser options.
Michal Vaskoe0665742021-02-11 11:08:44 +0100292 * @param[out] parsed Set to add all the parsed siblings into.
Michal Vaskoddd76592022-01-17 13:34:48 +0100293 * @param[out] subtree_sibling Set if ::LYD_PARSE_SUBTREE is used and another subtree is following in @p in.
Michal Vaskoafac7822020-10-20 14:22:26 +0200294 * @param[out] lydctx_p Data parser context to finish validation.
295 * @return LY_ERR value.
296 */
Radek Krejcif16e2542021-02-17 15:39:23 +0100297LY_ERR lyd_parse_json(const struct ly_ctx *ctx, const struct lysc_ext_instance *ext, struct lyd_node *parent,
Michal Vaskoe3ed7dc2022-11-30 11:39:44 +0100298 struct lyd_node **first_p, struct ly_in *in, uint32_t parse_opts, uint32_t val_opts, uint32_t int_opts,
Michal Vaskoddd76592022-01-17 13:34:48 +0100299 struct ly_set *parsed, ly_bool *subtree_sibling, struct lyd_ctx **lydctx_p);
Michal Vaskoafac7822020-10-20 14:22:26 +0200300
301/**
Michal Vasko820efe82023-05-12 15:47:43 +0200302 * @brief Parse JSON string as a RESTCONF message.
303 *
304 * @param[in] ctx libyang context.
305 * @param[in] ext Optional extension instance to parse data following the schema tree specified in the extension instance
306 * @param[in] parent Parent to connect the parsed nodes to, if any.
307 * @param[in,out] first_p Pointer to the first top-level parsed node, used only if @p parent is NULL.
308 * @param[in] in Input structure.
309 * @param[in] parse_opts Options for parser, see @ref dataparseroptions.
310 * @param[in] val_opts Options for the validation phase, see @ref datavalidationoptions.
311 * @param[in] data_type Expected RESTCONF data type of the data.
312 * @param[out] envp Individual parsed envelopes tree, may be returned possibly even on an error.
313 * @param[out] parsed Set to add all the parsed siblings into.
314 * @param[out] subtree_sibling Set if ::LYD_PARSE_SUBTREE is used and another subtree is following in @p in.
315 * @param[out] lydctx_p Data parser context to finish validation.
316 * @return LY_ERR value.
317 */
318LY_ERR lyd_parse_json_restconf(const struct ly_ctx *ctx, const struct lysc_ext_instance *ext, struct lyd_node *parent,
319 struct lyd_node **first_p, struct ly_in *in, uint32_t parse_opts, uint32_t val_opts, enum lyd_type data_type,
320 struct lyd_node **envp, struct ly_set *parsed, struct lyd_ctx **lydctx_p);
321
322/**
Michal Vaskoe0665742021-02-11 11:08:44 +0100323 * @brief Parse binary LYB data as a YANG data tree.
Michal Vaskoafac7822020-10-20 14:22:26 +0200324 *
Michal Vaskoafac7822020-10-20 14:22:26 +0200325 * @param[in] ctx libyang context.
aPiecekb0445f22021-06-24 11:34:07 +0200326 * @param[in] ext Optional extension instance to parse data following the schema tree specified in the extension instance
Michal Vaskoe0665742021-02-11 11:08:44 +0100327 * @param[in] parent Parent to connect the parsed nodes to, if any.
328 * @param[in,out] first_p Pointer to the first top-level parsed node, used only if @p parent is NULL.
Michal Vaskoafac7822020-10-20 14:22:26 +0200329 * @param[in] in Input structure.
Michal Vaskoe0665742021-02-11 11:08:44 +0100330 * @param[in] parse_opts Options for parser, see @ref dataparseroptions.
331 * @param[in] val_opts Options for the validation phase, see @ref datavalidationoptions.
Michal Vaskoe3ed7dc2022-11-30 11:39:44 +0100332 * @param[in] int_opts Internal data parser options.
Michal Vaskoe0665742021-02-11 11:08:44 +0100333 * @param[out] parsed Set to add all the parsed siblings into.
Michal Vaskoddd76592022-01-17 13:34:48 +0100334 * @param[out] subtree_sibling Set if ::LYD_PARSE_SUBTREE is used and another subtree is following in @p in.
Michal Vaskoafac7822020-10-20 14:22:26 +0200335 * @param[out] lydctx_p Data parser context to finish validation.
336 * @return LY_ERR value.
337 */
Radek Krejcif16e2542021-02-17 15:39:23 +0100338LY_ERR lyd_parse_lyb(const struct ly_ctx *ctx, const struct lysc_ext_instance *ext, struct lyd_node *parent,
Michal Vaskoe3ed7dc2022-11-30 11:39:44 +0100339 struct lyd_node **first_p, struct ly_in *in, uint32_t parse_opts, uint32_t val_opts, uint32_t int_opts,
Michal Vaskoddd76592022-01-17 13:34:48 +0100340 struct ly_set *parsed, ly_bool *subtree_sibling, struct lyd_ctx **lydctx_p);
Michal Vaskoafac7822020-10-20 14:22:26 +0200341
342/**
Michal Vasko820efe82023-05-12 15:47:43 +0200343 * @brief Validate eventTime date-and-time value.
344 *
345 * @param[in] node Opaque eventTime node.
346 * @return LY_SUCCESS on success.
347 * @return LY_ERR value on error.
348 */
349LY_ERR lyd_parser_notif_eventtime_validate(const struct lyd_node *node);
350
351/**
Michal Vaskoe0665742021-02-11 11:08:44 +0100352 * @brief Search all the parents for an operation node, check validity based on internal parser flags.
Michal Vaskoafac7822020-10-20 14:22:26 +0200353 *
Michal Vaskoe0665742021-02-11 11:08:44 +0100354 * @param[in] parent Parent to connect the parsed nodes to.
Radek Krejci84d7fd72021-07-14 18:32:21 +0200355 * @param[in] int_opts Internal parser options.
Michal Vaskoe0665742021-02-11 11:08:44 +0100356 * @param[out] op Found operation, if any.
Michal Vaskoafac7822020-10-20 14:22:26 +0200357 * @return LY_ERR value.
358 */
Michal Vaskoe0665742021-02-11 11:08:44 +0100359LY_ERR lyd_parser_find_operation(const struct lyd_node *parent, uint32_t int_opts, struct lyd_node **op);
Michal Vaskoafac7822020-10-20 14:22:26 +0200360
361/**
Michal Vaskoa878a892023-08-18 12:22:07 +0200362 * @brief Get schema node of a node being parsed, use nodes stored for logging.
363 *
364 * @param[in] node Node whose schema node to get.
365 * @return Schema node even for an opaque node, NULL if none found.
366 */
367const struct lysc_node *lyd_parser_node_schema(const struct lyd_node *node);
368
369/**
Radek Krejci1798aae2020-07-14 13:26:06 +0200370 * @brief Check that a data node representing the @p snode is suitable based on options.
371 *
372 * @param[in] lydctx Common data parsers context.
373 * @param[in] snode Schema node to check.
374 * @return LY_SUCCESS or LY_EVALID
375 */
376LY_ERR lyd_parser_check_schema(struct lyd_ctx *lydctx, const struct lysc_node *snode);
377
378/**
Radek Krejci8678fa42020-08-18 16:07:28 +0200379 * @brief Wrapper around ::lyd_create_term() for data parsers.
Radek Krejci1798aae2020-07-14 13:26:06 +0200380 *
381 * @param[in] lydctx Data parser context.
Radek Krejci84d7fd72021-07-14 18:32:21 +0200382 * @param[in] schema Schema node of the new data node.
383 * @param[in] value String value to be parsed.
384 * @param[in] value_len Length of @p value, must be set correctly.
385 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
386 * @param[in] format Input format of @p value.
387 * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix).
388 * @param[in] hints [Data parser's hints](@ref lydvalhints) for the value's type.
389 * @param[out] node Created node.
390 * @return LY_SUCCESS on success.
391 * @return LY_EINCOMPLETE in case data tree is needed to finish the validation.
392 * @return LY_ERR value if an error occurred.
Radek Krejci1798aae2020-07-14 13:26:06 +0200393 */
Radek Krejci09c77442021-04-26 11:10:34 +0200394LY_ERR lyd_parser_create_term(struct lyd_ctx *lydctx, const struct lysc_node *schema, const void *value, size_t value_len,
Radek Krejci8df109d2021-04-23 12:19:08 +0200395 ly_bool *dynamic, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints, struct lyd_node **node);
Radek Krejci1798aae2020-07-14 13:26:06 +0200396
397/**
Radek Krejci8678fa42020-08-18 16:07:28 +0200398 * @brief Wrapper around ::lyd_create_meta() for data parsers.
Radek Krejci1798aae2020-07-14 13:26:06 +0200399 *
400 * @param[in] lydctx Data parser context.
Michal Vaskob68571a2020-11-06 17:18:41 +0100401 * @param[in] parent Parent of the created meta. Must be set if @p meta is NULL.
402 * @param[in,out] meta First existing meta to connect to or empty pointer to set. Must be set if @p parent is NULL.
403 * @param[in] mod Module of the created metadata.
404 * @param[in] name Metadata name.
405 * @param[in] name_len Length of @p name.
406 * @param[in] value Metadata value.
407 * @param[in] value_len Length of @p value.
408 * @param[in,out] dynamic Whether the @p value is dynamically allocated, is adjusted once the value is assigned.
409 * @param[in] format Prefix format.
410 * @param[in] prefix_data Prefix format data (see ::ly_resolve_prefix()).
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200411 * @param[in] hints [Value hint](@ref lydvalhints) from the parser regarding the value type.
Michal Vaskoddd76592022-01-17 13:34:48 +0100412 * @param[in] ctx_node Value context node.
Michal Vaskob68571a2020-11-06 17:18:41 +0100413 * @return LY_ERR value.
Radek Krejci1798aae2020-07-14 13:26:06 +0200414 */
Michal Vaskoc8a230d2020-08-14 12:17:10 +0200415LY_ERR lyd_parser_create_meta(struct lyd_ctx *lydctx, struct lyd_node *parent, struct lyd_meta **meta,
Michal Vaskoddd76592022-01-17 13:34:48 +0100416 const struct lys_module *mod, const char *name, size_t name_len, const void *value, size_t value_len,
417 ly_bool *dynamic, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints, const struct lysc_node *ctx_node);
Radek Krejci1798aae2020-07-14 13:26:06 +0200418
Michal Vasko95c6d5c2022-05-20 10:33:39 +0200419/**
420 * @brief Check that a list has all its keys.
421 *
422 * @param[in] node List to check.
423 * @return LY_SUCCESS on success.
424 * @return LY_ENOT on a missing key.
425 */
426LY_ERR lyd_parse_check_keys(struct lyd_node *node);
427
428/**
429 * @brief Set data flags for a newly parsed node.
430 *
431 * @param[in] node Node to use.
432 * @param[in,out] meta Node metadata, may be removed from.
433 * @param[in] lydctx Data parsing context.
434 * @param[in] ext Extension instance if @p node was parsed for one.
435 * @return LY_ERR value.
436 */
437LY_ERR lyd_parse_set_data_flags(struct lyd_node *node, struct lyd_meta **meta, struct lyd_ctx *lydctx,
438 struct lysc_ext_instance *ext);
439
Michal Vasko193dacd2022-10-13 08:43:05 +0200440/**
441 * @brief Parse an instance extension statement.
442 *
443 * @param[in] pctx Parse context.
444 * @param[in] substmt Parsed ext instance substatement info.
445 * @param[in] stmt Parsed generic statement to process.
446 * @return LY_ERR value.
447 */
448LY_ERR lys_parse_ext_instance_stmt(struct lysp_ctx *pctx, struct lysp_ext_substmt *substmt, struct lysp_stmt *stmt);
449
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200450#endif /* LY_PARSER_INTERNAL_H_ */