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. |
| 61 | * - ::lyd_parse_rpc() is used for parsing RPCs/Actions, optionally including the RPC envelopes known from the NETCONF |
| 62 | * protocol. |
| 63 | * - ::lyd_parse_reply() processes reply to a previous RPC/Action, which must be provided. |
| 64 | * - ::lyd_parse_notif() is able to process complete Notification message. |
| 65 | * |
| 66 | * Further information regarding the processing input instance data can be found on the following pages. |
| 67 | * - @subpage howtoDataValidation |
| 68 | * - @subpage howtoDataWD |
| 69 | * |
| 70 | * Functions List |
| 71 | * -------------- |
| 72 | * - ::lyd_parse_data() |
| 73 | * - ::lyd_parse_data_mem() |
| 74 | * - ::lyd_parse_data_fd() |
| 75 | * - ::lyd_parse_data_path() |
| 76 | * - ::lyd_parse_rpc() |
| 77 | * - ::lyd_parse_reply() |
| 78 | * - ::lyd_parse_notif() |
| 79 | */ |
| 80 | |
| 81 | /** |
| 82 | * @page howtoDataValidation Validating Data |
| 83 | * |
| 84 | * Data validation is performed implicitly to the input data processed by the [parser](@ref howtoDataParsers) and |
| 85 | * on demand via the lyd_validate_*() functions. The explicit validation process is supposed to be used when a (complex or |
| 86 | * simple) change is done on the data tree (via [data manipulation](@ref howtoDataManipulation) functions) and the data |
| 87 | * tree is expected to be valid (it doesn't make sense to validate modified result of filtered \<get\> operation). |
| 88 | * |
| 89 | * Similarly to the [data parser](@ref howtoDataParsers), there are individual functions to validate standard data tree |
| 90 | * (::lyd_validate_all()) and RPC, Action and Notification (::lyd_validate_op()). For the standard data trees, it is possible |
| 91 | * to modify the validation process by @ref datavalidationoptions. This way the state data can be prohibited |
| 92 | * (::LYD_VALIDATE_NO_STATE) and checking for mandatory nodes can be limited to the YANG modules with already present data |
| 93 | * instances (::LYD_VALIDATE_PRESENT). Validation of the standard data tree can be also limited with ::lyd_validate_module() |
| 94 | * function, which scopes only to a specified single YANG module. |
| 95 | * |
| 96 | * Since the operation data trees (RPCs, Actions or Notifications) can reference (leafref, instance-identifier, when/must |
| 97 | * expressions) data from a datastore tree, ::lyd_validate_op() may require additional data tree to be provided. This is a |
| 98 | * difference in contrast to the parsing process, when the data are loaded from an external source and invalid reference |
| 99 | * outside the operation tree is acceptable. |
| 100 | * |
| 101 | * Functions List |
| 102 | * -------------- |
| 103 | * - ::lyd_validate_all() |
| 104 | * - ::lyd_validate_module() |
| 105 | * - ::lyd_validate_op() |
| 106 | */ |
| 107 | |
| 108 | /** |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 109 | * @addtogroup datatree |
| 110 | * @{ |
| 111 | */ |
| 112 | |
| 113 | /** |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 114 | * @ingroup datatree |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 115 | * @defgroup dataparseroptions Data parser options |
| 116 | * |
| 117 | * Various options to change the data tree parsers behavior. |
| 118 | * |
| 119 | * Default parser behavior: |
| 120 | * - complete input file is always parsed. In case of XML, even not well-formed XML document (multiple top-level |
| 121 | * elements) is parsed in its entirety, |
| 122 | * - parser silently ignores data without matching schema node definition, |
| 123 | * - list instances are checked whether they have all the keys, error is raised if not. |
| 124 | * |
| 125 | * Default parser validation behavior: |
| 126 | * - the provided data are expected to provide complete datastore content (both the configuration and state data) |
| 127 | * and performs data validation according to all YANG rules, specifics follow, |
| 128 | * - list instances are expected to have all the keys (it is not checked), |
| 129 | * - instantiated (status) obsolete data print a warning, |
| 130 | * - all types are fully resolved (leafref/instance-identifier targets, unions) and must be valid (lists have |
| 131 | * all the keys, leaf(-lists) correct values), |
| 132 | * - when statements on existing nodes are evaluated, if not satisfied, a validation error is raised, |
| 133 | * - if-feature statements are evaluated, |
| 134 | * - invalid multiple data instances/data from several cases cause a validation error, |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 135 | * - implicit nodes (NP containers and default values) are added. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 136 | * @{ |
| 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). */ |
| 145 | #define LYD_PARSE_TRUSTED 0x020000 /**< Data are considered trusted so they will be parsed as validated. If the parsed |
| 146 | data are not valid, using this flag may lead to some unexpected behavior! |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 147 | This flag can be used only with #LYD_PARSE_ONLY. */ |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 148 | #define LYD_PARSE_STRICT 0x040000 /**< Instead of silently ignoring data without schema definition raise an error. |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 149 | Do not combine with #LYD_PARSE_OPAQ (except for ::LYD_LYB). */ |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 150 | #define LYD_PARSE_OPAQ 0x080000 /**< Instead of silently ignoring data without definition, parse them into |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 151 | an opaq node. Do not combine with #LYD_PARSE_STRICT (except for ::LYD_LYB). */ |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 152 | #define LYD_PARSE_NO_STATE 0x100000 /**< Forbid state data in the parsed data. */ |
| 153 | |
| 154 | #define LYD_PARSE_LYB_MOD_UPDATE 0x200000 /**< Only for LYB format, allow parsing data printed using a specific module |
| 155 | revision to be loaded even with a module with the same name but newer |
| 156 | revision. */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 157 | |
| 158 | #define LYD_PARSE_OPTS_MASK 0xFFFF0000 /**< Mask for all the LYD_PARSE_ options. */ |
| 159 | |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 160 | /** @} dataparseroptions */ |
| 161 | |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 162 | /** |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 163 | * @ingroup datatree |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 164 | * @defgroup datavalidationoptions Data validation options |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 165 | * |
| 166 | * Various options to change data validation behaviour, both for the parser and separate validation. |
| 167 | * |
| 168 | * Default separate validation behavior: |
| 169 | * - the provided data are expected to provide complete datastore content (both the configuration and state data) |
| 170 | * and performs data validation according to all YANG rules, specifics follow, |
| 171 | * - instantiated (status) obsolete data print a warning, |
| 172 | * - all types are fully resolved (leafref/instance-identifier targets, unions) and must be valid (lists have |
| 173 | * all the keys, leaf(-lists) correct values), |
| 174 | * - when statements on existing nodes are evaluated. Depending on the previous when state (from previous validation |
| 175 | * or parsing), the node is silently auto-deleted if the state changed from true to false, otherwise a validation error |
| 176 | * is raised if it evaluates to false, |
| 177 | * - if-feature statements are evaluated, |
| 178 | * - data from several cases behave based on their previous state (from previous validation or parsing). If there existed |
| 179 | * already a case and another one was added, the previous one is silently auto-deleted. Otherwise (if data from 2 or |
| 180 | * more cases were created) a validation error is raised, |
| 181 | * - default values are added. |
| 182 | * |
| 183 | * @{ |
| 184 | */ |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 185 | #define LYD_VALIDATE_NO_STATE 0x0001 /**< Consider state data not allowed and raise an error if they are found. */ |
| 186 | #define LYD_VALIDATE_PRESENT 0x0002 /**< Validate only modules whose data actually exist. */ |
| 187 | |
| 188 | #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] | 189 | |
| 190 | /** @} datavalidationoptions */ |
| 191 | |
| 192 | /** |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 193 | * @ingroup datatree |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 194 | * @defgroup datavalidateop Operation to validate |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 195 | * |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 196 | * Operation provided to ::lyd_validate_op() to validate. |
| 197 | * |
| 198 | * The operation cannot be determined automatically since RPC/action and a reply to it share the common top level node |
| 199 | * referencing the RPC/action schema node and may not have any input/output children to use for distinction. |
Radek Krejci | 576f8fa | 2020-10-26 21:23:58 +0100 | [diff] [blame] | 200 | * |
| 201 | * @{ |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 202 | */ |
| 203 | typedef enum { |
| 204 | LYD_VALIDATE_OP_RPC = 1, /**< Validate RPC/action request (input parameters). */ |
| 205 | LYD_VALIDATE_OP_REPLY, /**< Validate RPC/action reply (output parameters). */ |
| 206 | LYD_VALIDATE_OP_NOTIF /**< Validate Notification operation. */ |
| 207 | } LYD_VALIDATE_OP; |
| 208 | |
| 209 | /** @} datavalidateop */ |
| 210 | |
| 211 | /** |
| 212 | * @brief Parse (and validate) data from the input handler as a YANG data tree. |
| 213 | * |
| 214 | * @param[in] ctx Context to connect with the tree being built here. |
| 215 | * @param[in] in The input handle to provide the dumped data in the specified @p format to parse (and validate). |
| 216 | * @param[in] format Format of the input data to be parsed. Can be 0 to try to detect format from the input handler. |
| 217 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 218 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
| 219 | * @param[out] tree Resulting data tree built from the input data. Note that NULL can be a valid result as a representation of an empty YANG data tree. |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 220 | * The returned data are expected to be freed using ::lyd_free_all(). |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 221 | * @return LY_SUCCESS in case of successful parsing (and validation). |
Michal Vasko | 6d49766 | 2020-07-08 10:42:57 +0200 | [diff] [blame] | 222 | * @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] | 223 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 224 | LY_ERR lyd_parse_data(const struct ly_ctx *ctx, struct ly_in *in, LYD_FORMAT format, uint32_t parse_options, |
| 225 | uint32_t validate_options, struct lyd_node **tree); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 226 | |
| 227 | /** |
| 228 | * @brief Parse (and validate) input data as a YANG data tree. |
| 229 | * |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 230 | * Wrapper around ::lyd_parse_data() hiding work with the input handler. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 231 | * |
| 232 | * @param[in] ctx Context to connect with the tree being built here. |
| 233 | * @param[in] data The input data in the specified @p format to parse (and validate). |
| 234 | * @param[in] format Format of the input data to be parsed. Can be 0 to try to detect format from the input handler. |
| 235 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 236 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
| 237 | * @param[out] tree Resulting data tree built from the input data. Note that NULL can be a valid result as a representation of an empty YANG data tree. |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 238 | * The returned data are expected to be freed using ::lyd_free_all(). |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 239 | * @return LY_SUCCESS in case of successful parsing (and validation). |
Michal Vasko | 6d49766 | 2020-07-08 10:42:57 +0200 | [diff] [blame] | 240 | * @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] | 241 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 242 | LY_ERR lyd_parse_data_mem(const struct ly_ctx *ctx, const char *data, LYD_FORMAT format, uint32_t parse_options, |
| 243 | uint32_t validate_options, struct lyd_node **tree); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 244 | |
| 245 | /** |
| 246 | * @brief Parse (and validate) input data as a YANG data tree. |
| 247 | * |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 248 | * Wrapper around ::lyd_parse_data() hiding work with the input handler. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 249 | * |
| 250 | * @param[in] ctx Context to connect with the tree being built here. |
| 251 | * @param[in] fd File descriptor of a regular file (e.g. sockets are not supported) containing the input data in the specified @p format to parse (and validate). |
| 252 | * @param[in] format Format of the input data to be parsed. Can be 0 to try to detect format from the input handler. |
| 253 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 254 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
| 255 | * @param[out] tree Resulting data tree built from the input data. Note that NULL can be a valid result as a representation of an empty YANG data tree. |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 256 | * The returned data are expected to be freed using ::lyd_free_all(). |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 257 | * @return LY_SUCCESS in case of successful parsing (and validation). |
Michal Vasko | 6d49766 | 2020-07-08 10:42:57 +0200 | [diff] [blame] | 258 | * @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] | 259 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 260 | LY_ERR lyd_parse_data_fd(const struct ly_ctx *ctx, int fd, LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 261 | struct lyd_node **tree); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 262 | |
| 263 | /** |
| 264 | * @brief Parse (and validate) input data as a YANG data tree. |
| 265 | * |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 266 | * Wrapper around ::lyd_parse_data() hiding work with the input handler. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 267 | * |
| 268 | * @param[in] ctx Context to connect with the tree being built here. |
| 269 | * @param[in] path Path to the file with the input data in the specified @p format to parse (and validate). |
| 270 | * @param[in] format Format of the input data to be parsed. Can be 0 to try to detect format from the input handler. |
| 271 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 272 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
| 273 | * @param[out] tree Resulting data tree built from the input data. Note that NULL can be a valid result as a representation of an empty YANG data tree. |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 274 | * The returned data are expected to be freed using ::lyd_free_all(). |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 275 | * @return LY_SUCCESS in case of successful parsing (and validation). |
Michal Vasko | 6d49766 | 2020-07-08 10:42:57 +0200 | [diff] [blame] | 276 | * @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] | 277 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 278 | LY_ERR lyd_parse_data_path(const struct ly_ctx *ctx, const char *path, LYD_FORMAT format, uint32_t parse_options, |
| 279 | uint32_t validate_options, struct lyd_node **tree); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 280 | |
| 281 | /** |
| 282 | * @brief Parse (and validate) data from the input handler as a YANG RPC/action invocation. |
| 283 | * |
| 284 | * In case o LYD_XML @p format, the \<rpc\> envelope element is accepted if present. It is [checked](https://tools.ietf.org/html/rfc6241#section-4.1), an opaq |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 285 | * data node (lyd_node_opaq) is created and all its XML attributes are parsed and inserted into the node. As a content of the envelope, an RPC data or |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 286 | * \<action\> envelope element is expected. The \<action\> envelope element is also [checked](https://tools.ietf.org/html/rfc7950#section-7.15.2) and parsed as |
| 287 | * the \<rpc\> envelope. Inside the \<action\> envelope, only an action data are expected. |
| 288 | * |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 289 | * Similarly, in the case of LYD_JSON @p format, the same envelopes in form of JSON objects are accepted. Nothing |
| 290 | * corresponding to the XML attributes is accepted in this case. |
| 291 | * |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 292 | * @param[in] ctx Context to connect with the tree being built here. |
| 293 | * @param[in] in The input handle to provide the dumped data in the specified @p format to parse (and validate). |
| 294 | * @param[in] format Format of the input data to be parsed. |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 295 | * @param[out] tree Resulting full RPC/action tree built from the input data. The returned data are expected to be freed using ::lyd_free_all(). |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 296 | * In contrast to YANG data tree, result of parsing RPC/action cannot be NULL until an error occurs. |
| 297 | * @param[out] op Optional pointer to the actual operation node inside the full action @p tree, useful only for action. |
| 298 | * @return LY_SUCCESS in case of successful parsing (and validation). |
Michal Vasko | 6d49766 | 2020-07-08 10:42:57 +0200 | [diff] [blame] | 299 | * @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] | 300 | */ |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 301 | LY_ERR lyd_parse_rpc(const struct ly_ctx *ctx, struct ly_in *in, LYD_FORMAT format, struct lyd_node **tree, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 302 | struct lyd_node **op); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 303 | |
| 304 | /** |
| 305 | * @brief Parse (and validate) data from the input handler as a YANG RPC/action reply. |
| 306 | * |
| 307 | * In case o LYD_XML @p format, the \<rpc-reply\> envelope element is accepted if present. It is [checked](https://tools.ietf.org/html/rfc6241#section-4.2), an opaq |
| 308 | * data node (lyd_node_opaq) is created and all its XML attributes are parsed and inserted into the node. |
| 309 | * |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 310 | * Similarly, in the case of LYD_JSON @p format, the same envelopes in form of JSON objects are accepted. Nothing |
| 311 | * corresponding to the XML attributes is processed in this case. |
| 312 | * |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 313 | * The reply data are strictly expected to be related to the provided RPC/action @p request. |
| 314 | * |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 315 | * @param[in] request The RPC/action tree (result of ::lyd_parse_rpc()) of the request for the reply being parsed. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 316 | * @param[in] in The input handle to provide the dumped data in the specified @p format to parse (and validate). |
| 317 | * @param[in] format Format of the input data to be parsed. |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 318 | * @param[out] tree Resulting full RPC/action reply tree built from the input data. The returned data are expected to be freed using ::lyd_free_all(). |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 319 | * The reply tree always includes duplicated operation node (and its parents) of the @p request, so in contrast to YANG data tree, |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 320 | * the result of parsing RPC/action reply cannot be NULL until an error occurs. At least one of the @p tree and @p op output variables must be provided. |
| 321 | * @param[out] op Pointer to the actual operation node inside the full action reply @p tree, useful only for action. At least one of the @p op |
| 322 | * and @p tree output variables must be provided. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 323 | * @return LY_SUCCESS in case of successful parsing (and validation). |
Michal Vasko | 6d49766 | 2020-07-08 10:42:57 +0200 | [diff] [blame] | 324 | * @return LY_ERR value in case of error. Additional error information can be obtained from the request's context using ly_err* functions. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 325 | */ |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 326 | LY_ERR lyd_parse_reply(const struct lyd_node *request, struct ly_in *in, LYD_FORMAT format, struct lyd_node **tree, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 327 | struct lyd_node **op); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 328 | |
| 329 | /** |
| 330 | * @brief Parse XML string as YANG notification. |
| 331 | * |
| 332 | * In case o LYD_XML @p format, the \<notification\> envelope element in combination with the child \<eventTime\> element are accepted if present. They are |
| 333 | * [checked](https://tools.ietf.org/html/rfc5277#page-25), opaq data nodes (lyd_node_opaq) are created and all their XML attributes are parsed and inserted into the nodes. |
| 334 | * |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 335 | * Similarly, in the case of LYD_JSON @p format, the same envelopes in form of JSON objects are accepted. Nothing |
| 336 | * corresponding to the XML attributes is accepted in this case. |
| 337 | * |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 338 | * @param[in] ctx Context to connect with the tree being built here. |
| 339 | * @param[in] in The input handle to provide the dumped data in the specified @p format to parse (and validate). |
| 340 | * @param[in] format Format of the input data to be parsed. |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 341 | * @param[out] tree Resulting full Notification tree built from the input data. The returned data are expected to be freed using ::lyd_free_all(). |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 342 | * In contrast to YANG data tree, result of parsing Notification cannot be NULL until an error occurs. |
| 343 | * @param[out] ntf Optional pointer to the actual notification node inside the full Notification @p tree, useful for nested notifications. |
| 344 | * @return LY_SUCCESS in case of successful parsing (and validation). |
Michal Vasko | 6d49766 | 2020-07-08 10:42:57 +0200 | [diff] [blame] | 345 | * @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] | 346 | */ |
Michal Vasko | 3a41dff | 2020-07-15 14:30:28 +0200 | [diff] [blame] | 347 | LY_ERR lyd_parse_notif(const struct ly_ctx *ctx, struct ly_in *in, LYD_FORMAT format, struct lyd_node **tree, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 348 | struct lyd_node **ntf); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 349 | |
| 350 | /** |
| 351 | * @brief Fully validate a data tree. |
| 352 | * |
| 353 | * @param[in,out] tree Data tree to recursively validate. May be changed by validation. |
| 354 | * @param[in] ctx libyang context. Can be NULL if @p tree is set. |
| 355 | * @param[in] val_opts Validation options (@ref datavalidationoptions). |
Michal Vasko | 8104fd4 | 2020-07-13 11:09:51 +0200 | [diff] [blame] | 356 | * @param[out] diff Optional diff with any changes made by the validation. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 357 | * @return LY_SUCCESS on success. |
| 358 | * @return LY_ERR error on error. |
| 359 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 360 | 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] | 361 | |
| 362 | /** |
Michal Vasko | 26e8001 | 2020-07-08 10:55:46 +0200 | [diff] [blame] | 363 | * @brief Fully validate a data tree of a module. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 364 | * |
| 365 | * @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] | 366 | * @param[in] module Module whose data (and schema restrictions) to validate. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 367 | * @param[in] val_opts Validation options (@ref datavalidationoptions). |
Michal Vasko | 8104fd4 | 2020-07-13 11:09:51 +0200 | [diff] [blame] | 368 | * @param[out] diff Optional diff with any changes made by the validation. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 369 | * @return LY_SUCCESS on success. |
| 370 | * @return LY_ERR error on error. |
| 371 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 372 | 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] | 373 | |
| 374 | /** |
| 375 | * @brief Validate an RPC/action, notification, or RPC/action reply. |
| 376 | * |
| 377 | * @param[in,out] op_tree Operation tree with any parents. It can point to the operation itself or any of |
| 378 | * its parents, only the operation subtree is actually validated. |
| 379 | * @param[in] tree Tree to be used for validating references from the operation subtree. |
| 380 | * @param[in] op Operation to validate (@ref datavalidateop), the given @p op_tree must correspond to this value. Note that |
| 381 | * it isn't possible to detect the operation simply from the @p op_tree since RPC/action and their reply share the same |
Michal Vasko | 8104fd4 | 2020-07-13 11:09:51 +0200 | [diff] [blame] | 382 | * RPC/action data node and in case one of the input and output do not define any data node children, it is not possible |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 383 | * to get know what is here given for validation and if it is really valid. |
Michal Vasko | 8104fd4 | 2020-07-13 11:09:51 +0200 | [diff] [blame] | 384 | * @param[out] diff Optional diff with any changes made by the validation. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 385 | * @return LY_SUCCESS on success. |
| 386 | * @return LY_ERR error on error. |
| 387 | */ |
Michal Vasko | 8104fd4 | 2020-07-13 11:09:51 +0200 | [diff] [blame] | 388 | LY_ERR lyd_validate_op(struct lyd_node *op_tree, const struct lyd_node *tree, LYD_VALIDATE_OP op, struct lyd_node **diff); |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 389 | |
| 390 | /** @} datatree */ |
| 391 | |
| 392 | #ifdef __cplusplus |
| 393 | } |
| 394 | #endif |
| 395 | |
| 396 | #endif /* LY_PARSER_DATA_H_ */ |