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