Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file parser_internal.h |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief Internal structures and functions for libyang parsers |
| 5 | * |
| 6 | * Copyright (c) 2020 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
| 14 | |
| 15 | #ifndef LY_PARSER_INTERNAL_H_ |
| 16 | #define LY_PARSER_INTERNAL_H_ |
| 17 | |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 18 | #include "parser_data.h" |
aPiecek | 704f8e9 | 2021-08-25 13:35:05 +0200 | [diff] [blame] | 19 | #include "set.h" |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 20 | |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 21 | struct lyd_ctx; |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 22 | struct ly_in; |
aPiecek | 704f8e9 | 2021-08-25 13:35:05 +0200 | [diff] [blame] | 23 | struct lys_yang_parser_ctx; |
| 24 | struct lys_yin_parser_ctx; |
| 25 | struct lys_parser_ctx; |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 26 | |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 27 | /** |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 28 | * @brief Callback for ::lyd_ctx to free the structure |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 29 | * |
| 30 | * @param[in] ctx Data parser context to free. |
| 31 | */ |
| 32 | typedef void (*lyd_ctx_free_clb)(struct lyd_ctx *ctx); |
| 33 | |
| 34 | /** |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 35 | * @brief Internal data parser flags. |
| 36 | */ |
| 37 | #define LYD_INTOPT_RPC 0x01 /**< RPC request is being parsed. */ |
| 38 | #define LYD_INTOPT_ACTION 0x02 /**< Action request is being parsed. */ |
| 39 | #define LYD_INTOPT_REPLY 0x04 /**< RPC/action reply is being parsed. */ |
| 40 | #define LYD_INTOPT_NOTIF 0x08 /**< Notification is being parsed. */ |
Michal Vasko | 02ed9d8 | 2021-07-15 14:58:04 +0200 | [diff] [blame] | 41 | #define LYD_INTOPT_ANY 0x10 /**< Anydata/anyxml content is being parsed, there can be anything. */ |
| 42 | #define LYD_INTOPT_WITH_SIBLINGS 0x20 /**< Parse the whole input with any siblings. */ |
| 43 | #define LYD_INTOPT_NO_SIBLINGS 0x40 /**< If there are any siblings, return an error. */ |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 44 | |
| 45 | /** |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 46 | * @brief Internal (common) context for YANG data parsers. |
Radek Krejci | 4f2e3e5 | 2021-03-30 14:20:28 +0200 | [diff] [blame] | 47 | * |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 48 | * Covers ::lyd_xml_ctx, ::lyd_json_ctx and ::lyd_lyb_ctx. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 49 | */ |
| 50 | struct lyd_ctx { |
Radek Krejci | f16e254 | 2021-02-17 15:39:23 +0100 | [diff] [blame] | 51 | const struct lysc_ext_instance *ext; /**< extension instance possibly changing document root context of the data being parsed */ |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 52 | uint32_t parse_opts; /**< various @ref dataparseroptions. */ |
| 53 | uint32_t val_opts; /**< various @ref datavalidationoptions. */ |
| 54 | uint32_t int_opts; /**< internal parser options */ |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 55 | uint32_t path_len; /**< used bytes in the path buffer */ |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 56 | |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 57 | #define LYD_PARSER_BUFSIZE 4078 |
| 58 | char path[LYD_PARSER_BUFSIZE]; /**< buffer for the generated path */ |
Michal Vasko | c43c8ab | 2021-03-05 13:32:44 +0100 | [diff] [blame] | 59 | struct ly_set node_when; /**< set of nodes with "when" conditions */ |
Michal Vasko | 3271138 | 2020-12-03 14:14:31 +0100 | [diff] [blame] | 60 | struct ly_set node_types; /**< set of nodes validated with LY_EINCOMPLETE result */ |
| 61 | struct ly_set meta_types; /**< set of metadata validated with LY_EINCOMPLETE result */ |
Michal Vasko | 135719f | 2022-08-25 12:18:17 +0200 | [diff] [blame] | 62 | struct ly_set ext_node; /**< set of nodes with extension instances to validate */ |
| 63 | struct ly_set ext_val; /**< set of nested subtrees parsed by extensions to validate */ |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 64 | struct lyd_node *op_node; /**< if an RPC/action/notification is being parsed, store the pointer to it */ |
| 65 | |
| 66 | /* callbacks */ |
Radek Krejci | 0bff0b1 | 2020-08-15 18:37:50 +0200 | [diff] [blame] | 67 | lyd_ctx_free_clb free; /**< destructor */ |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 68 | |
| 69 | struct { |
Radek Krejci | 0bff0b1 | 2020-08-15 18:37:50 +0200 | [diff] [blame] | 70 | const struct ly_ctx *ctx; /**< libyang context */ |
| 71 | uint64_t line; /**< current line */ |
| 72 | struct ly_in *in; /**< input structure */ |
| 73 | } *data_ctx; /**< generic pointer supposed to map to and access (common part of) XML/JSON/... parser contexts */ |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 74 | }; |
| 75 | |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 76 | /** |
Michal Vasko | 03fbaed | 2021-07-15 09:18:32 +0200 | [diff] [blame] | 77 | * @brief Internal context for XML data parser. |
| 78 | */ |
| 79 | struct lyd_xml_ctx { |
| 80 | const struct lysc_ext_instance *ext; |
| 81 | uint32_t parse_opts; |
| 82 | uint32_t val_opts; |
| 83 | uint32_t int_opts; |
| 84 | uint32_t path_len; |
| 85 | char path[LYD_PARSER_BUFSIZE]; |
| 86 | struct ly_set node_when; |
Michal Vasko | 03fbaed | 2021-07-15 09:18:32 +0200 | [diff] [blame] | 87 | struct ly_set node_types; |
| 88 | struct ly_set meta_types; |
Michal Vasko | 135719f | 2022-08-25 12:18:17 +0200 | [diff] [blame] | 89 | struct ly_set ext_node; |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 90 | struct ly_set ext_val; |
Michal Vasko | 03fbaed | 2021-07-15 09:18:32 +0200 | [diff] [blame] | 91 | struct lyd_node *op_node; |
| 92 | |
| 93 | /* callbacks */ |
| 94 | lyd_ctx_free_clb free; |
| 95 | |
| 96 | struct lyxml_ctx *xmlctx; /**< XML context */ |
| 97 | }; |
| 98 | |
| 99 | /** |
| 100 | * @brief Internal context for JSON data parser. |
| 101 | */ |
| 102 | struct lyd_json_ctx { |
| 103 | const struct lysc_ext_instance *ext; |
| 104 | uint32_t parse_opts; |
| 105 | uint32_t val_opts; |
| 106 | uint32_t int_opts; |
| 107 | uint32_t path_len; |
| 108 | char path[LYD_PARSER_BUFSIZE]; |
| 109 | struct ly_set node_when; |
Michal Vasko | 03fbaed | 2021-07-15 09:18:32 +0200 | [diff] [blame] | 110 | struct ly_set node_types; |
| 111 | struct ly_set meta_types; |
Michal Vasko | 135719f | 2022-08-25 12:18:17 +0200 | [diff] [blame] | 112 | struct ly_set ext_node; |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 113 | struct ly_set ext_val; |
Michal Vasko | 03fbaed | 2021-07-15 09:18:32 +0200 | [diff] [blame] | 114 | struct lyd_node *op_node; |
| 115 | |
| 116 | /* callbacks */ |
| 117 | lyd_ctx_free_clb free; |
| 118 | |
| 119 | struct lyjson_ctx *jsonctx; /**< JSON context */ |
| 120 | }; |
| 121 | |
| 122 | /** |
| 123 | * @brief Internal context for LYB data parser/printer. |
| 124 | */ |
| 125 | struct lyd_lyb_ctx { |
| 126 | const struct lysc_ext_instance *ext; |
Michal Vasko | 26bbb27 | 2022-08-02 14:54:33 +0200 | [diff] [blame] | 127 | |
Michal Vasko | 03fbaed | 2021-07-15 09:18:32 +0200 | [diff] [blame] | 128 | union { |
| 129 | struct { |
| 130 | uint32_t parse_opts; |
| 131 | uint32_t val_opts; |
| 132 | }; |
| 133 | uint32_t print_options; |
| 134 | }; |
| 135 | uint32_t int_opts; |
| 136 | uint32_t path_len; |
| 137 | char path[LYD_PARSER_BUFSIZE]; |
| 138 | struct ly_set node_when; |
Michal Vasko | 03fbaed | 2021-07-15 09:18:32 +0200 | [diff] [blame] | 139 | struct ly_set node_types; |
| 140 | struct ly_set meta_types; |
Michal Vasko | 135719f | 2022-08-25 12:18:17 +0200 | [diff] [blame] | 141 | struct ly_set ext_node; |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 142 | struct ly_set ext_val; |
Michal Vasko | 03fbaed | 2021-07-15 09:18:32 +0200 | [diff] [blame] | 143 | struct lyd_node *op_node; |
| 144 | |
| 145 | /* callbacks */ |
| 146 | lyd_ctx_free_clb free; |
| 147 | |
| 148 | struct lylyb_ctx *lybctx; /* LYB context */ |
| 149 | }; |
| 150 | |
| 151 | /** |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 152 | * @brief Parsed extension instance data to validate. |
| 153 | */ |
| 154 | struct lyd_ctx_ext_val { |
| 155 | struct lysc_ext_instance *ext; |
| 156 | struct lyd_node *sibling; |
| 157 | }; |
| 158 | |
| 159 | /** |
Michal Vasko | 135719f | 2022-08-25 12:18:17 +0200 | [diff] [blame] | 160 | * @brief Parsed data node with extension instance to validate. |
| 161 | */ |
| 162 | struct lyd_ctx_ext_node { |
| 163 | struct lysc_ext_instance *ext; |
| 164 | struct lyd_node *node; |
| 165 | }; |
| 166 | |
| 167 | /** |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 168 | * @brief Common part to supplement the specific ::lyd_ctx_free_clb callbacks. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 169 | */ |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 170 | void lyd_ctx_free(struct lyd_ctx *ctx); |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 171 | |
| 172 | /** |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 173 | * @brief Parse submodule from YANG data. |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 174 | * @param[in,out] context Parser context. |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 175 | * @param[in] ly_ctx Context of YANG schemas. |
| 176 | * @param[in] main_ctx Parser context of main module. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 177 | * @param[in] in Input structure. |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 178 | * @param[out] submod Pointer to the parsed submodule structure. |
| 179 | * @return LY_ERR value - LY_SUCCESS, LY_EINVAL or LY_EVALID. |
| 180 | */ |
| 181 | LY_ERR yang_parse_submodule(struct lys_yang_parser_ctx **context, struct ly_ctx *ly_ctx, struct lys_parser_ctx *main_ctx, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 182 | struct ly_in *in, struct lysp_submodule **submod); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 183 | |
| 184 | /** |
| 185 | * @brief Parse module from YANG data. |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 186 | * @param[in] context Parser context. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 187 | * @param[in] in Input structure. |
| 188 | * @param[in,out] mod Prepared module structure where the parsed information, including the parsed |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 189 | * module structure, will be filled in. |
Michal Vasko | 405cc9e | 2020-12-01 12:01:27 +0100 | [diff] [blame] | 190 | * @return LY_ERR values. |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 191 | */ |
aPiecek | c3e2614 | 2021-06-22 14:25:49 +0200 | [diff] [blame] | 192 | LY_ERR yang_parse_module(struct lys_yang_parser_ctx **context, struct ly_in *in, struct lys_module *mod); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 193 | |
| 194 | /** |
| 195 | * @brief Parse module from YIN data. |
| 196 | * |
| 197 | * @param[in,out] yin_ctx Context created during parsing, is used to finalize lysp_model after it's completly parsed. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 198 | * @param[in] in Input structure. |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 199 | * @param[in,out] mod Prepared module structure where the parsed information, including the parsed |
| 200 | * module structure, will be filled in. |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 201 | * @return LY_ERR values. |
| 202 | */ |
aPiecek | c3e2614 | 2021-06-22 14:25:49 +0200 | [diff] [blame] | 203 | LY_ERR yin_parse_module(struct lys_yin_parser_ctx **yin_ctx, struct ly_in *in, struct lys_module *mod); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 204 | |
| 205 | /** |
| 206 | * @brief Parse submodule from YIN data. |
| 207 | * |
| 208 | * @param[in,out] yin_ctx Context created during parsing, is used to finalize lysp_model after it's completly parsed. |
| 209 | * @param[in] ctx Libyang context. |
| 210 | * @param[in] main_ctx Parser context of main module. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 211 | * @param[in] in Input structure. |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 212 | * @param[in,out] submod Submodule structure where the parsed information, will be filled in. |
| 213 | * @return LY_ERR values. |
| 214 | */ |
| 215 | LY_ERR yin_parse_submodule(struct lys_yin_parser_ctx **yin_ctx, struct ly_ctx *ctx, struct lys_parser_ctx *main_ctx, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 216 | struct ly_in *in, struct lysp_submodule **submod); |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 217 | |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 218 | /** |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 219 | * @brief Parse XML string as a YANG data tree. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 220 | * |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 221 | * @param[in] ctx libyang context. |
aPiecek | b0445f2 | 2021-06-24 11:34:07 +0200 | [diff] [blame] | 222 | * @param[in] ext Optional extension instance to parse data following the schema tree specified in the extension instance |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 223 | * @param[in] parent Parent to connect the parsed nodes to, if any. |
| 224 | * @param[in,out] first_p Pointer to the first top-level parsed node, used only if @p parent is NULL. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 225 | * @param[in] in Input structure. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 226 | * @param[in] parse_opts Options for parser, see @ref dataparseroptions. |
| 227 | * @param[in] val_opts Options for the validation phase, see @ref datavalidationoptions. |
| 228 | * @param[in] data_type Expected data type of the data. |
Michal Vasko | 299d5d1 | 2021-02-16 16:36:37 +0100 | [diff] [blame] | 229 | * @param[out] envp Individual parsed envelopes tree, returned only by specific @p data_type and possibly even if |
| 230 | * an error occurs later. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 231 | * @param[out] parsed Set to add all the parsed siblings into. |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 232 | * @param[out] subtree_sibling Set if ::LYD_PARSE_SUBTREE is used and another subtree is following in @p in. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 233 | * @param[out] lydctx_p Data parser context to finish validation. |
| 234 | * @return LY_ERR value. |
| 235 | */ |
Radek Krejci | f16e254 | 2021-02-17 15:39:23 +0100 | [diff] [blame] | 236 | LY_ERR lyd_parse_xml(const struct ly_ctx *ctx, const struct lysc_ext_instance *ext, struct lyd_node *parent, |
| 237 | struct lyd_node **first_p, struct ly_in *in, uint32_t parse_opts, uint32_t val_opts, enum lyd_type data_type, |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 238 | struct lyd_node **envp, struct ly_set *parsed, ly_bool *subtree_sibling, struct lyd_ctx **lydctx_p); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 239 | |
| 240 | /** |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 241 | * @brief Parse JSON string as a YANG data tree. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 242 | * |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 243 | * @param[in] ctx libyang context. |
aPiecek | b0445f2 | 2021-06-24 11:34:07 +0200 | [diff] [blame] | 244 | * @param[in] ext Optional extension instance to parse data following the schema tree specified in the extension instance |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 245 | * @param[in] parent Parent to connect the parsed nodes to, if any. |
| 246 | * @param[in,out] first_p Pointer to the first top-level parsed node, used only if @p parent is NULL. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 247 | * @param[in] in Input structure. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 248 | * @param[in] parse_opts Options for parser, see @ref dataparseroptions. |
| 249 | * @param[in] val_opts Options for the validation phase, see @ref datavalidationoptions. |
| 250 | * @param[in] data_type Expected data type of the data. |
| 251 | * @param[out] parsed Set to add all the parsed siblings into. |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 252 | * @param[out] subtree_sibling Set if ::LYD_PARSE_SUBTREE is used and another subtree is following in @p in. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 253 | * @param[out] lydctx_p Data parser context to finish validation. |
| 254 | * @return LY_ERR value. |
| 255 | */ |
Radek Krejci | f16e254 | 2021-02-17 15:39:23 +0100 | [diff] [blame] | 256 | LY_ERR lyd_parse_json(const struct ly_ctx *ctx, const struct lysc_ext_instance *ext, struct lyd_node *parent, |
| 257 | struct lyd_node **first_p, struct ly_in *in, uint32_t parse_opts, uint32_t val_opts, enum lyd_type data_type, |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 258 | struct ly_set *parsed, ly_bool *subtree_sibling, struct lyd_ctx **lydctx_p); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 259 | |
| 260 | /** |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 261 | * @brief Parse binary LYB data as a YANG data tree. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 262 | * |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 263 | * @param[in] ctx libyang context. |
aPiecek | b0445f2 | 2021-06-24 11:34:07 +0200 | [diff] [blame] | 264 | * @param[in] ext Optional extension instance to parse data following the schema tree specified in the extension instance |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 265 | * @param[in] parent Parent to connect the parsed nodes to, if any. |
| 266 | * @param[in,out] first_p Pointer to the first top-level parsed node, used only if @p parent is NULL. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 267 | * @param[in] in Input structure. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 268 | * @param[in] parse_opts Options for parser, see @ref dataparseroptions. |
| 269 | * @param[in] val_opts Options for the validation phase, see @ref datavalidationoptions. |
| 270 | * @param[in] data_type Expected data type of the data. |
| 271 | * @param[out] parsed Set to add all the parsed siblings into. |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 272 | * @param[out] subtree_sibling Set if ::LYD_PARSE_SUBTREE is used and another subtree is following in @p in. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 273 | * @param[out] lydctx_p Data parser context to finish validation. |
| 274 | * @return LY_ERR value. |
| 275 | */ |
Radek Krejci | f16e254 | 2021-02-17 15:39:23 +0100 | [diff] [blame] | 276 | LY_ERR lyd_parse_lyb(const struct ly_ctx *ctx, const struct lysc_ext_instance *ext, struct lyd_node *parent, |
| 277 | struct lyd_node **first_p, struct ly_in *in, uint32_t parse_opts, uint32_t val_opts, enum lyd_type data_type, |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 278 | struct ly_set *parsed, ly_bool *subtree_sibling, struct lyd_ctx **lydctx_p); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 279 | |
| 280 | /** |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 281 | * @brief Search all the parents for an operation node, check validity based on internal parser flags. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 282 | * |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 283 | * @param[in] parent Parent to connect the parsed nodes to. |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 284 | * @param[in] int_opts Internal parser options. |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 285 | * @param[out] op Found operation, if any. |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 286 | * @return LY_ERR value. |
| 287 | */ |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 288 | LY_ERR lyd_parser_find_operation(const struct lyd_node *parent, uint32_t int_opts, struct lyd_node **op); |
Michal Vasko | afac782 | 2020-10-20 14:22:26 +0200 | [diff] [blame] | 289 | |
| 290 | /** |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 291 | * @brief Check that a data node representing the @p snode is suitable based on options. |
| 292 | * |
| 293 | * @param[in] lydctx Common data parsers context. |
| 294 | * @param[in] snode Schema node to check. |
| 295 | * @return LY_SUCCESS or LY_EVALID |
| 296 | */ |
| 297 | LY_ERR lyd_parser_check_schema(struct lyd_ctx *lydctx, const struct lysc_node *snode); |
| 298 | |
| 299 | /** |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 300 | * @brief Wrapper around ::lyd_create_term() for data parsers. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 301 | * |
| 302 | * @param[in] lydctx Data parser context. |
Radek Krejci | 84d7fd7 | 2021-07-14 18:32:21 +0200 | [diff] [blame] | 303 | * @param[in] schema Schema node of the new data node. |
| 304 | * @param[in] value String value to be parsed. |
| 305 | * @param[in] value_len Length of @p value, must be set correctly. |
| 306 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
| 307 | * @param[in] format Input format of @p value. |
| 308 | * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix). |
| 309 | * @param[in] hints [Data parser's hints](@ref lydvalhints) for the value's type. |
| 310 | * @param[out] node Created node. |
| 311 | * @return LY_SUCCESS on success. |
| 312 | * @return LY_EINCOMPLETE in case data tree is needed to finish the validation. |
| 313 | * @return LY_ERR value if an error occurred. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 314 | */ |
Radek Krejci | 09c7744 | 2021-04-26 11:10:34 +0200 | [diff] [blame] | 315 | LY_ERR lyd_parser_create_term(struct lyd_ctx *lydctx, const struct lysc_node *schema, const void *value, size_t value_len, |
Radek Krejci | 8df109d | 2021-04-23 12:19:08 +0200 | [diff] [blame] | 316 | ly_bool *dynamic, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints, struct lyd_node **node); |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 317 | |
| 318 | /** |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 319 | * @brief Wrapper around ::lyd_create_meta() for data parsers. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 320 | * |
| 321 | * @param[in] lydctx Data parser context. |
Michal Vasko | b68571a | 2020-11-06 17:18:41 +0100 | [diff] [blame] | 322 | * @param[in] parent Parent of the created meta. Must be set if @p meta is NULL. |
| 323 | * @param[in,out] meta First existing meta to connect to or empty pointer to set. Must be set if @p parent is NULL. |
| 324 | * @param[in] mod Module of the created metadata. |
| 325 | * @param[in] name Metadata name. |
| 326 | * @param[in] name_len Length of @p name. |
| 327 | * @param[in] value Metadata value. |
| 328 | * @param[in] value_len Length of @p value. |
| 329 | * @param[in,out] dynamic Whether the @p value is dynamically allocated, is adjusted once the value is assigned. |
| 330 | * @param[in] format Prefix format. |
| 331 | * @param[in] prefix_data Prefix format data (see ::ly_resolve_prefix()). |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 332 | * @param[in] hints [Value hint](@ref lydvalhints) from the parser regarding the value type. |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 333 | * @param[in] ctx_node Value context node. |
Michal Vasko | b68571a | 2020-11-06 17:18:41 +0100 | [diff] [blame] | 334 | * @return LY_ERR value. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 335 | */ |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 336 | LY_ERR lyd_parser_create_meta(struct lyd_ctx *lydctx, struct lyd_node *parent, struct lyd_meta **meta, |
Michal Vasko | ddd7659 | 2022-01-17 13:34:48 +0100 | [diff] [blame] | 337 | const struct lys_module *mod, const char *name, size_t name_len, const void *value, size_t value_len, |
| 338 | ly_bool *dynamic, LY_VALUE_FORMAT format, void *prefix_data, uint32_t hints, const struct lysc_node *ctx_node); |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 339 | |
Michal Vasko | 95c6d5c | 2022-05-20 10:33:39 +0200 | [diff] [blame] | 340 | /** |
| 341 | * @brief Check that a list has all its keys. |
| 342 | * |
| 343 | * @param[in] node List to check. |
| 344 | * @return LY_SUCCESS on success. |
| 345 | * @return LY_ENOT on a missing key. |
| 346 | */ |
| 347 | LY_ERR lyd_parse_check_keys(struct lyd_node *node); |
| 348 | |
| 349 | /** |
| 350 | * @brief Set data flags for a newly parsed node. |
| 351 | * |
| 352 | * @param[in] node Node to use. |
| 353 | * @param[in,out] meta Node metadata, may be removed from. |
| 354 | * @param[in] lydctx Data parsing context. |
| 355 | * @param[in] ext Extension instance if @p node was parsed for one. |
| 356 | * @return LY_ERR value. |
| 357 | */ |
| 358 | LY_ERR lyd_parse_set_data_flags(struct lyd_node *node, struct lyd_meta **meta, struct lyd_ctx *lydctx, |
| 359 | struct lysc_ext_instance *ext); |
| 360 | |
Radek Krejci | f0e1ba5 | 2020-05-22 15:14:35 +0200 | [diff] [blame] | 361 | #endif /* LY_PARSER_INTERNAL_H_ */ |