Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file parser_data.h |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Michal Vasko | af5a8dd | 2023-03-02 11:25:02 +0100 | [diff] [blame] | 4 | * @author Michal Vasko <mvasko@cesnet.cz> |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 5 | * @brief Data parsers for libyang |
| 6 | * |
Michal Vasko | af5a8dd | 2023-03-02 11:25:02 +0100 | [diff] [blame] | 7 | * Copyright (c) 2015-2023 CESNET, z.s.p.o. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [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 | |
| 16 | #ifndef LY_PARSER_DATA_H_ |
| 17 | #define LY_PARSER_DATA_H_ |
| 18 | |
| 19 | #include "tree_data.h" |
| 20 | |
| 21 | #ifdef __cplusplus |
| 22 | extern "C" { |
| 23 | #endif |
| 24 | |
| 25 | struct ly_in; |
| 26 | |
| 27 | /** |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 28 | * @page howtoDataParsers Parsing Data |
| 29 | * |
| 30 | * Data parser allows to read instances from a specific format. libyang supports the following data formats: |
| 31 | * |
| 32 | * - XML |
| 33 | * |
| 34 | * Original data format used in NETCONF protocol. XML mapping is part of the YANG specification |
| 35 | * ([RFC 6020](http://tools.ietf.org/html/rfc6020)). |
| 36 | * |
| 37 | * - JSON |
| 38 | * |
| 39 | * The alternative data format available in RESTCONF protocol. Specification of JSON encoding of data modeled by YANG |
| 40 | * can be found in [RFC 7951](http://tools.ietf.org/html/rfc7951). The specification does not cover RPCs, actions and |
| 41 | * Notifications, so the representation of these data trees is proprietary and corresponds to the representation of these |
| 42 | * trees in XML. |
| 43 | * |
| 44 | * While the parsers themselves process the input data only syntactically, all the parser functions actually incorporate |
| 45 | * the [common validator](@ref howtoDataValidation) checking the input data semantically. Therefore, the parser functions |
| 46 | * accepts two groups of options - @ref dataparseroptions and @ref datavalidationoptions. |
| 47 | * |
| 48 | * In contrast to the schema parser, data parser also accepts empty input data if such an empty data tree is valid |
| 49 | * according to the schemas in the libyang context (i.e. there are no top level mandatory nodes). |
| 50 | * |
| 51 | * There are individual functions to process different types of the data instances trees: |
| 52 | * - ::lyd_parse_data() is intended for standard configuration data trees. According to the given |
| 53 | * [parser options](@ref dataparseroptions), the caller can further specify which kind of data tree is expected: |
| 54 | * - *complete :running datastore*: this is the default case, possibly with the use of (some of) the |
| 55 | * ::LYD_PARSE_STRICT, ::LYD_PARSE_OPAQ or ::LYD_VALIDATE_PRESENT options. |
| 56 | * - *complete configuration-only datastore* (such as :startup): in this case it is necessary to except all state data |
| 57 | * using ::LYD_PARSE_NO_STATE option. |
| 58 | * - *incomplete datastore*: there are situation when the data tree is incomplete or invalid by specification. For |
| 59 | * example the *:operational* datastore is not necessarily valid and results of the NETCONF's \<get\> or \<get-config\> |
| 60 | * oprations used with filters will be incomplete (and thus invalid). This can be allowed using ::LYD_PARSE_ONLY, |
| 61 | * the ::LYD_PARSE_NO_STATE should be used for the data returned by \<get-config\> operation. |
Radek Krejci | f16e254 | 2021-02-17 15:39:23 +0100 | [diff] [blame] | 62 | * - ::lyd_parse_ext_data() is used for parsing configuration data trees defined inside extension instances, such as |
| 63 | * instances of yang-data extension specified in [RFC 8040](http://tools.ietf.org/html/rfc8040). |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 64 | * - ::lyd_parse_op() is used for parsing RPCs/actions, replies, and notifications. Even NETCONF rpc, rpc-reply, and |
Radek Krejci | f16e254 | 2021-02-17 15:39:23 +0100 | [diff] [blame] | 65 | * notification messages are supported. |
| 66 | * - ::lyd_parse_ext_op() is used for parsing RPCs/actions, replies, and notifications defined inside extension instances. |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 67 | * |
| 68 | * Further information regarding the processing input instance data can be found on the following pages. |
| 69 | * - @subpage howtoDataValidation |
| 70 | * - @subpage howtoDataWD |
| 71 | * |
| 72 | * Functions List |
| 73 | * -------------- |
| 74 | * - ::lyd_parse_data() |
| 75 | * - ::lyd_parse_data_mem() |
| 76 | * - ::lyd_parse_data_fd() |
| 77 | * - ::lyd_parse_data_path() |
Radek Krejci | f16e254 | 2021-02-17 15:39:23 +0100 | [diff] [blame] | 78 | * - ::lyd_parse_ext_data() |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 79 | * - ::lyd_parse_op() |
Radek Krejci | f16e254 | 2021-02-17 15:39:23 +0100 | [diff] [blame] | 80 | * - ::lyd_parse_ext_op() |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 81 | */ |
| 82 | |
| 83 | /** |
| 84 | * @page howtoDataValidation Validating Data |
| 85 | * |
| 86 | * Data validation is performed implicitly to the input data processed by the [parser](@ref howtoDataParsers) and |
| 87 | * on demand via the lyd_validate_*() functions. The explicit validation process is supposed to be used when a (complex or |
| 88 | * simple) change is done on the data tree (via [data manipulation](@ref howtoDataManipulation) functions) and the data |
| 89 | * tree is expected to be valid (it doesn't make sense to validate modified result of filtered \<get\> operation). |
| 90 | * |
| 91 | * Similarly to the [data parser](@ref howtoDataParsers), there are individual functions to validate standard data tree |
| 92 | * (::lyd_validate_all()) and RPC, Action and Notification (::lyd_validate_op()). For the standard data trees, it is possible |
| 93 | * to modify the validation process by @ref datavalidationoptions. This way the state data can be prohibited |
| 94 | * (::LYD_VALIDATE_NO_STATE) and checking for mandatory nodes can be limited to the YANG modules with already present data |
| 95 | * instances (::LYD_VALIDATE_PRESENT). Validation of the standard data tree can be also limited with ::lyd_validate_module() |
| 96 | * function, which scopes only to a specified single YANG module. |
| 97 | * |
| 98 | * Since the operation data trees (RPCs, Actions or Notifications) can reference (leafref, instance-identifier, when/must |
| 99 | * expressions) data from a datastore tree, ::lyd_validate_op() may require additional data tree to be provided. This is a |
| 100 | * difference in contrast to the parsing process, when the data are loaded from an external source and invalid reference |
| 101 | * outside the operation tree is acceptable. |
| 102 | * |
| 103 | * Functions List |
| 104 | * -------------- |
| 105 | * - ::lyd_validate_all() |
| 106 | * - ::lyd_validate_module() |
| 107 | * - ::lyd_validate_op() |
| 108 | */ |
| 109 | |
| 110 | /** |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 111 | * @addtogroup datatree |
| 112 | * @{ |
| 113 | */ |
| 114 | |
| 115 | /** |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 116 | * @ingroup datatree |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 117 | * @defgroup dataparseroptions Data parser options |
| 118 | * |
| 119 | * Various options to change the data tree parsers behavior. |
| 120 | * |
| 121 | * Default parser behavior: |
| 122 | * - complete input file is always parsed. In case of XML, even not well-formed XML document (multiple top-level |
| 123 | * elements) is parsed in its entirety, |
Michal Vasko | 78041d1 | 2022-11-29 14:11:07 +0100 | [diff] [blame] | 124 | * - parser silently ignores data without matching schema node definition (for LYB format an error), |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 125 | * - list instances are checked whether they have all the keys, error is raised if not. |
| 126 | * |
| 127 | * Default parser validation behavior: |
| 128 | * - the provided data are expected to provide complete datastore content (both the configuration and state data) |
| 129 | * and performs data validation according to all YANG rules, specifics follow, |
| 130 | * - list instances are expected to have all the keys (it is not checked), |
| 131 | * - instantiated (status) obsolete data print a warning, |
| 132 | * - all types are fully resolved (leafref/instance-identifier targets, unions) and must be valid (lists have |
| 133 | * all the keys, leaf(-lists) correct values), |
| 134 | * - when statements on existing nodes are evaluated, if not satisfied, a validation error is raised, |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 135 | * - invalid multiple data instances/data from several cases cause a validation error, |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 136 | * - implicit nodes (NP containers and default values) are added. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 137 | * @{ |
| 138 | */ |
| 139 | /* note: keep the lower 16bits free for use by LYD_VALIDATE_ flags. They are not supposed to be combined together, |
| 140 | * but since they are used (as a separate parameter) together in some functions, we want to keep them in a separated |
| 141 | * range to be able detect that the caller put wrong flags into the parser/validate options parameter. */ |
| 142 | #define LYD_PARSE_ONLY 0x010000 /**< Data will be only parsed and no validation will be performed. When statements |
Michal Vasko | a65c72c | 2022-02-17 16:20:18 +0100 | [diff] [blame] | 143 | are kept unevaluated, union types may not be fully resolved, and |
| 144 | default values are not added (only the ones parsed are present). */ |
Michal Vasko | 0f3377d | 2020-11-09 20:56:11 +0100 | [diff] [blame] | 145 | #define LYD_PARSE_STRICT 0x020000 /**< Instead of silently ignoring data without schema definition raise an error. |
Michal Vasko | 369f7a6 | 2021-02-01 08:59:36 +0100 | [diff] [blame] | 146 | Do not combine with ::LYD_PARSE_OPAQ (except for ::LYD_LYB). */ |
Michal Vasko | 0f3377d | 2020-11-09 20:56:11 +0100 | [diff] [blame] | 147 | #define LYD_PARSE_OPAQ 0x040000 /**< Instead of silently ignoring data without definition, parse them into |
Michal Vasko | 369f7a6 | 2021-02-01 08:59:36 +0100 | [diff] [blame] | 148 | 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 Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 150 | |
Michal Vasko | 0f3377d | 2020-11-09 20:56:11 +0100 | [diff] [blame] | 151 | #define LYD_PARSE_LYB_MOD_UPDATE 0x100000 /**< Only for LYB format, allow parsing data printed using a specific module |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 152 | revision to be loaded even with a module with the same name but newer |
| 153 | revision. */ |
Michal Vasko | 6ee6f43 | 2021-07-16 09:49:14 +0200 | [diff] [blame] | 154 | #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. */ |
Jan Kundrát | d49adf8 | 2023-11-01 15:46:36 +0100 | [diff] [blame] | 160 | #define LYD_PARSE_SUBTREE 0x400000 /**< Parse only the first child item along with any descendants, but no |
| 161 | siblings. This flag is not required when parsing data which do not |
| 162 | start at the schema root; for that purpose, use lyd_parse_data's parent |
| 163 | argument. |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 164 | Also, a new return value ::LY_ENOT is returned if there is a sibling |
Michal Vasko | 0820b5b | 2023-10-03 12:00:01 +0200 | [diff] [blame] | 165 | subtree following in the input data. Note that if validation is requested, |
Jan Kundrát | d49adf8 | 2023-11-01 15:46:36 +0100 | [diff] [blame] | 166 | only the newly parsed subtree is validated. This might result in |
| 167 | an invalid datastore content. */ |
Michal Vasko | fbb48c2 | 2022-11-30 13:28:03 +0100 | [diff] [blame] | 168 | #define LYD_PARSE_WHEN_TRUE 0x800000 /**< Mark all the parsed nodes dependend on a when condition with the flag |
| 169 | that means the condition was satisifed before. This allows for |
| 170 | auto-deletion of these nodes during validation. */ |
Michal Vasko | bc9f76f | 2022-12-01 10:31:38 +0100 | [diff] [blame] | 171 | #define LYD_PARSE_NO_NEW 0x1000000 /**< Do not set ::LYD_NEW (non-validated node flag) for any nodes. Use |
| 172 | when parsing validated data to skip some validation tasks and modify |
| 173 | some validation behavior (auto-deletion of cases). */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 174 | |
| 175 | #define LYD_PARSE_OPTS_MASK 0xFFFF0000 /**< Mask for all the LYD_PARSE_ options. */ |
| 176 | |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 177 | /** @} dataparseroptions */ |
| 178 | |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 179 | /** |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 180 | * @ingroup datatree |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 181 | * @defgroup datavalidationoptions Data validation options |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 182 | * |
| 183 | * Various options to change data validation behaviour, both for the parser and separate validation. |
| 184 | * |
| 185 | * Default separate validation behavior: |
| 186 | * - the provided data are expected to provide complete datastore content (both the configuration and state data) |
| 187 | * and performs data validation according to all YANG rules, specifics follow, |
| 188 | * - instantiated (status) obsolete data print a warning, |
| 189 | * - all types are fully resolved (leafref/instance-identifier targets, unions) and must be valid (lists have |
| 190 | * all the keys, leaf(-lists) correct values), |
| 191 | * - when statements on existing nodes are evaluated. Depending on the previous when state (from previous validation |
| 192 | * or parsing), the node is silently auto-deleted if the state changed from true to false, otherwise a validation error |
| 193 | * is raised if it evaluates to false, |
| 194 | * - if-feature statements are evaluated, |
| 195 | * - data from several cases behave based on their previous state (from previous validation or parsing). If there existed |
| 196 | * already a case and another one was added, the previous one is silently auto-deleted. Otherwise (if data from 2 or |
| 197 | * more cases were created) a validation error is raised, |
| 198 | * - default values are added. |
| 199 | * |
| 200 | * @{ |
| 201 | */ |
Michal Vasko | 369f7a6 | 2021-02-01 08:59:36 +0100 | [diff] [blame] | 202 | #define LYD_VALIDATE_NO_STATE 0x0001 /**< Consider state data not allowed and raise an error if they are found. |
| 203 | Also, no implicit state data are added. */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 204 | #define LYD_VALIDATE_PRESENT 0x0002 /**< Validate only modules whose data actually exist. */ |
Michal Vasko | d027f38 | 2023-02-10 09:13:25 +0100 | [diff] [blame] | 205 | #define LYD_VALIDATE_MULTI_ERROR 0x0004 /**< Do not stop validation on the first error but generate all the detected errors. */ |
Michal Vasko | 6b14c7e | 2023-11-09 12:08:14 +0100 | [diff] [blame^] | 206 | #define LYD_VALIDATE_OPERATIONAL 0x0008 /**< Semantic constraint violations are reported only as warnings instead of |
| 207 | errors (see [RFC 8342 sec. 5.3](https://datatracker.ietf.org/doc/html/rfc8342#section-5.3)). */ |
Michal Vasko | af5a8dd | 2023-03-02 11:25:02 +0100 | [diff] [blame] | 208 | #define LYD_VALIDATE_NO_DEFAULTS 0x0010 /**< Do not add any default nodes during validation, other implicit nodes |
| 209 | (such as NP containers) are still added. Validation will fail if a |
| 210 | default node is required for it to pass. */ |
Michal Vasko | 6b14c7e | 2023-11-09 12:08:14 +0100 | [diff] [blame^] | 211 | #define LYD_VALIDATE_NOT_FINAL 0x0020 /**< Skip final validation tasks that require for all the data nodes to |
| 212 | either exist or not, based on the YANG constraints. Once the data |
| 213 | satisfy this requirement, the final validation should be performed. */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 214 | |
| 215 | #define LYD_VALIDATE_OPTS_MASK 0x0000FFFF /**< Mask for all the LYD_VALIDATE_* options. */ |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 216 | |
| 217 | /** @} datavalidationoptions */ |
| 218 | |
| 219 | /** |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 220 | * @brief Parse (and validate) data from the input handler as a YANG data tree. |
| 221 | * |
| 222 | * @param[in] ctx Context to connect with the tree being built here. |
Jan Kundrát | d49adf8 | 2023-11-01 15:46:36 +0100 | [diff] [blame] | 223 | * @param[in] parent Optional parent to connect the parsed nodes to. If provided, the data are expected to describe |
| 224 | * a subtree of the YANG model instead of starting at the schema root. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 225 | * @param[in] in The input handle to provide the dumped data in the specified @p format to parse (and validate). |
| 226 | * @param[in] format Format of the input data to be parsed. Can be 0 to try to detect format from the input handler. |
| 227 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 228 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 229 | * @param[out] tree Full parsed data tree, note that NULL can be a valid tree. If @p parent is set, set to NULL. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 230 | * @return LY_SUCCESS in case of successful parsing (and validation). |
Michal Vasko | 6d49766 | 2020-07-08 10:42:57 +0200 | [diff] [blame] | 231 | * @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions. |
Jan Kundrát | d49adf8 | 2023-11-01 15:46:36 +0100 | [diff] [blame] | 232 | * |
| 233 | * When parsing subtrees (i.e., when @p parent is non-NULL), validation is only performed on the newly parsed data. |
| 234 | * This might result in allowing invalid datastore content when the schema contains cross-branch constraints, |
| 235 | * complicated `must` statements, etc. When a full-datastore validation is desirable, parse all subtrees |
| 236 | * first, and then request validation of the complete datastore content. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 237 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 238 | LIBYANG_API_DECL LY_ERR lyd_parse_data(const struct ly_ctx *ctx, struct lyd_node *parent, struct ly_in *in, LYD_FORMAT format, |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 239 | uint32_t parse_options, uint32_t validate_options, struct lyd_node **tree); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 240 | |
| 241 | /** |
| 242 | * @brief Parse (and validate) input data as a YANG data tree. |
| 243 | * |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 244 | * Wrapper around ::lyd_parse_data() hiding work with the input handler and some obscure options. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 245 | * |
| 246 | * @param[in] ctx Context to connect with the tree being built here. |
| 247 | * @param[in] data The input data in the specified @p format to parse (and validate). |
Michal Vasko | 107c816 | 2021-09-23 11:21:53 +0200 | [diff] [blame] | 248 | * @param[in] format Format of the input data to be parsed. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 249 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 250 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 251 | * @param[out] tree Full parsed data tree, note that NULL can be a valid tree |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 252 | * @return LY_SUCCESS in case of successful parsing (and validation). |
Michal Vasko | 6d49766 | 2020-07-08 10:42:57 +0200 | [diff] [blame] | 253 | * @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 254 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 255 | LIBYANG_API_DECL LY_ERR lyd_parse_data_mem(const struct ly_ctx *ctx, const char *data, LYD_FORMAT format, uint32_t parse_options, |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 256 | uint32_t validate_options, struct lyd_node **tree); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 257 | |
| 258 | /** |
| 259 | * @brief Parse (and validate) input data as a YANG data tree. |
| 260 | * |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 261 | * Wrapper around ::lyd_parse_data() hiding work with the input handler and some obscure options. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 262 | * |
| 263 | * @param[in] ctx Context to connect with the tree being built here. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 264 | * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the input data in the |
| 265 | * specified @p format to parse. |
Michal Vasko | 107c816 | 2021-09-23 11:21:53 +0200 | [diff] [blame] | 266 | * @param[in] format Format of the input data to be parsed. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 267 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 268 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 269 | * @param[out] tree Full parsed data tree, note that NULL can be a valid tree |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 270 | * @return LY_SUCCESS in case of successful parsing (and validation). |
Michal Vasko | 6d49766 | 2020-07-08 10:42:57 +0200 | [diff] [blame] | 271 | * @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 272 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 273 | LIBYANG_API_DECL LY_ERR lyd_parse_data_fd(const struct ly_ctx *ctx, int fd, LYD_FORMAT format, uint32_t parse_options, |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 274 | uint32_t validate_options, struct lyd_node **tree); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 275 | |
| 276 | /** |
| 277 | * @brief Parse (and validate) input data as a YANG data tree. |
| 278 | * |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 279 | * Wrapper around ::lyd_parse_data() hiding work with the input handler and some obscure options. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 280 | * |
| 281 | * @param[in] ctx Context to connect with the tree being built here. |
| 282 | * @param[in] path Path to the file with the input data in the specified @p format to parse (and validate). |
Michal Vasko | 107c816 | 2021-09-23 11:21:53 +0200 | [diff] [blame] | 283 | * @param[in] format Format of the input data to be parsed. Can be 0 to try to detect format from @p path extension. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 284 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 285 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 286 | * @param[out] tree Full parsed data tree, note that NULL can be a valid tree |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 287 | * @return LY_SUCCESS in case of successful parsing (and validation). |
Michal Vasko | 6d49766 | 2020-07-08 10:42:57 +0200 | [diff] [blame] | 288 | * @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 289 | */ |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 290 | LIBYANG_API_DECL LY_ERR lyd_parse_data_path(const struct ly_ctx *ctx, const char *path, LYD_FORMAT format, |
| 291 | uint32_t parse_options, uint32_t validate_options, struct lyd_node **tree); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 292 | |
| 293 | /** |
Radek Krejci | 7510412 | 2021-04-01 15:37:45 +0200 | [diff] [blame] | 294 | * @brief Parse (and validate) data from the input handler as an extension data tree following the schema tree of the given |
Radek Krejci | f16e254 | 2021-02-17 15:39:23 +0100 | [diff] [blame] | 295 | * extension instance. |
| 296 | * |
| 297 | * Note that the data being parsed are limited only to the schema tree specified by the given extension, it does not allow |
| 298 | * to mix them with the standard data from any module. |
| 299 | * |
Radek Krejci | 7510412 | 2021-04-01 15:37:45 +0200 | [diff] [blame] | 300 | * Directly applicable to data defined as [yang-data](@ref howtoDataYangdata). |
| 301 | * |
Radek Krejci | f16e254 | 2021-02-17 15:39:23 +0100 | [diff] [blame] | 302 | * @param[in] ext Extension instance providing the specific schema tree to match with the data being parsed. |
| 303 | * @param[in] parent Optional parent to connect the parsed nodes to. |
| 304 | * @param[in] in The input handle to provide the dumped data in the specified @p format to parse (and validate). |
| 305 | * @param[in] format Format of the input data to be parsed. Can be 0 to try to detect format from the input handler. |
| 306 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 307 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
| 308 | * @param[out] tree Full parsed data tree, note that NULL can be a valid tree. If @p parent is set, set to NULL. |
| 309 | * @return LY_SUCCESS in case of successful parsing (and validation). |
| 310 | * @return LY_ERR value in case of error. Additional error information can be obtained from the context using ly_err* functions. |
| 311 | */ |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 312 | LIBYANG_API_DECL LY_ERR lyd_parse_ext_data(const struct lysc_ext_instance *ext, struct lyd_node *parent, struct ly_in *in, |
| 313 | LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options, struct lyd_node **tree); |
Radek Krejci | f16e254 | 2021-02-17 15:39:23 +0100 | [diff] [blame] | 314 | |
| 315 | /** |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 316 | * @ingroup datatree |
| 317 | * @defgroup datatype Data operation type |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 318 | * |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 319 | * Operation provided to ::lyd_validate_op() to validate. |
| 320 | * |
| 321 | * The operation cannot be determined automatically since RPC/action and a reply to it share the common top level node |
| 322 | * referencing the RPC/action schema node and may not have any input/output children to use for distinction. |
| 323 | * |
| 324 | * @{ |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 325 | */ |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 326 | enum lyd_type { |
Michal Vasko | 820efe8 | 2023-05-12 15:47:43 +0200 | [diff] [blame] | 327 | LYD_TYPE_DATA_YANG = 0, /* generic YANG instance data */ |
| 328 | LYD_TYPE_RPC_YANG, /* instance of a YANG RPC/action request with only "input" data children, |
Michal Vasko | 6459269 | 2023-06-12 13:50:11 +0200 | [diff] [blame] | 329 | including all parents and optional top-level "action" element in case of an action */ |
Michal Vasko | 820efe8 | 2023-05-12 15:47:43 +0200 | [diff] [blame] | 330 | LYD_TYPE_NOTIF_YANG, /* instance of a YANG notification, including all parents in case of a nested one */ |
| 331 | LYD_TYPE_REPLY_YANG, /* instance of a YANG RPC/action reply with only "output" data children, |
| 332 | including all parents in case of an action */ |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 333 | |
Michal Vasko | 820efe8 | 2023-05-12 15:47:43 +0200 | [diff] [blame] | 334 | LYD_TYPE_RPC_NETCONF, /* complete NETCONF RPC invocation as defined for |
| 335 | [RPC](https://tools.ietf.org/html/rfc7950#section-7.14.4) and |
| 336 | [action](https://tools.ietf.org/html/rfc7950#section-7.15.2) */ |
| 337 | LYD_TYPE_NOTIF_NETCONF, /* complete NETCONF notification message as defined for |
| 338 | [notification](https://tools.ietf.org/html/rfc7950#section-7.16.2) */ |
| 339 | LYD_TYPE_REPLY_NETCONF, /* complete NETCONF RPC reply as defined for |
| 340 | [RPC](https://tools.ietf.org/html/rfc7950#section-7.14.4) and |
| 341 | [action](https://tools.ietf.org/html/rfc7950#section-7.15.2) */ |
| 342 | |
| 343 | LYD_TYPE_RPC_RESTCONF, /* message-body of a RESTCONF operation input parameters |
| 344 | ([ref](https://www.rfc-editor.org/rfc/rfc8040.html#section-3.6.1)) */ |
| 345 | LYD_TYPE_NOTIF_RESTCONF, /* RESTCONF JSON notification data |
| 346 | ([ref](https://www.rfc-editor.org/rfc/rfc8040.html#section-6.4)), to parse |
| 347 | a notification in XML, use ::LYD_TYPE_NOTIF_NETCONF */ |
| 348 | LYD_TYPE_REPLY_RESTCONF /* message-body of a RESTCONF operation output parameters |
| 349 | ([ref](https://www.rfc-editor.org/rfc/rfc8040.html#section-3.6.2)) */ |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 350 | }; |
| 351 | /** @} datatype */ |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 352 | |
| 353 | /** |
Michal Vasko | 2d4d369 | 2023-05-04 08:52:03 +0200 | [diff] [blame] | 354 | * @brief Parse YANG data into an operation data tree. Specific parsing flags ::LYD_PARSE_ONLY, ::LYD_PARSE_STRICT and |
| 355 | * no validation flags are used. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 356 | * |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 357 | * At least one of @p parent, @p tree, or @p op must always be set. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 358 | * |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 359 | * Specific @p data_type values have different parameter meaning as follows: |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 360 | * - ::LYD_TYPE_RPC_NETCONF: |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 361 | * - @p parent - must be NULL, the whole RPC is expected; |
| 362 | * - @p format - must be ::LYD_XML, NETCONF supports only this format; |
| 363 | * - @p tree - must be provided, all the NETCONF-specific XML envelopes will be returned here as |
Michal Vasko | 299d5d1 | 2021-02-16 16:36:37 +0100 | [diff] [blame] | 364 | * a separate opaque data tree, even if the function fails, this may be returned; |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 365 | * - @p op - must be provided, the RPC/action data tree itself will be returned here, pointing to the operation; |
| 366 | * |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 367 | * - ::LYD_TYPE_NOTIF_NETCONF: |
| 368 | * - @p parent - must be NULL, the whole notification is expected; |
| 369 | * - @p format - must be ::LYD_XML, NETCONF supports only this format; |
| 370 | * - @p tree - must be provided, all the NETCONF-specific XML envelopes will be returned here as |
Michal Vasko | f4da889 | 2021-02-19 09:15:18 +0100 | [diff] [blame] | 371 | * a separate opaque data tree, even if the function fails, this may be returned; |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 372 | * - @p op - must be provided, the notification data tree itself will be returned here, pointing to the operation; |
| 373 | * |
| 374 | * - ::LYD_TYPE_REPLY_NETCONF: |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 375 | * - @p parent - must be set, pointing to the invoked RPC operation (RPC or action) node; |
| 376 | * - @p format - must be ::LYD_XML, NETCONF supports only this format; |
| 377 | * - @p tree - must be provided, all the NETCONF-specific XML envelopes will be returned here as |
Michal Vasko | f4da889 | 2021-02-19 09:15:18 +0100 | [diff] [blame] | 378 | * a separate opaque data tree, even if the function fails, this may be returned; |
Michal Vasko | 1e4c68e | 2021-02-18 15:03:01 +0100 | [diff] [blame] | 379 | * - @p op - must be NULL, the reply is appended to the RPC; |
| 380 | * Note that there are 3 kinds of NETCONF replies - ok, error, and data. Only data reply appends any nodes to the RPC. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 381 | * |
Michal Vasko | 820efe8 | 2023-05-12 15:47:43 +0200 | [diff] [blame] | 382 | * - ::LYD_TYPE_RPC_RESTCONF: |
| 383 | * - @p parent - must be set, pointing to the invoked RPC operation (RPC or action) node; |
| 384 | * - @p format - can be both ::LYD_JSON and ::LYD_XML; |
| 385 | * - @p tree - must be provided, all the RESTCONF-specific JSON objects will be returned here as |
| 386 | * a separate opaque data tree, even if the function fails, this may be returned; |
| 387 | * - @p op - must be NULL, @p parent points to the operation; |
| 388 | * |
| 389 | * - ::LYD_TYPE_NOTIF_RESTCONF: |
| 390 | * - @p parent - must be NULL, the whole notification is expected; |
| 391 | * - @p format - must be ::LYD_JSON, XML-formatted notifications are parsed using ::LYD_TYPE_NOTIF_NETCONF; |
| 392 | * - @p tree - must be provided, all the RESTCONF-specific JSON objects will be returned here as |
| 393 | * a separate opaque data tree, even if the function fails, this may be returned; |
| 394 | * - @p op - must be provided, the notification data tree itself will be returned here, pointing to the operation; |
| 395 | * |
| 396 | * - ::LYD_TYPE_REPLY_RESTCONF: |
| 397 | * - @p parent - must be set, pointing to the invoked RPC operation (RPC or action) node; |
| 398 | * - @p format - can be both ::LYD_JSON and ::LYD_XML; |
| 399 | * - @p tree - must be provided, all the RESTCONF-specific JSON objects will be returned here as |
| 400 | * a separate opaque data tree, even if the function fails, this may be returned; |
| 401 | * - @p op - must be NULL, @p parent points to the operation; |
| 402 | * Note that error reply should be parsed as 'yang-data' extension data. |
| 403 | * |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 404 | * @param[in] ctx libyang context. |
| 405 | * @param[in] parent Optional parent to connect the parsed nodes to. |
| 406 | * @param[in] in Input handle to read the input from. |
| 407 | * @param[in] format Expected format of the data in @p in. |
| 408 | * @param[in] data_type Expected operation to parse (@ref datatype). |
| 409 | * @param[out] tree Optional full parsed data tree. If @p parent is set, set to NULL. |
Michal Vasko | 438b529 | 2021-06-09 14:31:25 +0200 | [diff] [blame] | 410 | * @param[out] op Optional pointer to the operation (action/RPC) node. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 411 | * @return LY_ERR value. |
Michal Vasko | b7dba86 | 2021-02-18 16:10:02 +0100 | [diff] [blame] | 412 | * @return LY_ENOT if @p data_type is a NETCONF message and the root XML element is not the expected one. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 413 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 414 | LIBYANG_API_DECL LY_ERR lyd_parse_op(const struct ly_ctx *ctx, struct lyd_node *parent, struct ly_in *in, LYD_FORMAT format, |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 415 | enum lyd_type data_type, struct lyd_node **tree, struct lyd_node **op); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 416 | |
| 417 | /** |
Radek Krejci | 7510412 | 2021-04-01 15:37:45 +0200 | [diff] [blame] | 418 | * @brief Parse extension data into an operation data tree following only the specification from the given extension instance. |
| 419 | * |
| 420 | * Directly applicable to data defined as [yang-data](@ref howtoDataYangdata). |
Radek Krejci | f16e254 | 2021-02-17 15:39:23 +0100 | [diff] [blame] | 421 | * |
| 422 | * At least one of @p parent, @p tree, or @p op must always be set. |
| 423 | * |
| 424 | * Specific @p data_type values have different parameter meaning as follows: |
| 425 | * - ::LYD_TYPE_RPC_NETCONF: |
| 426 | * - @p parent - must be NULL, the whole RPC is expected; |
| 427 | * - @p format - must be ::LYD_XML, NETCONF supports only this format; |
| 428 | * - @p tree - must be provided, all the NETCONF-specific XML envelopes will be returned here as |
| 429 | * a separate opaque data tree, even if the function fails, this may be returned; |
| 430 | * - @p op - must be provided, the RPC/action data tree itself will be returned here, pointing to the operation; |
| 431 | * |
| 432 | * - ::LYD_TYPE_NOTIF_NETCONF: |
| 433 | * - @p parent - must be NULL, the whole notification is expected; |
| 434 | * - @p format - must be ::LYD_XML, NETCONF supports only this format; |
| 435 | * - @p tree - must be provided, all the NETCONF-specific XML envelopes will be returned here as |
| 436 | * a separate opaque data tree, even if the function fails, this may be returned; |
| 437 | * - @p op - must be provided, the notification data tree itself will be returned here, pointing to the operation; |
| 438 | * |
| 439 | * - ::LYD_TYPE_REPLY_NETCONF: |
| 440 | * - @p parent - must be set, pointing to the invoked RPC operation (RPC or action) node; |
| 441 | * - @p format - must be ::LYD_XML, NETCONF supports only this format; |
| 442 | * - @p tree - must be provided, all the NETCONF-specific XML envelopes will be returned here as |
| 443 | * a separate opaque data tree, even if the function fails, this may be returned; |
| 444 | * - @p op - must be NULL, the reply is appended to the RPC; |
| 445 | * Note that there are 3 kinds of NETCONF replies - ok, error, and data. Only data reply appends any nodes to the RPC. |
| 446 | * |
| 447 | * @param[in] ext Extension instance providing the specific schema tree to match with the data being parsed. |
| 448 | * @param[in] parent Optional parent to connect the parsed nodes to. |
| 449 | * @param[in] in Input handle to read the input from. |
| 450 | * @param[in] format Expected format of the data in @p in. |
| 451 | * @param[in] data_type Expected operation to parse (@ref datatype). |
| 452 | * @param[out] tree Optional full parsed data tree. If @p parent is set, set to NULL. |
Michal Vasko | 438b529 | 2021-06-09 14:31:25 +0200 | [diff] [blame] | 453 | * @param[out] op Optional pointer to the operation (action/RPC) node. |
Radek Krejci | f16e254 | 2021-02-17 15:39:23 +0100 | [diff] [blame] | 454 | * @return LY_ERR value. |
| 455 | * @return LY_ENOT if @p data_type is a NETCONF message and the root XML element is not the expected one. |
| 456 | */ |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 457 | LIBYANG_API_DECL LY_ERR lyd_parse_ext_op(const struct lysc_ext_instance *ext, struct lyd_node *parent, struct ly_in *in, |
| 458 | LYD_FORMAT format, enum lyd_type data_type, struct lyd_node **tree, struct lyd_node **op); |
Radek Krejci | f16e254 | 2021-02-17 15:39:23 +0100 | [diff] [blame] | 459 | |
| 460 | /** |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 461 | * @brief Fully validate a data tree. |
| 462 | * |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 463 | * The data tree is modified in-place. As a result of the validation, some data might be removed |
Jan Kundrát | 9474763 | 2021-10-14 16:23:09 +0200 | [diff] [blame] | 464 | * from the tree. In that case, the removed items are freed, not just unlinked. |
| 465 | * |
| 466 | * @param[in,out] tree Data tree to recursively validate. May be changed by validation, might become NULL. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 467 | * @param[in] ctx libyang context. Can be NULL if @p tree is set. |
| 468 | * @param[in] val_opts Validation options (@ref datavalidationoptions). |
Michal Vasko | 8104fd4 | 2020-07-13 11:09:51 +0200 | [diff] [blame] | 469 | * @param[out] diff Optional diff with any changes made by the validation. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 470 | * @return LY_SUCCESS on success. |
| 471 | * @return LY_ERR error on error. |
| 472 | */ |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 473 | LIBYANG_API_DECL LY_ERR lyd_validate_all(struct lyd_node **tree, const struct ly_ctx *ctx, uint32_t val_opts, |
| 474 | struct lyd_node **diff); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 475 | |
| 476 | /** |
Michal Vasko | 26e8001 | 2020-07-08 10:55:46 +0200 | [diff] [blame] | 477 | * @brief Fully validate a data tree of a module. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 478 | * |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 479 | * The data tree is modified in-place. As a result of the validation, some data might be removed |
Jan Kundrát | 9474763 | 2021-10-14 16:23:09 +0200 | [diff] [blame] | 480 | * from the tree. In that case, the removed items are freed, not just unlinked. |
| 481 | * |
Michal Vasko | 6b14c7e | 2023-11-09 12:08:14 +0100 | [diff] [blame^] | 482 | * If several modules need to be validated, the flag ::LYD_VALIDATE_NOT_FINAL should be used first for validation |
| 483 | * of each module and then ::lyd_validate_module_final() should be called also for each module. Otherwise, |
| 484 | * false-positive validation errors for foreign dependencies may occur. |
| 485 | * |
Jan Kundrát | 9474763 | 2021-10-14 16:23:09 +0200 | [diff] [blame] | 486 | * @param[in,out] tree Data tree to recursively validate. May be changed by validation, might become NULL. |
Michal Vasko | 26e8001 | 2020-07-08 10:55:46 +0200 | [diff] [blame] | 487 | * @param[in] module Module whose data (and schema restrictions) to validate. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 488 | * @param[in] val_opts Validation options (@ref datavalidationoptions). |
Michal Vasko | 8104fd4 | 2020-07-13 11:09:51 +0200 | [diff] [blame] | 489 | * @param[out] diff Optional diff with any changes made by the validation. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 490 | * @return LY_SUCCESS on success. |
| 491 | * @return LY_ERR error on error. |
| 492 | */ |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 493 | LIBYANG_API_DECL LY_ERR lyd_validate_module(struct lyd_node **tree, const struct lys_module *module, uint32_t val_opts, |
| 494 | struct lyd_node **diff); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 495 | |
| 496 | /** |
Michal Vasko | 6b14c7e | 2023-11-09 12:08:14 +0100 | [diff] [blame^] | 497 | * @brief Finish validation of a module data that have previously been validated with ::LYD_VALIDATE_NOT_FINAL flag. |
| 498 | * |
| 499 | * This final validation will not add or remove any nodes. |
| 500 | * |
| 501 | * @param[in] tree Data tree to recursively validate. |
| 502 | * @param[in] module Module whose data (and schema restrictions) to validate. |
| 503 | * @param[in] val_opts Validation options (@ref datavalidationoptions). |
| 504 | * @return LY_SUCCESS on success. |
| 505 | * @return LY_ERR error on error. |
| 506 | */ |
| 507 | LIBYANG_API_DECL LY_ERR lyd_validate_module_final(struct lyd_node *tree, const struct lys_module *module, |
| 508 | uint32_t val_opts); |
| 509 | |
| 510 | /** |
Michal Vasko | 0bec322 | 2022-04-22 07:46:00 +0200 | [diff] [blame] | 511 | * @brief Validate an RPC/action request, reply, or notification. Only the operation data tree (input/output/notif) |
| 512 | * is validate, any parents are ignored. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 513 | * |
| 514 | * @param[in,out] op_tree Operation tree with any parents. It can point to the operation itself or any of |
| 515 | * its parents, only the operation subtree is actually validated. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 516 | * @param[in] dep_tree Tree to be used for validating references from the operation subtree. |
| 517 | * @param[in] data_type Operation type to validate (only YANG operations are accepted, @ref datatype). |
Michal Vasko | 8104fd4 | 2020-07-13 11:09:51 +0200 | [diff] [blame] | 518 | * @param[out] diff Optional diff with any changes made by the validation. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 519 | * @return LY_SUCCESS on success. |
| 520 | * @return LY_ERR error on error. |
| 521 | */ |
Jan Kundrát | c53a7ec | 2021-12-09 16:01:19 +0100 | [diff] [blame] | 522 | LIBYANG_API_DECL LY_ERR lyd_validate_op(struct lyd_node *op_tree, const struct lyd_node *dep_tree, enum lyd_type data_type, |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 523 | struct lyd_node **diff); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 524 | |
| 525 | /** @} datatree */ |
| 526 | |
| 527 | #ifdef __cplusplus |
| 528 | } |
| 529 | #endif |
| 530 | |
| 531 | #endif /* LY_PARSER_DATA_H_ */ |