Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file tree_data_internal.h |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief internal functions for YANG schema trees. |
| 5 | * |
| 6 | * Copyright (c) 2015 - 2019 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_TREE_DATA_INTERNAL_H_ |
| 16 | #define LY_TREE_DATA_INTERNAL_H_ |
| 17 | |
| 18 | #include "tree_data.h" |
Radek Krejci | aca7403 | 2019-06-04 08:53:06 +0200 | [diff] [blame] | 19 | #include "plugins_types.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * @brief Get address of a node's child pointer if any. |
| 23 | * |
| 24 | * Decides the node's type and in case it has a children list, returns its address. |
| 25 | * @param[in] node Node to check. |
| 26 | * @return Address of the node's child member if any, NULL otherwise. |
| 27 | */ |
| 28 | struct lyd_node **lyd_node_children_p(struct lyd_node *node); |
| 29 | |
| 30 | /** |
| 31 | * @brief Check validity of data parser options. |
| 32 | * |
| 33 | * @param ctx libyang context |
| 34 | * @param options Data parser options to check |
| 35 | * @param func name of the function where called |
| 36 | * @return LY_SUCCESS when options are ok |
| 37 | * @return LY_EINVAL when multiple data types bits are set, or incompatible options are used together. |
| 38 | */ |
Radek Krejci | f3b6fec | 2019-07-24 15:53:11 +0200 | [diff] [blame] | 39 | LY_ERR lyd_parse_options_check(struct ly_ctx *ctx, int options, const char *func); |
| 40 | |
| 41 | /** |
| 42 | * @brief Get string describing the type of the data according to the data parser options. |
| 43 | * @param[in] options Data parser options to examine. |
| 44 | * @return String description of the data set type. |
| 45 | */ |
| 46 | const char *lyd_parse_options_type2str(int options); |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 47 | |
| 48 | /** |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 49 | * @brief Validate, canonize and store the given @p value into the node according to the node's type's rules. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 50 | * |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame^] | 51 | * @param[in] node Data node for the @p value. |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 52 | * @param[in] value String value to be parsed, must not be NULL. |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 53 | * @param[in] value_len Length of the give @p value (mandatory). |
| 54 | * @param[in] dynamic Flag if @p value is a dynamically allocated memory and should be directly consumed/freed inside the function. |
Radek Krejci | 3c9758d | 2019-07-11 16:49:10 +0200 | [diff] [blame] | 55 | * @param[in] second Flag for the second call after returning LY_EINCOMPLETE |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 56 | * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string. |
Radek Krejci | aca7403 | 2019-06-04 08:53:06 +0200 | [diff] [blame] | 57 | * @param[in] parser Parser's data for @p get_prefix |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 58 | * @param[in] format Input format of the data. |
Radek Krejci | e553e6d | 2019-06-07 15:33:18 +0200 | [diff] [blame] | 59 | * @param[in] trees ([Sized array](@ref sizedarrays)) of data trees (e.g. when validating RPC/Notification) where the required |
| 60 | * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete, |
| 61 | * then LY_EINCOMPLETE can be returned. |
| 62 | * @return LY_SUCCESS on success |
| 63 | * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation. |
| 64 | * @return LY_ERR value if an error occurred. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 65 | */ |
Radek Krejci | 3c9758d | 2019-07-11 16:49:10 +0200 | [diff] [blame] | 66 | LY_ERR lyd_value_parse(struct lyd_node_term *node, const char *value, size_t value_len, int dynamic, int second, |
Radek Krejci | 576b23f | 2019-07-12 14:06:32 +0200 | [diff] [blame] | 67 | ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format, const struct lyd_node **trees); |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 68 | |
| 69 | /** |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame^] | 70 | * @brief Validate, canonize and store the given @p value into the attribute according to the metadata annotation type's rules. |
| 71 | * |
| 72 | * @param[in] attr Data attribute for the @p value. |
| 73 | * @param[in] value String value to be parsed, must not be NULL. |
| 74 | * @param[in] value_len Length of the give @p value (mandatory). |
| 75 | * @param[in] dynamic Flag if @p value is a dynamically allocated memory and should be directly consumed/freed inside the function. |
| 76 | * @param[in] second Flag for the second call after returning LY_EINCOMPLETE |
| 77 | * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string. |
| 78 | * @param[in] parser Parser's data for @p get_prefix |
| 79 | * @param[in] format Input format of the data. |
| 80 | * @param[in] trees ([Sized array](@ref sizedarrays)) of data trees (e.g. when validating RPC/Notification) where the required |
| 81 | * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete, |
| 82 | * then LY_EINCOMPLETE can be returned. |
| 83 | * @return LY_SUCCESS on success |
| 84 | * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation. |
| 85 | * @return LY_ERR value if an error occurred. |
| 86 | */ |
| 87 | LY_ERR lyd_value_parse_attr(struct lyd_attr *attr, const char *value, size_t value_len, int dynamic, int second, |
| 88 | ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format, const struct lyd_node **trees); |
| 89 | |
| 90 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 91 | * @brief Parse XML string as YANG data tree. |
| 92 | * |
| 93 | * @param[in] ctx libyang context |
| 94 | * @param[in] data Pointer to the XML string representation of the YANG data to parse. |
| 95 | * @param[in] options @ref dataparseroptions |
Radek Krejci | f3b6fec | 2019-07-24 15:53:11 +0200 | [diff] [blame] | 96 | * @param[in] trees ([Sized array](@ref sizedarrays)) of data trees (e.g. when validating RPC/Notification) where the required |
| 97 | * data instances (leafref target, instance-identifier, when, must) can be placed. To simply prepare this structure, |
| 98 | * use lyd_trees_new(). In case of parsing RPC/action reply (LYD_OPT_RPCREPLY), the first tree in the array MUST be |
| 99 | * complete RPC/action data tree (the source request) for the reply. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 100 | * @param[out] result Resulting list of the parsed data trees. Note that NULL can be a valid result. |
| 101 | * @reutn LY_ERR value. |
| 102 | */ |
Radek Krejci | f3b6fec | 2019-07-24 15:53:11 +0200 | [diff] [blame] | 103 | LY_ERR lyd_parse_xml(struct ly_ctx *ctx, const char *data, int options, const struct lyd_node **trees, struct lyd_node **result); |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * @defgroup datahash Data nodes hash manipulation |
| 107 | * @ingroup datatree |
| 108 | */ |
| 109 | |
| 110 | /** |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 111 | * @brief Generate hash for the node. |
| 112 | * |
| 113 | * @param[in] node Data node to (re)generate hash value. |
| 114 | * @return LY_ERR value. |
| 115 | */ |
| 116 | LY_ERR lyd_hash(struct lyd_node *node); |
| 117 | |
| 118 | /** |
| 119 | * @brief Insert hash of the node into the hash table of its parent. |
| 120 | * |
| 121 | * @param[in] node Data node which hash will be inserted into the lyd_node_inner::children_hash hash table of its parent. |
| 122 | * @return LY_ERR value. |
| 123 | */ |
| 124 | LY_ERR lyd_insert_hash(struct lyd_node *node); |
| 125 | |
| 126 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 127 | * @brief Maintain node's parent's children hash table when unlinking the node. |
| 128 | * |
| 129 | * When completely freeing data tree, it is expected to free the parent's children hash table first, at once. |
| 130 | * |
| 131 | * @param[in] node The data node being unlinked from its parent. |
| 132 | */ |
| 133 | void lyd_unlink_hash(struct lyd_node *node); |
| 134 | |
| 135 | /** @} datahash */ |
| 136 | |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 137 | /** |
| 138 | * @brief Free path (target) structure of the lyd_value. |
| 139 | * |
| 140 | * @param[in] ctx libyang context. |
| 141 | * @param[in] path The structure ([sized array](@ref sizedarrays)) to free. |
| 142 | */ |
| 143 | void lyd_value_free_path(struct ly_ctx *ctx, struct lyd_value_path *path); |
| 144 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 145 | #endif /* LY_TREE_DATA_INTERNAL_H_ */ |