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