diff options
Diffstat (limited to '')
-rw-r--r-- | src/parser_internal.h | 62 |
1 files changed, 60 insertions, 2 deletions
diff --git a/src/parser_internal.h b/src/parser_internal.h index 458d297..92412e2 100644 --- a/src/parser_internal.h +++ b/src/parser_internal.h @@ -1,9 +1,10 @@ /** * @file parser_internal.h * @author Radek Krejci <rkrejci@cesnet.cz> + * @author Michal Vasko <mvasko@cesnet.cz> * @brief Internal structures and functions for libyang parsers * - * Copyright (c) 2020 CESNET, z.s.p.o. + * Copyright (c) 2020 - 2023 CESNET, z.s.p.o. * * This source code is licensed under BSD 3-Clause License (the "License"). * You may not use this file except in compliance with the License. @@ -27,6 +28,23 @@ struct lysp_yin_ctx; struct lysp_ctx; /** + * @brief Check data parser error taking into account multi-error validation. + * + * @param[in] r Local return value. + * @param[in] err_cmd Command to perform on any error. + * @param[in] lydctx Data parser context. + * @param[in] label Label to go to on fatal error. + */ +#define LY_DPARSER_ERR_GOTO(r, err_cmd, lydctx, label) \ + if (r) { \ + err_cmd; \ + if ((r != LY_EVALID) || !lydctx || !(lydctx->val_opts & LYD_VALIDATE_MULTI_ERROR) || \ + (ly_vecode(((struct lyd_ctx *)lydctx)->data_ctx->ctx) == LYVE_SYNTAX)) { \ + goto label; \ + } \ + } + +/** * @brief Callback for ::lyd_ctx to free the structure * * @param[in] ctx Data parser context to free. @@ -43,6 +61,7 @@ typedef void (*lyd_ctx_free_clb)(struct lyd_ctx *ctx); #define LYD_INTOPT_ANY 0x10 /**< Anydata/anyxml content is being parsed, there can be anything. */ #define LYD_INTOPT_WITH_SIBLINGS 0x20 /**< Parse the whole input with any siblings. */ #define LYD_INTOPT_NO_SIBLINGS 0x40 /**< If there are any siblings, return an error. */ +#define LYD_INTOPT_EVENTTIME 0x80 /**< Parse notification eventTime node. */ /** * @brief Internal (common) context for YANG data parsers. @@ -118,7 +137,8 @@ struct lyd_json_ctx { /* callbacks */ lyd_ctx_free_clb free; - struct lyjson_ctx *jsonctx; /**< JSON context */ + struct lyjson_ctx *jsonctx; /**< JSON context */ + const struct lysc_node *any_schema; /**< parent anyxml/anydata schema node if parsing nested data tree */ }; /** @@ -279,6 +299,27 @@ LY_ERR lyd_parse_json(const struct ly_ctx *ctx, const struct lysc_ext_instance * struct ly_set *parsed, ly_bool *subtree_sibling, struct lyd_ctx **lydctx_p); /** + * @brief Parse JSON string as a RESTCONF message. + * + * @param[in] ctx libyang context. + * @param[in] ext Optional extension instance to parse data following the schema tree specified in the extension instance + * @param[in] parent Parent to connect the parsed nodes to, if any. + * @param[in,out] first_p Pointer to the first top-level parsed node, used only if @p parent is NULL. + * @param[in] in Input structure. + * @param[in] parse_opts Options for parser, see @ref dataparseroptions. + * @param[in] val_opts Options for the validation phase, see @ref datavalidationoptions. + * @param[in] data_type Expected RESTCONF data type of the data. + * @param[out] envp Individual parsed envelopes tree, may be returned possibly even on an error. + * @param[out] parsed Set to add all the parsed siblings into. + * @param[out] subtree_sibling Set if ::LYD_PARSE_SUBTREE is used and another subtree is following in @p in. + * @param[out] lydctx_p Data parser context to finish validation. + * @return LY_ERR value. + */ +LY_ERR lyd_parse_json_restconf(const struct ly_ctx *ctx, const struct lysc_ext_instance *ext, struct lyd_node *parent, + struct lyd_node **first_p, struct ly_in *in, uint32_t parse_opts, uint32_t val_opts, enum lyd_type data_type, + struct lyd_node **envp, struct ly_set *parsed, struct lyd_ctx **lydctx_p); + +/** * @brief Parse binary LYB data as a YANG data tree. * * @param[in] ctx libyang context. @@ -299,6 +340,15 @@ LY_ERR lyd_parse_lyb(const struct ly_ctx *ctx, const struct lysc_ext_instance *e struct ly_set *parsed, ly_bool *subtree_sibling, struct lyd_ctx **lydctx_p); /** + * @brief Validate eventTime date-and-time value. + * + * @param[in] node Opaque eventTime node. + * @return LY_SUCCESS on success. + * @return LY_ERR value on error. + */ +LY_ERR lyd_parser_notif_eventtime_validate(const struct lyd_node *node); + +/** * @brief Search all the parents for an operation node, check validity based on internal parser flags. * * @param[in] parent Parent to connect the parsed nodes to. @@ -309,6 +359,14 @@ LY_ERR lyd_parse_lyb(const struct ly_ctx *ctx, const struct lysc_ext_instance *e LY_ERR lyd_parser_find_operation(const struct lyd_node *parent, uint32_t int_opts, struct lyd_node **op); /** + * @brief Get schema node of a node being parsed, use nodes stored for logging. + * + * @param[in] node Node whose schema node to get. + * @return Schema node even for an opaque node, NULL if none found. + */ +const struct lysc_node *lyd_parser_node_schema(const struct lyd_node *node); + +/** * @brief Check that a data node representing the @p snode is suitable based on options. * * @param[in] lydctx Common data parsers context. |