blob: 458d29719ce780bb4ed19c6a39355d308834044c [file] [log] [blame]
Radek Krejcif0e1ba52020-05-22 15:14:35 +02001/**
2 * @file parser_internal.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief Internal structures and functions for libyang parsers
5 *
6 * Copyright (c) 2020 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_PARSER_INTERNAL_H_
16#define LY_PARSER_INTERNAL_H_
17
Michal Vaskoe0665742021-02-11 11:08:44 +010018#include "parser_data.h"
aPiecek704f8e92021-08-25 13:35:05 +020019#include "set.h"
Radek Krejcif0e1ba52020-05-22 15:14:35 +020020
Radek Krejci1798aae2020-07-14 13:26:06 +020021struct lyd_ctx;
Michal Vaskoafac7822020-10-20 14:22:26 +020022struct ly_in;
Michal Vasko193dacd2022-10-13 08:43:05 +020023struct lysp_ext_substmt;
24struct lysp_stmt;
Michal Vaskod0625d72022-10-06 15:02:50 +020025struct lysp_yang_ctx;
26struct lysp_yin_ctx;
27struct lysp_ctx;
Michal Vaskoc8a230d2020-08-14 12:17:10 +020028
Radek Krejci1798aae2020-07-14 13:26:06 +020029/**
Radek Krejci84d7fd72021-07-14 18:32:21 +020030 * @brief Callback for ::lyd_ctx to free the structure
Radek Krejci1798aae2020-07-14 13:26:06 +020031 *
32 * @param[in] ctx Data parser context to free.
33 */
34typedef void (*lyd_ctx_free_clb)(struct lyd_ctx *ctx);
35
36/**
Michal Vaskoe0665742021-02-11 11:08:44 +010037 * @brief Internal data parser flags.
38 */
39#define LYD_INTOPT_RPC 0x01 /**< RPC request is being parsed. */
40#define LYD_INTOPT_ACTION 0x02 /**< Action request is being parsed. */
41#define LYD_INTOPT_REPLY 0x04 /**< RPC/action reply is being parsed. */
42#define LYD_INTOPT_NOTIF 0x08 /**< Notification is being parsed. */
Michal Vasko02ed9d82021-07-15 14:58:04 +020043#define LYD_INTOPT_ANY 0x10 /**< Anydata/anyxml content is being parsed, there can be anything. */
44#define LYD_INTOPT_WITH_SIBLINGS 0x20 /**< Parse the whole input with any siblings. */
45#define LYD_INTOPT_NO_SIBLINGS 0x40 /**< If there are any siblings, return an error. */
Michal Vaskoe0665742021-02-11 11:08:44 +010046
47/**
Radek Krejci1798aae2020-07-14 13:26:06 +020048 * @brief Internal (common) context for YANG data parsers.
Radek Krejci4f2e3e52021-03-30 14:20:28 +020049 *
Radek Krejci84d7fd72021-07-14 18:32:21 +020050 * Covers ::lyd_xml_ctx, ::lyd_json_ctx and ::lyd_lyb_ctx.
Radek Krejci1798aae2020-07-14 13:26:06 +020051 */
52struct lyd_ctx {
Radek Krejcif16e2542021-02-17 15:39:23 +010053 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 +010054 uint32_t parse_opts; /**< various @ref dataparseroptions. */
55 uint32_t val_opts; /**< various @ref datavalidationoptions. */
56 uint32_t int_opts; /**< internal parser options */
Radek Krejci1798aae2020-07-14 13:26:06 +020057 uint32_t path_len; /**< used bytes in the path buffer */
Michal Vasko26bbb272022-08-02 14:54:33 +020058
Radek Krejci1798aae2020-07-14 13:26:06 +020059#define LYD_PARSER_BUFSIZE 4078
60 char path[LYD_PARSER_BUFSIZE]; /**< buffer for the generated path */
Michal Vaskoc43c8ab2021-03-05 13:32:44 +010061 struct ly_set node_when; /**< set of nodes with "when" conditions */
Michal Vasko32711382020-12-03 14:14:31 +010062 struct ly_set node_types; /**< set of nodes validated with LY_EINCOMPLETE result */
63 struct ly_set meta_types; /**< set of metadata validated with LY_EINCOMPLETE result */
Michal Vasko135719f2022-08-25 12:18:17 +020064 struct ly_set ext_node; /**< set of nodes with extension instances to validate */
65 struct ly_set ext_val; /**< set of nested subtrees parsed by extensions to validate */
Radek Krejci1798aae2020-07-14 13:26:06 +020066 struct lyd_node *op_node; /**< if an RPC/action/notification is being parsed, store the pointer to it */
67
68 /* callbacks */
Radek Krejci0bff0b12020-08-15 18:37:50 +020069 lyd_ctx_free_clb free; /**< destructor */
Radek Krejci1798aae2020-07-14 13:26:06 +020070
71 struct {
Radek Krejci0bff0b12020-08-15 18:37:50 +020072 const struct ly_ctx *ctx; /**< libyang context */
73 uint64_t line; /**< current line */
74 struct ly_in *in; /**< input structure */
75 } *data_ctx; /**< generic pointer supposed to map to and access (common part of) XML/JSON/... parser contexts */
Radek Krejci1798aae2020-07-14 13:26:06 +020076};
77
Radek Krejci7931b192020-06-25 17:05:03 +020078/**
Michal Vasko03fbaed2021-07-15 09:18:32 +020079 * @brief Internal context for XML data parser.
80 */
81struct lyd_xml_ctx {
82 const struct lysc_ext_instance *ext;
83 uint32_t parse_opts;
84 uint32_t val_opts;
85 uint32_t int_opts;
86 uint32_t path_len;
87 char path[LYD_PARSER_BUFSIZE];
88 struct ly_set node_when;
Michal Vasko03fbaed2021-07-15 09:18:32 +020089 struct ly_set node_types;
90 struct ly_set meta_types;
Michal Vasko135719f2022-08-25 12:18:17 +020091 struct ly_set ext_node;
Michal Vaskoddd76592022-01-17 13:34:48 +010092 struct ly_set ext_val;
Michal Vasko03fbaed2021-07-15 09:18:32 +020093 struct lyd_node *op_node;
94
95 /* callbacks */
96 lyd_ctx_free_clb free;
97
98 struct lyxml_ctx *xmlctx; /**< XML context */
99};
100
101/**
102 * @brief Internal context for JSON data parser.
103 */
104struct lyd_json_ctx {
105 const struct lysc_ext_instance *ext;
106 uint32_t parse_opts;
107 uint32_t val_opts;
108 uint32_t int_opts;
109 uint32_t path_len;
110 char path[LYD_PARSER_BUFSIZE];
111 struct ly_set node_when;
Michal Vasko03fbaed2021-07-15 09:18:32 +0200112 struct ly_set node_types;
113 struct ly_set meta_types;
Michal Vasko135719f2022-08-25 12:18:17 +0200114 struct ly_set ext_node;
Michal Vaskoddd76592022-01-17 13:34:48 +0100115 struct ly_set ext_val;
Michal Vasko03fbaed2021-07-15 09:18:32 +0200116 struct lyd_node *op_node;
117
118 /* callbacks */
119 lyd_ctx_free_clb free;
120
121 struct lyjson_ctx *jsonctx; /**< JSON context */
122};
123
124/**
125 * @brief Internal context for LYB data parser/printer.
126 */
127struct lyd_lyb_ctx {
128 const struct lysc_ext_instance *ext;
Michal Vasko26bbb272022-08-02 14:54:33 +0200129
Michal Vasko03fbaed2021-07-15 09:18:32 +0200130 union {
131 struct {
132 uint32_t parse_opts;
133 uint32_t val_opts;
134 };
135 uint32_t print_options;
136 };
137 uint32_t int_opts;
138 uint32_t path_len;
139 char path[LYD_PARSER_BUFSIZE];
140 struct ly_set node_when;
Michal Vasko03fbaed2021-07-15 09:18:32 +0200141 struct ly_set node_types;
142 struct ly_set meta_types;
Michal Vasko135719f2022-08-25 12:18:17 +0200143 struct ly_set ext_node;
Michal Vaskoddd76592022-01-17 13:34:48 +0100144 struct ly_set ext_val;
Michal Vasko03fbaed2021-07-15 09:18:32 +0200145 struct lyd_node *op_node;
146
147 /* callbacks */
148 lyd_ctx_free_clb free;
149
150 struct lylyb_ctx *lybctx; /* LYB context */
151};
152
153/**
Michal Vaskoddd76592022-01-17 13:34:48 +0100154 * @brief Parsed extension instance data to validate.
155 */
156struct lyd_ctx_ext_val {
157 struct lysc_ext_instance *ext;
158 struct lyd_node *sibling;
159};
160
161/**
Michal Vasko135719f2022-08-25 12:18:17 +0200162 * @brief Parsed data node with extension instance to validate.
163 */
164struct lyd_ctx_ext_node {
165 struct lysc_ext_instance *ext;
166 struct lyd_node *node;
167};
168
169/**
Radek Krejci84d7fd72021-07-14 18:32:21 +0200170 * @brief Common part to supplement the specific ::lyd_ctx_free_clb callbacks.
Radek Krejci1798aae2020-07-14 13:26:06 +0200171 */
Michal Vaskoddd76592022-01-17 13:34:48 +0100172void lyd_ctx_free(struct lyd_ctx *ctx);
Radek Krejci1798aae2020-07-14 13:26:06 +0200173
174/**
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200175 * @brief Parse submodule from YANG data.
Radek Krejci84d7fd72021-07-14 18:32:21 +0200176 * @param[in,out] context Parser context.
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200177 * @param[in] ly_ctx Context of YANG schemas.
178 * @param[in] main_ctx Parser context of main module.
Michal Vasko63f3d842020-07-08 10:10:14 +0200179 * @param[in] in Input structure.
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200180 * @param[out] submod Pointer to the parsed submodule structure.
181 * @return LY_ERR value - LY_SUCCESS, LY_EINVAL or LY_EVALID.
182 */
Michal Vaskod0625d72022-10-06 15:02:50 +0200183LY_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 +0200184 struct ly_in *in, struct lysp_submodule **submod);
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200185
186/**
187 * @brief Parse module from YANG data.
Radek Krejci84d7fd72021-07-14 18:32:21 +0200188 * @param[in] context Parser context.
Michal Vasko63f3d842020-07-08 10:10:14 +0200189 * @param[in] in Input structure.
190 * @param[in,out] mod Prepared module structure where the parsed information, including the parsed
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200191 * module structure, will be filled in.
Michal Vasko405cc9e2020-12-01 12:01:27 +0100192 * @return LY_ERR values.
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200193 */
Michal Vaskod0625d72022-10-06 15:02:50 +0200194LY_ERR yang_parse_module(struct lysp_yang_ctx **context, struct ly_in *in, struct lys_module *mod);
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200195
196/**
197 * @brief Parse module from YIN data.
198 *
199 * @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 +0200200 * @param[in] in Input structure.
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200201 * @param[in,out] mod Prepared module structure where the parsed information, including the parsed
202 * module structure, will be filled in.
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200203 * @return LY_ERR values.
204 */
Michal Vaskod0625d72022-10-06 15:02:50 +0200205LY_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 +0200206
207/**
208 * @brief Parse submodule from YIN data.
209 *
210 * @param[in,out] yin_ctx Context created during parsing, is used to finalize lysp_model after it's completly parsed.
211 * @param[in] ctx Libyang context.
212 * @param[in] main_ctx Parser context of main module.
Michal Vasko63f3d842020-07-08 10:10:14 +0200213 * @param[in] in Input structure.
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200214 * @param[in,out] submod Submodule structure where the parsed information, will be filled in.
215 * @return LY_ERR values.
216 */
Michal Vaskod0625d72022-10-06 15:02:50 +0200217LY_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 +0200218 struct ly_in *in, struct lysp_submodule **submod);
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200219
Radek Krejci1798aae2020-07-14 13:26:06 +0200220/**
Michal Vaskoe0665742021-02-11 11:08:44 +0100221 * @brief Parse XML string as a YANG data tree.
Michal Vaskoafac7822020-10-20 14:22:26 +0200222 *
Michal Vaskoe0665742021-02-11 11:08:44 +0100223 * @param[in] ctx libyang context.
aPiecekb0445f22021-06-24 11:34:07 +0200224 * @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 +0100225 * @param[in] parent Parent to connect the parsed nodes to, if any.
226 * @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 +0200227 * @param[in] in Input structure.
Michal Vaskoe0665742021-02-11 11:08:44 +0100228 * @param[in] parse_opts Options for parser, see @ref dataparseroptions.
229 * @param[in] val_opts Options for the validation phase, see @ref datavalidationoptions.
Michal Vaskoe3ed7dc2022-11-30 11:39:44 +0100230 * @param[in] int_opts Internal data parser options.
Michal Vaskoe0665742021-02-11 11:08:44 +0100231 * @param[out] parsed Set to add all the parsed siblings into.
Michal Vaskoddd76592022-01-17 13:34:48 +0100232 * @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 +0200233 * @param[out] lydctx_p Data parser context to finish validation.
234 * @return LY_ERR value.
235 */
Radek Krejcif16e2542021-02-17 15:39:23 +0100236LY_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 +0100237 struct lyd_node **first_p, struct ly_in *in, uint32_t parse_opts, uint32_t val_opts, uint32_t int_opts,
238 struct ly_set *parsed, ly_bool *subtree_sibling, struct lyd_ctx **lydctx_p);
239
240/**
241 * @brief Parse XML string as a NETCONF message.
242 *
243 * @param[in] ctx libyang context.
244 * @param[in] ext Optional extension instance to parse data following the schema tree specified in the extension instance
245 * @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.
247 * @param[in] in Input structure.
248 * @param[in] parse_opts Options for parser, see @ref dataparseroptions.
249 * @param[in] val_opts Options for the validation phase, see @ref datavalidationoptions.
250 * @param[in] data_type Expected NETCONF data type of the data.
251 * @param[out] envp Individual parsed envelopes tree, may be returned possibly even on an error.
252 * @param[out] parsed Set to add all the parsed siblings into.
253 * @param[out] subtree_sibling Set if ::LYD_PARSE_SUBTREE is used and another subtree is following in @p in.
254 * @param[out] lydctx_p Data parser context to finish validation.
255 * @return LY_ERR value.
256 */
257LY_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 +0100258 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 +0100259 struct lyd_node **envp, struct ly_set *parsed, struct lyd_ctx **lydctx_p);
Michal Vaskoafac7822020-10-20 14:22:26 +0200260
261/**
Michal Vaskoe0665742021-02-11 11:08:44 +0100262 * @brief Parse JSON string as a YANG data tree.
Michal Vaskoafac7822020-10-20 14:22:26 +0200263 *
Michal Vaskoafac7822020-10-20 14:22:26 +0200264 * @param[in] ctx libyang context.
aPiecekb0445f22021-06-24 11:34:07 +0200265 * @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 +0100266 * @param[in] parent Parent to connect the parsed nodes to, if any.
267 * @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 +0200268 * @param[in] in Input structure.
Michal Vaskoe0665742021-02-11 11:08:44 +0100269 * @param[in] parse_opts Options for parser, see @ref dataparseroptions.
270 * @param[in] val_opts Options for the validation phase, see @ref datavalidationoptions.
Michal Vaskoe3ed7dc2022-11-30 11:39:44 +0100271 * @param[in] int_opts Internal data parser options.
Michal Vaskoe0665742021-02-11 11:08:44 +0100272 * @param[out] parsed Set to add all the parsed siblings into.
Michal Vaskoddd76592022-01-17 13:34:48 +0100273 * @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 +0200274 * @param[out] lydctx_p Data parser context to finish validation.
275 * @return LY_ERR value.
276 */
Radek Krejcif16e2542021-02-17 15:39:23 +0100277LY_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 +0100278 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 +0100279 struct ly_set *parsed, ly_bool *subtree_sibling, struct lyd_ctx **lydctx_p);
Michal Vaskoafac7822020-10-20 14:22:26 +0200280
281/**
Michal Vaskoe0665742021-02-11 11:08:44 +0100282 * @brief Parse binary LYB data 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_lyb(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 Vaskoe0665742021-02-11 11:08:44 +0100302 * @brief Search all the parents for an operation node, check validity based on internal parser flags.
Michal Vaskoafac7822020-10-20 14:22:26 +0200303 *
Michal Vaskoe0665742021-02-11 11:08:44 +0100304 * @param[in] parent Parent to connect the parsed nodes to.
Radek Krejci84d7fd72021-07-14 18:32:21 +0200305 * @param[in] int_opts Internal parser options.
Michal Vaskoe0665742021-02-11 11:08:44 +0100306 * @param[out] op Found operation, if any.
Michal Vaskoafac7822020-10-20 14:22:26 +0200307 * @return LY_ERR value.
308 */
Michal Vaskoe0665742021-02-11 11:08:44 +0100309LY_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 +0200310
311/**
Radek Krejci1798aae2020-07-14 13:26:06 +0200312 * @brief Check that a data node representing the @p snode is suitable based on options.
313 *
314 * @param[in] lydctx Common data parsers context.
315 * @param[in] snode Schema node to check.
316 * @return LY_SUCCESS or LY_EVALID
317 */
318LY_ERR lyd_parser_check_schema(struct lyd_ctx *lydctx, const struct lysc_node *snode);
319
320/**
Radek Krejci8678fa42020-08-18 16:07:28 +0200321 * @brief Wrapper around ::lyd_create_term() for data parsers.
Radek Krejci1798aae2020-07-14 13:26:06 +0200322 *
323 * @param[in] lydctx Data parser context.
Radek Krejci84d7fd72021-07-14 18:32:21 +0200324 * @param[in] schema Schema node of the new data node.
325 * @param[in] value String value to be parsed.
326 * @param[in] value_len Length of @p value, must be set correctly.
327 * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed.
328 * @param[in] format Input format of @p value.
329 * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix).
330 * @param[in] hints [Data parser's hints](@ref lydvalhints) for the value's type.
331 * @param[out] node Created node.
332 * @return LY_SUCCESS on success.
333 * @return LY_EINCOMPLETE in case data tree is needed to finish the validation.
334 * @return LY_ERR value if an error occurred.
Radek Krejci1798aae2020-07-14 13:26:06 +0200335 */
Radek Krejci09c77442021-04-26 11:10:34 +0200336LY_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 +0200337 ly_bool *dynamic, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints, struct lyd_node **node);
Radek Krejci1798aae2020-07-14 13:26:06 +0200338
339/**
Radek Krejci8678fa42020-08-18 16:07:28 +0200340 * @brief Wrapper around ::lyd_create_meta() for data parsers.
Radek Krejci1798aae2020-07-14 13:26:06 +0200341 *
342 * @param[in] lydctx Data parser context.
Michal Vaskob68571a2020-11-06 17:18:41 +0100343 * @param[in] parent Parent of the created meta. Must be set if @p meta is NULL.
344 * @param[in,out] meta First existing meta to connect to or empty pointer to set. Must be set if @p parent is NULL.
345 * @param[in] mod Module of the created metadata.
346 * @param[in] name Metadata name.
347 * @param[in] name_len Length of @p name.
348 * @param[in] value Metadata value.
349 * @param[in] value_len Length of @p value.
350 * @param[in,out] dynamic Whether the @p value is dynamically allocated, is adjusted once the value is assigned.
351 * @param[in] format Prefix format.
352 * @param[in] prefix_data Prefix format data (see ::ly_resolve_prefix()).
Michal Vaskofeca4fb2020-10-05 08:58:40 +0200353 * @param[in] hints [Value hint](@ref lydvalhints) from the parser regarding the value type.
Michal Vaskoddd76592022-01-17 13:34:48 +0100354 * @param[in] ctx_node Value context node.
Michal Vaskob68571a2020-11-06 17:18:41 +0100355 * @return LY_ERR value.
Radek Krejci1798aae2020-07-14 13:26:06 +0200356 */
Michal Vaskoc8a230d2020-08-14 12:17:10 +0200357LY_ERR lyd_parser_create_meta(struct lyd_ctx *lydctx, struct lyd_node *parent, struct lyd_meta **meta,
Michal Vaskoddd76592022-01-17 13:34:48 +0100358 const struct lys_module *mod, const char *name, size_t name_len, const void *value, size_t value_len,
359 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 +0200360
Michal Vasko95c6d5c2022-05-20 10:33:39 +0200361/**
362 * @brief Check that a list has all its keys.
363 *
364 * @param[in] node List to check.
365 * @return LY_SUCCESS on success.
366 * @return LY_ENOT on a missing key.
367 */
368LY_ERR lyd_parse_check_keys(struct lyd_node *node);
369
370/**
371 * @brief Set data flags for a newly parsed node.
372 *
373 * @param[in] node Node to use.
374 * @param[in,out] meta Node metadata, may be removed from.
375 * @param[in] lydctx Data parsing context.
376 * @param[in] ext Extension instance if @p node was parsed for one.
377 * @return LY_ERR value.
378 */
379LY_ERR lyd_parse_set_data_flags(struct lyd_node *node, struct lyd_meta **meta, struct lyd_ctx *lydctx,
380 struct lysc_ext_instance *ext);
381
Michal Vasko193dacd2022-10-13 08:43:05 +0200382/**
383 * @brief Parse an instance extension statement.
384 *
385 * @param[in] pctx Parse context.
386 * @param[in] substmt Parsed ext instance substatement info.
387 * @param[in] stmt Parsed generic statement to process.
388 * @return LY_ERR value.
389 */
390LY_ERR lys_parse_ext_instance_stmt(struct lysp_ctx *pctx, struct lysp_ext_substmt *substmt, struct lysp_stmt *stmt);
391
Radek Krejcif0e1ba52020-05-22 15:14:35 +0200392#endif /* LY_PARSER_INTERNAL_H_ */