blob: 06093c082cc631beb69dca4ac6c306a1b3a64e5c [file] [log] [blame]
Radek Krejci7931b192020-06-25 17:05:03 +02001/**
2 * @file parser_data.h
3 * @author Radek Krejci <rkrejci@cesnet.cz>
4 * @brief Data parsers for libyang
5 *
6 * Copyright (c) 2015-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_DATA_H_
16#define LY_PARSER_DATA_H_
17
18#include "tree_data.h"
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24struct ly_in;
25
26/**
Radek Krejci8678fa42020-08-18 16:07:28 +020027 * @page howtoDataParsers Parsing Data
28 *
29 * Data parser allows to read instances from a specific format. libyang supports the following data formats:
30 *
31 * - XML
32 *
33 * Original data format used in NETCONF protocol. XML mapping is part of the YANG specification
34 * ([RFC 6020](http://tools.ietf.org/html/rfc6020)).
35 *
36 * - JSON
37 *
38 * The alternative data format available in RESTCONF protocol. Specification of JSON encoding of data modeled by YANG
39 * can be found in [RFC 7951](http://tools.ietf.org/html/rfc7951). The specification does not cover RPCs, actions and
40 * Notifications, so the representation of these data trees is proprietary and corresponds to the representation of these
41 * trees in XML.
42 *
43 * While the parsers themselves process the input data only syntactically, all the parser functions actually incorporate
44 * the [common validator](@ref howtoDataValidation) checking the input data semantically. Therefore, the parser functions
45 * accepts two groups of options - @ref dataparseroptions and @ref datavalidationoptions.
46 *
47 * In contrast to the schema parser, data parser also accepts empty input data if such an empty data tree is valid
48 * according to the schemas in the libyang context (i.e. there are no top level mandatory nodes).
49 *
50 * There are individual functions to process different types of the data instances trees:
51 * - ::lyd_parse_data() is intended for standard configuration data trees. According to the given
52 * [parser options](@ref dataparseroptions), the caller can further specify which kind of data tree is expected:
53 * - *complete :running datastore*: this is the default case, possibly with the use of (some of) the
54 * ::LYD_PARSE_STRICT, ::LYD_PARSE_OPAQ or ::LYD_VALIDATE_PRESENT options.
55 * - *complete configuration-only datastore* (such as :startup): in this case it is necessary to except all state data
56 * using ::LYD_PARSE_NO_STATE option.
57 * - *incomplete datastore*: there are situation when the data tree is incomplete or invalid by specification. For
58 * example the *:operational* datastore is not necessarily valid and results of the NETCONF's \<get\> or \<get-config\>
59 * oprations used with filters will be incomplete (and thus invalid). This can be allowed using ::LYD_PARSE_ONLY,
60 * the ::LYD_PARSE_NO_STATE should be used for the data returned by \<get-config\> operation.
Radek Krejcif16e2542021-02-17 15:39:23 +010061 * - ::lyd_parse_ext_data() is used for parsing configuration data trees defined inside extension instances, such as
62 * instances of yang-data extension specified in [RFC 8040](http://tools.ietf.org/html/rfc8040).
Michal Vaskoe0665742021-02-11 11:08:44 +010063 * - ::lyd_parse_op() is used for parsing RPCs/actions, replies, and notifications. Even NETCONF rpc, rpc-reply, and
Radek Krejcif16e2542021-02-17 15:39:23 +010064 * notification messages are supported.
65 * - ::lyd_parse_ext_op() is used for parsing RPCs/actions, replies, and notifications defined inside extension instances.
Radek Krejci8678fa42020-08-18 16:07:28 +020066 *
67 * Further information regarding the processing input instance data can be found on the following pages.
68 * - @subpage howtoDataValidation
69 * - @subpage howtoDataWD
70 *
71 * Functions List
72 * --------------
73 * - ::lyd_parse_data()
74 * - ::lyd_parse_data_mem()
75 * - ::lyd_parse_data_fd()
76 * - ::lyd_parse_data_path()
Radek Krejcif16e2542021-02-17 15:39:23 +010077 * - ::lyd_parse_ext_data()
Michal Vaskoe0665742021-02-11 11:08:44 +010078 * - ::lyd_parse_op()
Radek Krejcif16e2542021-02-17 15:39:23 +010079 * - ::lyd_parse_ext_op()
Radek Krejci8678fa42020-08-18 16:07:28 +020080 */
81
82/**
83 * @page howtoDataValidation Validating Data
84 *
85 * Data validation is performed implicitly to the input data processed by the [parser](@ref howtoDataParsers) and
86 * on demand via the lyd_validate_*() functions. The explicit validation process is supposed to be used when a (complex or
87 * simple) change is done on the data tree (via [data manipulation](@ref howtoDataManipulation) functions) and the data
88 * tree is expected to be valid (it doesn't make sense to validate modified result of filtered \<get\> operation).
89 *
90 * Similarly to the [data parser](@ref howtoDataParsers), there are individual functions to validate standard data tree
91 * (::lyd_validate_all()) and RPC, Action and Notification (::lyd_validate_op()). For the standard data trees, it is possible
92 * to modify the validation process by @ref datavalidationoptions. This way the state data can be prohibited
93 * (::LYD_VALIDATE_NO_STATE) and checking for mandatory nodes can be limited to the YANG modules with already present data
94 * instances (::LYD_VALIDATE_PRESENT). Validation of the standard data tree can be also limited with ::lyd_validate_module()
95 * function, which scopes only to a specified single YANG module.
96 *
97 * Since the operation data trees (RPCs, Actions or Notifications) can reference (leafref, instance-identifier, when/must
98 * expressions) data from a datastore tree, ::lyd_validate_op() may require additional data tree to be provided. This is a
99 * difference in contrast to the parsing process, when the data are loaded from an external source and invalid reference
100 * outside the operation tree is acceptable.
101 *
102 * Functions List
103 * --------------
104 * - ::lyd_validate_all()
105 * - ::lyd_validate_module()
106 * - ::lyd_validate_op()
107 */
108
109/**
Radek Krejci7931b192020-06-25 17:05:03 +0200110 * @addtogroup datatree
111 * @{
112 */
113
114/**
Radek Krejci8678fa42020-08-18 16:07:28 +0200115 * @ingroup datatree
Radek Krejci7931b192020-06-25 17:05:03 +0200116 * @defgroup dataparseroptions Data parser options
117 *
118 * Various options to change the data tree parsers behavior.
119 *
120 * Default parser behavior:
121 * - complete input file is always parsed. In case of XML, even not well-formed XML document (multiple top-level
122 * elements) is parsed in its entirety,
123 * - parser silently ignores data without matching schema node definition,
124 * - list instances are checked whether they have all the keys, error is raised if not.
125 *
126 * Default parser validation behavior:
127 * - the provided data are expected to provide complete datastore content (both the configuration and state data)
128 * and performs data validation according to all YANG rules, specifics follow,
129 * - list instances are expected to have all the keys (it is not checked),
130 * - instantiated (status) obsolete data print a warning,
131 * - all types are fully resolved (leafref/instance-identifier targets, unions) and must be valid (lists have
132 * all the keys, leaf(-lists) correct values),
133 * - when statements on existing nodes are evaluated, if not satisfied, a validation error is raised,
Radek Krejci7931b192020-06-25 17:05:03 +0200134 * - invalid multiple data instances/data from several cases cause a validation error,
Michal Vaskoa6669ba2020-08-06 16:14:26 +0200135 * - implicit nodes (NP containers and default values) are added.
Radek Krejci7931b192020-06-25 17:05:03 +0200136 * @{
137 */
138/* note: keep the lower 16bits free for use by LYD_VALIDATE_ flags. They are not supposed to be combined together,
139 * but since they are used (as a separate parameter) together in some functions, we want to keep them in a separated
140 * range to be able detect that the caller put wrong flags into the parser/validate options parameter. */
141#define LYD_PARSE_ONLY 0x010000 /**< Data will be only parsed and no validation will be performed. When statements
142 are kept unevaluated, union types may not be fully resolved, if-feature
143 statements are not checked, and default values are not added (only the ones
144 parsed are present). */
Michal Vasko0f3377d2020-11-09 20:56:11 +0100145#define LYD_PARSE_STRICT 0x020000 /**< Instead of silently ignoring data without schema definition raise an error.
Michal Vasko369f7a62021-02-01 08:59:36 +0100146 Do not combine with ::LYD_PARSE_OPAQ (except for ::LYD_LYB). */
Michal Vasko0f3377d2020-11-09 20:56:11 +0100147#define LYD_PARSE_OPAQ 0x040000 /**< Instead of silently ignoring data without definition, parse them into
Michal Vasko369f7a62021-02-01 08:59:36 +0100148 an opaq node. Do not combine with ::LYD_PARSE_STRICT (except for ::LYD_LYB). */
149#define LYD_PARSE_NO_STATE 0x080000 /**< Forbid state data in the parsed data. Usually used with ::LYD_VALIDATE_NO_STATE. */
Radek Krejci7931b192020-06-25 17:05:03 +0200150
Michal Vasko0f3377d2020-11-09 20:56:11 +0100151#define LYD_PARSE_LYB_MOD_UPDATE 0x100000 /**< Only for LYB format, allow parsing data printed using a specific module
Radek Krejci7931b192020-06-25 17:05:03 +0200152 revision to be loaded even with a module with the same name but newer
153 revision. */
Michal Vasko6ee6f432021-07-16 09:49:14 +0200154#define LYD_PARSE_ORDERED 0x200000 /**< Do not search for the correct place of each node but instead expect
155 that the nodes are being parsed in the correct schema-based order,
156 which is always true if the data were printed by libyang and not
157 modified manually. If this flag is used incorrectly (for unordered data),
158 the behavior is undefined and most functions executed with these
159 data will not work correctly. */
Michal Vaskoafac7822020-10-20 14:22:26 +0200160
161#define LYD_PARSE_OPTS_MASK 0xFFFF0000 /**< Mask for all the LYD_PARSE_ options. */
162
Radek Krejci7931b192020-06-25 17:05:03 +0200163/** @} dataparseroptions */
164
Radek Krejci7931b192020-06-25 17:05:03 +0200165/**
Radek Krejci7931b192020-06-25 17:05:03 +0200166 * @ingroup datatree
Radek Krejci8678fa42020-08-18 16:07:28 +0200167 * @defgroup datavalidationoptions Data validation options
Radek Krejci7931b192020-06-25 17:05:03 +0200168 *
169 * Various options to change data validation behaviour, both for the parser and separate validation.
170 *
171 * Default separate validation behavior:
172 * - the provided data are expected to provide complete datastore content (both the configuration and state data)
173 * and performs data validation according to all YANG rules, specifics follow,
174 * - instantiated (status) obsolete data print a warning,
175 * - all types are fully resolved (leafref/instance-identifier targets, unions) and must be valid (lists have
176 * all the keys, leaf(-lists) correct values),
177 * - when statements on existing nodes are evaluated. Depending on the previous when state (from previous validation
178 * or parsing), the node is silently auto-deleted if the state changed from true to false, otherwise a validation error
179 * is raised if it evaluates to false,
180 * - if-feature statements are evaluated,
181 * - data from several cases behave based on their previous state (from previous validation or parsing). If there existed
182 * already a case and another one was added, the previous one is silently auto-deleted. Otherwise (if data from 2 or
183 * more cases were created) a validation error is raised,
184 * - default values are added.
185 *
186 * @{
187 */
Michal Vasko369f7a62021-02-01 08:59:36 +0100188#define LYD_VALIDATE_NO_STATE 0x0001 /**< Consider state data not allowed and raise an error if they are found.
189 Also, no implicit state data are added. */
Michal Vaskoafac7822020-10-20 14:22:26 +0200190#define LYD_VALIDATE_PRESENT 0x0002 /**< Validate only modules whose data actually exist. */
191
192#define LYD_VALIDATE_OPTS_MASK 0x0000FFFF /**< Mask for all the LYD_VALIDATE_* options. */
Radek Krejci7931b192020-06-25 17:05:03 +0200193
194/** @} datavalidationoptions */
195
196/**
Radek Krejci7931b192020-06-25 17:05:03 +0200197 * @brief Parse (and validate) data from the input handler as a YANG data tree.
198 *
199 * @param[in] ctx Context to connect with the tree being built here.
Michal Vaskoe0665742021-02-11 11:08:44 +0100200 * @param[in] parent Optional parent to connect the parsed nodes to.
Radek Krejci7931b192020-06-25 17:05:03 +0200201 * @param[in] in The input handle to provide the dumped data in the specified @p format to parse (and validate).
202 * @param[in] format Format of the input data to be parsed. Can be 0 to try to detect format from the input handler.
203 * @param[in] parse_options Options for parser, see @ref dataparseroptions.
204 * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions.
Michal Vaskoe0665742021-02-11 11:08:44 +0100205 * @param[out] tree Full parsed data tree, note that NULL can be a valid tree. If @p parent is set, set to NULL.
Radek Krejci7931b192020-06-25 17:05:03 +0200206 * @return LY_SUCCESS in case of successful parsing (and validation).
Michal Vasko6d497662020-07-08 10:42:57 +0200207 * @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions.
Radek Krejci7931b192020-06-25 17:05:03 +0200208 */
Michal Vaskoe0665742021-02-11 11:08:44 +0100209LY_ERR lyd_parse_data(const struct ly_ctx *ctx, struct lyd_node *parent, struct ly_in *in, LYD_FORMAT format,
210 uint32_t parse_options, uint32_t validate_options, struct lyd_node **tree);
Radek Krejci7931b192020-06-25 17:05:03 +0200211
212/**
213 * @brief Parse (and validate) input data as a YANG data tree.
214 *
Michal Vaskoe0665742021-02-11 11:08:44 +0100215 * Wrapper around ::lyd_parse_data() hiding work with the input handler and some obscure options.
Radek Krejci7931b192020-06-25 17:05:03 +0200216 *
217 * @param[in] ctx Context to connect with the tree being built here.
218 * @param[in] data The input data in the specified @p format to parse (and validate).
Michal Vasko107c8162021-09-23 11:21:53 +0200219 * @param[in] format Format of the input data to be parsed.
Radek Krejci7931b192020-06-25 17:05:03 +0200220 * @param[in] parse_options Options for parser, see @ref dataparseroptions.
221 * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions.
Michal Vaskoe0665742021-02-11 11:08:44 +0100222 * @param[out] tree Full parsed data tree, note that NULL can be a valid tree
Radek Krejci7931b192020-06-25 17:05:03 +0200223 * @return LY_SUCCESS in case of successful parsing (and validation).
Michal Vasko6d497662020-07-08 10:42:57 +0200224 * @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions.
Radek Krejci7931b192020-06-25 17:05:03 +0200225 */
Radek Krejci1deb5be2020-08-26 16:43:36 +0200226LY_ERR lyd_parse_data_mem(const struct ly_ctx *ctx, const char *data, LYD_FORMAT format, uint32_t parse_options,
227 uint32_t validate_options, struct lyd_node **tree);
Radek Krejci7931b192020-06-25 17:05:03 +0200228
229/**
230 * @brief Parse (and validate) input data as a YANG data tree.
231 *
Michal Vaskoe0665742021-02-11 11:08:44 +0100232 * Wrapper around ::lyd_parse_data() hiding work with the input handler and some obscure options.
Radek Krejci7931b192020-06-25 17:05:03 +0200233 *
234 * @param[in] ctx Context to connect with the tree being built here.
Michal Vaskoe0665742021-02-11 11:08:44 +0100235 * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the input data in the
236 * specified @p format to parse.
Michal Vasko107c8162021-09-23 11:21:53 +0200237 * @param[in] format Format of the input data to be parsed.
Radek Krejci7931b192020-06-25 17:05:03 +0200238 * @param[in] parse_options Options for parser, see @ref dataparseroptions.
239 * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions.
Michal Vaskoe0665742021-02-11 11:08:44 +0100240 * @param[out] tree Full parsed data tree, note that NULL can be a valid tree
Radek Krejci7931b192020-06-25 17:05:03 +0200241 * @return LY_SUCCESS in case of successful parsing (and validation).
Michal Vasko6d497662020-07-08 10:42:57 +0200242 * @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions.
Radek Krejci7931b192020-06-25 17:05:03 +0200243 */
Michal Vaskoe0665742021-02-11 11:08:44 +0100244LY_ERR lyd_parse_data_fd(const struct ly_ctx *ctx, int fd, LYD_FORMAT format, uint32_t parse_options,
245 uint32_t validate_options, struct lyd_node **tree);
Radek Krejci7931b192020-06-25 17:05:03 +0200246
247/**
248 * @brief Parse (and validate) input data as a YANG data tree.
249 *
Michal Vaskoe0665742021-02-11 11:08:44 +0100250 * Wrapper around ::lyd_parse_data() hiding work with the input handler and some obscure options.
Radek Krejci7931b192020-06-25 17:05:03 +0200251 *
252 * @param[in] ctx Context to connect with the tree being built here.
253 * @param[in] path Path to the file with the input data in the specified @p format to parse (and validate).
Michal Vasko107c8162021-09-23 11:21:53 +0200254 * @param[in] format Format of the input data to be parsed. Can be 0 to try to detect format from @p path extension.
Radek Krejci7931b192020-06-25 17:05:03 +0200255 * @param[in] parse_options Options for parser, see @ref dataparseroptions.
256 * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions.
Michal Vaskoe0665742021-02-11 11:08:44 +0100257 * @param[out] tree Full parsed data tree, note that NULL can be a valid tree
Radek Krejci7931b192020-06-25 17:05:03 +0200258 * @return LY_SUCCESS in case of successful parsing (and validation).
Michal Vasko6d497662020-07-08 10:42:57 +0200259 * @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions.
Radek Krejci7931b192020-06-25 17:05:03 +0200260 */
Radek Krejci1deb5be2020-08-26 16:43:36 +0200261LY_ERR lyd_parse_data_path(const struct ly_ctx *ctx, const char *path, LYD_FORMAT format, uint32_t parse_options,
262 uint32_t validate_options, struct lyd_node **tree);
Radek Krejci7931b192020-06-25 17:05:03 +0200263
264/**
Radek Krejci75104122021-04-01 15:37:45 +0200265 * @brief Parse (and validate) data from the input handler as an extension data tree following the schema tree of the given
Radek Krejcif16e2542021-02-17 15:39:23 +0100266 * extension instance.
267 *
268 * Note that the data being parsed are limited only to the schema tree specified by the given extension, it does not allow
269 * to mix them with the standard data from any module.
270 *
Radek Krejci75104122021-04-01 15:37:45 +0200271 * Directly applicable to data defined as [yang-data](@ref howtoDataYangdata).
272 *
Radek Krejcif16e2542021-02-17 15:39:23 +0100273 * @param[in] ext Extension instance providing the specific schema tree to match with the data being parsed.
274 * @param[in] parent Optional parent to connect the parsed nodes to.
275 * @param[in] in The input handle to provide the dumped data in the specified @p format to parse (and validate).
276 * @param[in] format Format of the input data to be parsed. Can be 0 to try to detect format from the input handler.
277 * @param[in] parse_options Options for parser, see @ref dataparseroptions.
278 * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions.
279 * @param[out] tree Full parsed data tree, note that NULL can be a valid tree. If @p parent is set, set to NULL.
280 * @return LY_SUCCESS in case of successful parsing (and validation).
281 * @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions.
282 */
283LY_ERR lyd_parse_ext_data(const struct lysc_ext_instance *ext, struct lyd_node *parent, struct ly_in *in, LYD_FORMAT format,
284 uint32_t parse_options, uint32_t validate_options, struct lyd_node **tree);
285
286/**
Michal Vaskoe0665742021-02-11 11:08:44 +0100287 * @ingroup datatree
288 * @defgroup datatype Data operation type
Radek Krejci7931b192020-06-25 17:05:03 +0200289 *
Michal Vaskoe0665742021-02-11 11:08:44 +0100290 * Operation provided to ::lyd_validate_op() to validate.
291 *
292 * The operation cannot be determined automatically since RPC/action and a reply to it share the common top level node
293 * referencing the RPC/action schema node and may not have any input/output children to use for distinction.
294 *
295 * @{
Radek Krejci7931b192020-06-25 17:05:03 +0200296 */
Michal Vaskoe0665742021-02-11 11:08:44 +0100297enum lyd_type {
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100298 LYD_TYPE_DATA_YANG = 0, /* generic YANG instance data */
299 LYD_TYPE_RPC_YANG, /* instance of a YANG RPC/action request with only "input" data children,
300 including all parents in case of an action */
301 LYD_TYPE_NOTIF_YANG, /* instance of a YANG notification , including all parents in case of a nested one */
302 LYD_TYPE_REPLY_YANG, /* instance of a YANG RPC/action reply with only "output" data children,
303 including all parents in case of an action */
304
305 LYD_TYPE_RPC_NETCONF, /* complete NETCONF RPC invocation as defined for
306 [RPC](https://tools.ietf.org/html/rfc7950#section-7.14.4) and
307 [action](https://tools.ietf.org/html/rfc7950#section-7.15.2) */
308 LYD_TYPE_NOTIF_NETCONF, /* complete NETCONF notification message as defined for
309 [notification](https://tools.ietf.org/html/rfc7950#section-7.16.2) */
310 LYD_TYPE_REPLY_NETCONF /* complete NETCONF RPC reply as defined for
311 [RPC](https://tools.ietf.org/html/rfc7950#section-7.14.4) and
312 [action](https://tools.ietf.org/html/rfc7950#section-7.15.2) */
Michal Vaskoe0665742021-02-11 11:08:44 +0100313};
314/** @} datatype */
Radek Krejci7931b192020-06-25 17:05:03 +0200315
316/**
Michal Vaskoe0665742021-02-11 11:08:44 +0100317 * @brief Parse YANG data into an operation data tree.
Radek Krejci7931b192020-06-25 17:05:03 +0200318 *
Michal Vaskoe0665742021-02-11 11:08:44 +0100319 * At least one of @p parent, @p tree, or @p op must always be set.
Radek Krejci7931b192020-06-25 17:05:03 +0200320 *
Michal Vaskoe0665742021-02-11 11:08:44 +0100321 * Specific @p data_type values have different parameter meaning as follows:
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100322 * - ::LYD_TYPE_RPC_NETCONF:
Michal Vaskoe0665742021-02-11 11:08:44 +0100323 * - @p parent - must be NULL, the whole RPC is expected;
324 * - @p format - must be ::LYD_XML, NETCONF supports only this format;
325 * - @p tree - must be provided, all the NETCONF-specific XML envelopes will be returned here as
Michal Vasko299d5d12021-02-16 16:36:37 +0100326 * a separate opaque data tree, even if the function fails, this may be returned;
Michal Vaskoe0665742021-02-11 11:08:44 +0100327 * - @p op - must be provided, the RPC/action data tree itself will be returned here, pointing to the operation;
328 *
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100329 * - ::LYD_TYPE_NOTIF_NETCONF:
330 * - @p parent - must be NULL, the whole notification is expected;
331 * - @p format - must be ::LYD_XML, NETCONF supports only this format;
332 * - @p tree - must be provided, all the NETCONF-specific XML envelopes will be returned here as
Michal Vaskof4da8892021-02-19 09:15:18 +0100333 * a separate opaque data tree, even if the function fails, this may be returned;
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100334 * - @p op - must be provided, the notification data tree itself will be returned here, pointing to the operation;
335 *
336 * - ::LYD_TYPE_REPLY_NETCONF:
Michal Vaskoe0665742021-02-11 11:08:44 +0100337 * - @p parent - must be set, pointing to the invoked RPC operation (RPC or action) node;
338 * - @p format - must be ::LYD_XML, NETCONF supports only this format;
339 * - @p tree - must be provided, all the NETCONF-specific XML envelopes will be returned here as
Michal Vaskof4da8892021-02-19 09:15:18 +0100340 * a separate opaque data tree, even if the function fails, this may be returned;
Michal Vasko1e4c68e2021-02-18 15:03:01 +0100341 * - @p op - must be NULL, the reply is appended to the RPC;
342 * Note that there are 3 kinds of NETCONF replies - ok, error, and data. Only data reply appends any nodes to the RPC.
Michal Vaskoe0665742021-02-11 11:08:44 +0100343 *
344 * @param[in] ctx libyang context.
345 * @param[in] parent Optional parent to connect the parsed nodes to.
346 * @param[in] in Input handle to read the input from.
347 * @param[in] format Expected format of the data in @p in.
348 * @param[in] data_type Expected operation to parse (@ref datatype).
349 * @param[out] tree Optional full parsed data tree. If @p parent is set, set to NULL.
Michal Vasko438b5292021-06-09 14:31:25 +0200350 * @param[out] op Optional pointer to the operation (action/RPC) node.
Michal Vaskoe0665742021-02-11 11:08:44 +0100351 * @return LY_ERR value.
Michal Vaskob7dba862021-02-18 16:10:02 +0100352 * @return LY_ENOT if @p data_type is a NETCONF message and the root XML element is not the expected one.
Radek Krejci7931b192020-06-25 17:05:03 +0200353 */
Michal Vaskoe0665742021-02-11 11:08:44 +0100354LY_ERR lyd_parse_op(const struct ly_ctx *ctx, struct lyd_node *parent, struct ly_in *in, LYD_FORMAT format,
355 enum lyd_type data_type, struct lyd_node **tree, struct lyd_node **op);
Radek Krejci7931b192020-06-25 17:05:03 +0200356
357/**
Radek Krejci75104122021-04-01 15:37:45 +0200358 * @brief Parse extension data into an operation data tree following only the specification from the given extension instance.
359 *
360 * Directly applicable to data defined as [yang-data](@ref howtoDataYangdata).
Radek Krejcif16e2542021-02-17 15:39:23 +0100361 *
362 * At least one of @p parent, @p tree, or @p op must always be set.
363 *
364 * Specific @p data_type values have different parameter meaning as follows:
365 * - ::LYD_TYPE_RPC_NETCONF:
366 * - @p parent - must be NULL, the whole RPC is expected;
367 * - @p format - must be ::LYD_XML, NETCONF supports only this format;
368 * - @p tree - must be provided, all the NETCONF-specific XML envelopes will be returned here as
369 * a separate opaque data tree, even if the function fails, this may be returned;
370 * - @p op - must be provided, the RPC/action data tree itself will be returned here, pointing to the operation;
371 *
372 * - ::LYD_TYPE_NOTIF_NETCONF:
373 * - @p parent - must be NULL, the whole notification is expected;
374 * - @p format - must be ::LYD_XML, NETCONF supports only this format;
375 * - @p tree - must be provided, all the NETCONF-specific XML envelopes will be returned here as
376 * a separate opaque data tree, even if the function fails, this may be returned;
377 * - @p op - must be provided, the notification data tree itself will be returned here, pointing to the operation;
378 *
379 * - ::LYD_TYPE_REPLY_NETCONF:
380 * - @p parent - must be set, pointing to the invoked RPC operation (RPC or action) node;
381 * - @p format - must be ::LYD_XML, NETCONF supports only this format;
382 * - @p tree - must be provided, all the NETCONF-specific XML envelopes will be returned here as
383 * a separate opaque data tree, even if the function fails, this may be returned;
384 * - @p op - must be NULL, the reply is appended to the RPC;
385 * Note that there are 3 kinds of NETCONF replies - ok, error, and data. Only data reply appends any nodes to the RPC.
386 *
387 * @param[in] ext Extension instance providing the specific schema tree to match with the data being parsed.
388 * @param[in] parent Optional parent to connect the parsed nodes to.
389 * @param[in] in Input handle to read the input from.
390 * @param[in] format Expected format of the data in @p in.
391 * @param[in] data_type Expected operation to parse (@ref datatype).
392 * @param[out] tree Optional full parsed data tree. If @p parent is set, set to NULL.
Michal Vasko438b5292021-06-09 14:31:25 +0200393 * @param[out] op Optional pointer to the operation (action/RPC) node.
Radek Krejcif16e2542021-02-17 15:39:23 +0100394 * @return LY_ERR value.
395 * @return LY_ENOT if @p data_type is a NETCONF message and the root XML element is not the expected one.
396 */
397LY_ERR lyd_parse_ext_op(const struct lysc_ext_instance *ext, struct lyd_node *parent, struct ly_in *in, LYD_FORMAT format,
398 enum lyd_type data_type, struct lyd_node **tree, struct lyd_node **op);
399
400/**
Radek Krejci7931b192020-06-25 17:05:03 +0200401 * @brief Fully validate a data tree.
402 *
403 * @param[in,out] tree Data tree to recursively validate. May be changed by validation.
404 * @param[in] ctx libyang context. Can be NULL if @p tree is set.
405 * @param[in] val_opts Validation options (@ref datavalidationoptions).
Michal Vasko8104fd42020-07-13 11:09:51 +0200406 * @param[out] diff Optional diff with any changes made by the validation.
Radek Krejci7931b192020-06-25 17:05:03 +0200407 * @return LY_SUCCESS on success.
408 * @return LY_ERR error on error.
409 */
Radek Krejci1deb5be2020-08-26 16:43:36 +0200410LY_ERR lyd_validate_all(struct lyd_node **tree, const struct ly_ctx *ctx, uint32_t val_opts, struct lyd_node **diff);
Radek Krejci7931b192020-06-25 17:05:03 +0200411
412/**
Michal Vasko26e80012020-07-08 10:55:46 +0200413 * @brief Fully validate a data tree of a module.
Radek Krejci7931b192020-06-25 17:05:03 +0200414 *
415 * @param[in,out] tree Data tree to recursively validate. May be changed by validation.
Michal Vasko26e80012020-07-08 10:55:46 +0200416 * @param[in] module Module whose data (and schema restrictions) to validate.
Radek Krejci7931b192020-06-25 17:05:03 +0200417 * @param[in] val_opts Validation options (@ref datavalidationoptions).
Michal Vasko8104fd42020-07-13 11:09:51 +0200418 * @param[out] diff Optional diff with any changes made by the validation.
Radek Krejci7931b192020-06-25 17:05:03 +0200419 * @return LY_SUCCESS on success.
420 * @return LY_ERR error on error.
421 */
Radek Krejci1deb5be2020-08-26 16:43:36 +0200422LY_ERR lyd_validate_module(struct lyd_node **tree, const struct lys_module *module, uint32_t val_opts, struct lyd_node **diff);
Radek Krejci7931b192020-06-25 17:05:03 +0200423
424/**
Michal Vaskoe0665742021-02-11 11:08:44 +0100425 * @brief Validate an RPC/action request, reply, or notification.
Radek Krejci7931b192020-06-25 17:05:03 +0200426 *
427 * @param[in,out] op_tree Operation tree with any parents. It can point to the operation itself or any of
428 * its parents, only the operation subtree is actually validated.
Michal Vaskoe0665742021-02-11 11:08:44 +0100429 * @param[in] dep_tree Tree to be used for validating references from the operation subtree.
430 * @param[in] data_type Operation type to validate (only YANG operations are accepted, @ref datatype).
Michal Vasko8104fd42020-07-13 11:09:51 +0200431 * @param[out] diff Optional diff with any changes made by the validation.
Radek Krejci7931b192020-06-25 17:05:03 +0200432 * @return LY_SUCCESS on success.
433 * @return LY_ERR error on error.
434 */
Michal Vaskoe0665742021-02-11 11:08:44 +0100435LY_ERR lyd_validate_op(struct lyd_node *op_tree, const struct lyd_node *dep_tree, enum lyd_type data_type,
436 struct lyd_node **diff);
Radek Krejci7931b192020-06-25 17:05:03 +0200437
438/** @} datatree */
439
440#ifdef __cplusplus
441}
442#endif
443
444#endif /* LY_PARSER_DATA_H_ */