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> |
| 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 |
| 21 | extern "C" { |
| 22 | #endif |
| 23 | |
| 24 | struct ly_in; |
| 25 | |
| 26 | /** |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 27 | * @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. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 61 | * - ::lyd_parse_op() is used for parsing RPCs/actions, replies, and notifications. Even NETCONF rpc, rpc-reply, and |
| 62 | * notification messages are supported. |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 63 | * |
| 64 | * Further information regarding the processing input instance data can be found on the following pages. |
| 65 | * - @subpage howtoDataValidation |
| 66 | * - @subpage howtoDataWD |
| 67 | * |
| 68 | * Functions List |
| 69 | * -------------- |
| 70 | * - ::lyd_parse_data() |
| 71 | * - ::lyd_parse_data_mem() |
| 72 | * - ::lyd_parse_data_fd() |
| 73 | * - ::lyd_parse_data_path() |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 74 | * - ::lyd_parse_op() |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 75 | */ |
| 76 | |
| 77 | /** |
| 78 | * @page howtoDataValidation Validating Data |
| 79 | * |
| 80 | * Data validation is performed implicitly to the input data processed by the [parser](@ref howtoDataParsers) and |
| 81 | * on demand via the lyd_validate_*() functions. The explicit validation process is supposed to be used when a (complex or |
| 82 | * simple) change is done on the data tree (via [data manipulation](@ref howtoDataManipulation) functions) and the data |
| 83 | * tree is expected to be valid (it doesn't make sense to validate modified result of filtered \<get\> operation). |
| 84 | * |
| 85 | * Similarly to the [data parser](@ref howtoDataParsers), there are individual functions to validate standard data tree |
| 86 | * (::lyd_validate_all()) and RPC, Action and Notification (::lyd_validate_op()). For the standard data trees, it is possible |
| 87 | * to modify the validation process by @ref datavalidationoptions. This way the state data can be prohibited |
| 88 | * (::LYD_VALIDATE_NO_STATE) and checking for mandatory nodes can be limited to the YANG modules with already present data |
| 89 | * instances (::LYD_VALIDATE_PRESENT). Validation of the standard data tree can be also limited with ::lyd_validate_module() |
| 90 | * function, which scopes only to a specified single YANG module. |
| 91 | * |
| 92 | * Since the operation data trees (RPCs, Actions or Notifications) can reference (leafref, instance-identifier, when/must |
| 93 | * expressions) data from a datastore tree, ::lyd_validate_op() may require additional data tree to be provided. This is a |
| 94 | * difference in contrast to the parsing process, when the data are loaded from an external source and invalid reference |
| 95 | * outside the operation tree is acceptable. |
| 96 | * |
| 97 | * Functions List |
| 98 | * -------------- |
| 99 | * - ::lyd_validate_all() |
| 100 | * - ::lyd_validate_module() |
| 101 | * - ::lyd_validate_op() |
| 102 | */ |
| 103 | |
| 104 | /** |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 105 | * @addtogroup datatree |
| 106 | * @{ |
| 107 | */ |
| 108 | |
| 109 | /** |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 110 | * @ingroup datatree |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 111 | * @defgroup dataparseroptions Data parser options |
| 112 | * |
| 113 | * Various options to change the data tree parsers behavior. |
| 114 | * |
| 115 | * Default parser behavior: |
| 116 | * - complete input file is always parsed. In case of XML, even not well-formed XML document (multiple top-level |
| 117 | * elements) is parsed in its entirety, |
| 118 | * - parser silently ignores data without matching schema node definition, |
| 119 | * - list instances are checked whether they have all the keys, error is raised if not. |
| 120 | * |
| 121 | * Default parser validation behavior: |
| 122 | * - the provided data are expected to provide complete datastore content (both the configuration and state data) |
| 123 | * and performs data validation according to all YANG rules, specifics follow, |
| 124 | * - list instances are expected to have all the keys (it is not checked), |
| 125 | * - instantiated (status) obsolete data print a warning, |
| 126 | * - all types are fully resolved (leafref/instance-identifier targets, unions) and must be valid (lists have |
| 127 | * all the keys, leaf(-lists) correct values), |
| 128 | * - when statements on existing nodes are evaluated, if not satisfied, a validation error is raised, |
| 129 | * - if-feature statements are evaluated, |
| 130 | * - invalid multiple data instances/data from several cases cause a validation error, |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 131 | * - implicit nodes (NP containers and default values) are added. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 132 | * @{ |
| 133 | */ |
| 134 | /* note: keep the lower 16bits free for use by LYD_VALIDATE_ flags. They are not supposed to be combined together, |
| 135 | * but since they are used (as a separate parameter) together in some functions, we want to keep them in a separated |
| 136 | * range to be able detect that the caller put wrong flags into the parser/validate options parameter. */ |
| 137 | #define LYD_PARSE_ONLY 0x010000 /**< Data will be only parsed and no validation will be performed. When statements |
| 138 | are kept unevaluated, union types may not be fully resolved, if-feature |
| 139 | statements are not checked, and default values are not added (only the ones |
| 140 | parsed are present). */ |
Michal Vasko | 0f3377d | 2020-11-09 20:56:11 +0100 | [diff] [blame] | 141 | #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] | 142 | Do not combine with ::LYD_PARSE_OPAQ (except for ::LYD_LYB). */ |
Michal Vasko | 0f3377d | 2020-11-09 20:56:11 +0100 | [diff] [blame] | 143 | #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] | 144 | an opaq node. Do not combine with ::LYD_PARSE_STRICT (except for ::LYD_LYB). */ |
| 145 | #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] | 146 | |
Michal Vasko | 0f3377d | 2020-11-09 20:56:11 +0100 | [diff] [blame] | 147 | #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] | 148 | revision to be loaded even with a module with the same name but newer |
| 149 | revision. */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 150 | |
| 151 | #define LYD_PARSE_OPTS_MASK 0xFFFF0000 /**< Mask for all the LYD_PARSE_ options. */ |
| 152 | |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 153 | /** @} dataparseroptions */ |
| 154 | |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 155 | /** |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 156 | * @ingroup datatree |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 157 | * @defgroup datavalidationoptions Data validation options |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 158 | * |
| 159 | * Various options to change data validation behaviour, both for the parser and separate validation. |
| 160 | * |
| 161 | * Default separate validation behavior: |
| 162 | * - the provided data are expected to provide complete datastore content (both the configuration and state data) |
| 163 | * and performs data validation according to all YANG rules, specifics follow, |
| 164 | * - instantiated (status) obsolete data print a warning, |
| 165 | * - all types are fully resolved (leafref/instance-identifier targets, unions) and must be valid (lists have |
| 166 | * all the keys, leaf(-lists) correct values), |
| 167 | * - when statements on existing nodes are evaluated. Depending on the previous when state (from previous validation |
| 168 | * or parsing), the node is silently auto-deleted if the state changed from true to false, otherwise a validation error |
| 169 | * is raised if it evaluates to false, |
| 170 | * - if-feature statements are evaluated, |
| 171 | * - data from several cases behave based on their previous state (from previous validation or parsing). If there existed |
| 172 | * already a case and another one was added, the previous one is silently auto-deleted. Otherwise (if data from 2 or |
| 173 | * more cases were created) a validation error is raised, |
| 174 | * - default values are added. |
| 175 | * |
| 176 | * @{ |
| 177 | */ |
Michal Vasko | 369f7a6 | 2021-02-01 08:59:36 +0100 | [diff] [blame] | 178 | #define LYD_VALIDATE_NO_STATE 0x0001 /**< Consider state data not allowed and raise an error if they are found. |
| 179 | Also, no implicit state data are added. */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 180 | #define LYD_VALIDATE_PRESENT 0x0002 /**< Validate only modules whose data actually exist. */ |
| 181 | |
| 182 | #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] | 183 | |
| 184 | /** @} datavalidationoptions */ |
| 185 | |
| 186 | /** |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 187 | * @brief Parse (and validate) data from the input handler as a YANG data tree. |
| 188 | * |
| 189 | * @param[in] ctx Context to connect with the tree being built here. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 190 | * @param[in] parent Optional parent to connect the parsed nodes to. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 191 | * @param[in] in The input handle to provide the dumped data in the specified @p format to parse (and validate). |
| 192 | * @param[in] format Format of the input data to be parsed. Can be 0 to try to detect format from the input handler. |
| 193 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 194 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 195 | * @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] | 196 | * @return LY_SUCCESS in case of successful parsing (and validation). |
Michal Vasko | 6d49766 | 2020-07-08 10:42:57 +0200 | [diff] [blame] | 197 | * @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] | 198 | */ |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 199 | LY_ERR lyd_parse_data(const struct ly_ctx *ctx, struct lyd_node *parent, struct ly_in *in, LYD_FORMAT format, |
| 200 | uint32_t parse_options, uint32_t validate_options, struct lyd_node **tree); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 201 | |
| 202 | /** |
| 203 | * @brief Parse (and validate) input data as a YANG data tree. |
| 204 | * |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 205 | * 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] | 206 | * |
| 207 | * @param[in] ctx Context to connect with the tree being built here. |
| 208 | * @param[in] data The input data in the specified @p format to parse (and validate). |
| 209 | * @param[in] format Format of the input data to be parsed. Can be 0 to try to detect format from the input handler. |
| 210 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 211 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 212 | * @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] | 213 | * @return LY_SUCCESS in case of successful parsing (and validation). |
Michal Vasko | 6d49766 | 2020-07-08 10:42:57 +0200 | [diff] [blame] | 214 | * @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] | 215 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 216 | LY_ERR lyd_parse_data_mem(const struct ly_ctx *ctx, const char *data, LYD_FORMAT format, uint32_t parse_options, |
| 217 | uint32_t validate_options, struct lyd_node **tree); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 218 | |
| 219 | /** |
| 220 | * @brief Parse (and validate) input data as a YANG data tree. |
| 221 | * |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 222 | * 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] | 223 | * |
| 224 | * @param[in] ctx Context to connect with the tree being built here. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 225 | * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the input data in the |
| 226 | * specified @p format to parse. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 227 | * @param[in] format Format of the input data to be parsed. Can be 0 to try to detect format from the input handler. |
| 228 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 229 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 230 | * @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] | 231 | * @return LY_SUCCESS in case of successful parsing (and validation). |
Michal Vasko | 6d49766 | 2020-07-08 10:42:57 +0200 | [diff] [blame] | 232 | * @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] | 233 | */ |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 234 | LY_ERR lyd_parse_data_fd(const struct ly_ctx *ctx, int fd, LYD_FORMAT format, uint32_t parse_options, |
| 235 | uint32_t validate_options, struct lyd_node **tree); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 236 | |
| 237 | /** |
| 238 | * @brief Parse (and validate) input data as a YANG data tree. |
| 239 | * |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 240 | * 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] | 241 | * |
| 242 | * @param[in] ctx Context to connect with the tree being built here. |
| 243 | * @param[in] path Path to the file with the input data in the specified @p format to parse (and validate). |
| 244 | * @param[in] format Format of the input data to be parsed. Can be 0 to try to detect format from the input handler. |
| 245 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 246 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 247 | * @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] | 248 | * @return LY_SUCCESS in case of successful parsing (and validation). |
Michal Vasko | 6d49766 | 2020-07-08 10:42:57 +0200 | [diff] [blame] | 249 | * @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] | 250 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 251 | LY_ERR lyd_parse_data_path(const struct ly_ctx *ctx, const char *path, LYD_FORMAT format, uint32_t parse_options, |
| 252 | uint32_t validate_options, struct lyd_node **tree); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 253 | |
| 254 | /** |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 255 | * @ingroup datatree |
| 256 | * @defgroup datatype Data operation type |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 257 | * |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 258 | * Operation provided to ::lyd_validate_op() to validate. |
| 259 | * |
| 260 | * The operation cannot be determined automatically since RPC/action and a reply to it share the common top level node |
| 261 | * referencing the RPC/action schema node and may not have any input/output children to use for distinction. |
| 262 | * |
| 263 | * @{ |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 264 | */ |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 265 | enum lyd_type { |
| 266 | LYD_TYPE_YANG_DATA = 0, /* generic YANG instance data */ |
| 267 | LYD_TYPE_YANG_RPC, /* instance of a YANG RPC/action request with only "input" data children, |
| 268 | including all parents in case of an action */ |
| 269 | LYD_TYPE_YANG_NOTIF, /* instance of a YANG notification , including all parents in case of a nested one */ |
| 270 | LYD_TYPE_YANG_REPLY, /* instance of a YANG RPC/action reply with only "output" data children, |
| 271 | including all parents in case of an action */ |
| 272 | LYD_TYPE_NETCONF_RPC, /* complete NETCONF RPC invocation as defined for |
| 273 | [RPC](https://tools.ietf.org/html/rfc7950#section-7.14.4) and |
| 274 | [action](https://tools.ietf.org/html/rfc7950#section-7.15.2) */ |
| 275 | LYD_TYPE_NETCONF_REPLY_OR_NOTIF /* complete NETCONF RPC reply as defined for |
| 276 | [RPC](https://tools.ietf.org/html/rfc7950#section-7.14.4) and |
| 277 | [action](https://tools.ietf.org/html/rfc7950#section-7.15.2) or |
| 278 | [notification](https://tools.ietf.org/html/rfc7950#section-7.16.2), which |
| 279 | of these is parsed is decided based on the first element name */ |
| 280 | }; |
| 281 | /** @} datatype */ |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 282 | |
| 283 | /** |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 284 | * @brief Parse YANG data into an operation data tree. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 285 | * |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 286 | * 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] | 287 | * |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 288 | * Specific @p data_type values have different parameter meaning as follows: |
| 289 | * - ::LYD_TYPE_NETCONF_RPC: |
| 290 | * - @p parent - must be NULL, the whole RPC is expected; |
| 291 | * - @p format - must be ::LYD_XML, NETCONF supports only this format; |
| 292 | * - @p tree - must be provided, all the NETCONF-specific XML envelopes will be returned here as |
| 293 | * a separate opaque data tree; |
| 294 | * - @p op - must be provided, the RPC/action data tree itself will be returned here, pointing to the operation; |
| 295 | * |
| 296 | * - ::LYD_TYPE_NETCONF_REPLY_OR_NOTIF: |
| 297 | * - @p parent - must be set, pointing to the invoked RPC operation (RPC or action) node; |
| 298 | * - @p format - must be ::LYD_XML, NETCONF supports only this format; |
| 299 | * - @p tree - must be provided, all the NETCONF-specific XML envelopes will be returned here as |
| 300 | * a separate opaque data tree; |
| 301 | * - @p op - must be provided, the notification data tree itself will be returned here, pointing to the operation, |
| 302 | * it will be set to NULL if no data nodes were parsed in the reply (ok or rpc-error); |
| 303 | * |
| 304 | * @param[in] ctx libyang context. |
| 305 | * @param[in] parent Optional parent to connect the parsed nodes to. |
| 306 | * @param[in] in Input handle to read the input from. |
| 307 | * @param[in] format Expected format of the data in @p in. |
| 308 | * @param[in] data_type Expected operation to parse (@ref datatype). |
| 309 | * @param[out] tree Optional full parsed data tree. If @p parent is set, set to NULL. |
| 310 | * @param[out] op Optional parsed operation node. |
| 311 | * @return LY_ERR value. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 312 | */ |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 313 | LY_ERR lyd_parse_op(const struct ly_ctx *ctx, struct lyd_node *parent, struct ly_in *in, LYD_FORMAT format, |
| 314 | 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] | 315 | |
| 316 | /** |
| 317 | * @brief Fully validate a data tree. |
| 318 | * |
| 319 | * @param[in,out] tree Data tree to recursively validate. May be changed by validation. |
| 320 | * @param[in] ctx libyang context. Can be NULL if @p tree is set. |
| 321 | * @param[in] val_opts Validation options (@ref datavalidationoptions). |
Michal Vasko | 8104fd4 | 2020-07-13 11:09:51 +0200 | [diff] [blame] | 322 | * @param[out] diff Optional diff with any changes made by the validation. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 323 | * @return LY_SUCCESS on success. |
| 324 | * @return LY_ERR error on error. |
| 325 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 326 | LY_ERR lyd_validate_all(struct lyd_node **tree, const struct ly_ctx *ctx, uint32_t val_opts, struct lyd_node **diff); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 327 | |
| 328 | /** |
Michal Vasko | 26e8001 | 2020-07-08 10:55:46 +0200 | [diff] [blame] | 329 | * @brief Fully validate a data tree of a module. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 330 | * |
| 331 | * @param[in,out] tree Data tree to recursively validate. May be changed by validation. |
Michal Vasko | 26e8001 | 2020-07-08 10:55:46 +0200 | [diff] [blame] | 332 | * @param[in] module Module whose data (and schema restrictions) to validate. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 333 | * @param[in] val_opts Validation options (@ref datavalidationoptions). |
Michal Vasko | 8104fd4 | 2020-07-13 11:09:51 +0200 | [diff] [blame] | 334 | * @param[out] diff Optional diff with any changes made by the validation. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 335 | * @return LY_SUCCESS on success. |
| 336 | * @return LY_ERR error on error. |
| 337 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 338 | LY_ERR lyd_validate_module(struct lyd_node **tree, const struct lys_module *module, uint32_t val_opts, struct lyd_node **diff); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 339 | |
| 340 | /** |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 341 | * @brief Validate an RPC/action request, reply, or notification. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 342 | * |
| 343 | * @param[in,out] op_tree Operation tree with any parents. It can point to the operation itself or any of |
| 344 | * its parents, only the operation subtree is actually validated. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 345 | * @param[in] dep_tree Tree to be used for validating references from the operation subtree. |
| 346 | * @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] | 347 | * @param[out] diff Optional diff with any changes made by the validation. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 348 | * @return LY_SUCCESS on success. |
| 349 | * @return LY_ERR error on error. |
| 350 | */ |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame^] | 351 | LY_ERR lyd_validate_op(struct lyd_node *op_tree, const struct lyd_node *dep_tree, enum lyd_type data_type, |
| 352 | struct lyd_node **diff); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 353 | |
| 354 | /** @} datatree */ |
| 355 | |
| 356 | #ifdef __cplusplus |
| 357 | } |
| 358 | #endif |
| 359 | |
| 360 | #endif /* LY_PARSER_DATA_H_ */ |