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 | * |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 6 | * Copyright (c) 2015 - 2020 CESNET, z.s.p.o. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 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 | |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 18 | #include "log.h" |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 19 | #include "lyb.h" |
Radek Krejci | aca7403 | 2019-06-04 08:53:06 +0200 | [diff] [blame] | 20 | #include "plugins_types.h" |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 21 | #include "set.h" |
| 22 | #include "tree_data.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 23 | |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 24 | #include <stddef.h> |
| 25 | |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 26 | struct ly_path_predicate; |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 27 | struct lysc_module; |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 28 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 29 | /** |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 30 | * @brief Internal data parser flags. |
| 31 | */ |
| 32 | #define LYD_INTOPT_RPC 0x01 /**< RPC/action invocation is being parsed */ |
| 33 | #define LYD_INTOPT_NOTIF 0x02 /**< notification is being parsed */ |
| 34 | #define LYD_INTOPT_REPLY 0x04 /**< RPC/action reply is being parsed */ |
| 35 | |
| 36 | /** |
| 37 | * @brief Hash schema sibling to be used for LYB data. |
| 38 | * |
| 39 | * @param[in] sibling Sibling to hash. |
| 40 | * @param[in] collision_id Collision ID of the hash to generate. |
| 41 | * @return Generated hash. |
| 42 | */ |
| 43 | LYB_HASH lyb_hash(struct lysc_node *sibling, uint8_t collision_id); |
| 44 | |
| 45 | /** |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 46 | * @brief Check whether a sibling's module is in a module array. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 47 | * |
| 48 | * @param[in] sibling Sibling to check. |
| 49 | * @param[in] models Modules in a sized array. |
| 50 | * @return non-zero if the module was found, |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 51 | * @return Boolean value whether @p sibling's module found in the given @p models array. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 52 | */ |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 53 | ly_bool lyb_has_schema_model(const struct lysc_node *sibling, const struct lys_module **models); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 54 | |
| 55 | /** |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 56 | * @brief Check whether a node to be deleted is the first top-level sibling. |
| 57 | * |
| 58 | * @param[in] first First sibling. |
| 59 | * @param[in] to_del Node to be deleted. |
| 60 | */ |
| 61 | #define LYD_DEL_IS_ROOT(first, to_del) (((first) == (to_del)) && !(first)->parent && !(first)->prev->next) |
| 62 | |
| 63 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 64 | * @brief Get address of a node's child pointer if any. |
| 65 | * |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 66 | * @param[in] node Node to check. |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 67 | * @return Address of the node's child member, |
| 68 | * @return NULL if there is no child pointer. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 69 | */ |
| 70 | struct lyd_node **lyd_node_children_p(struct lyd_node *node); |
| 71 | |
| 72 | /** |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 73 | * @brief Just like ::lys_getnext() but iterates over all data instances of the schema nodes. |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 74 | * |
| 75 | * @param[in] last Last returned data node. |
| 76 | * @param[in] sibling Data node sibling to search in. |
| 77 | * @param[in,out] slast Schema last node, set to NULL for first call and do not change afterwards. |
| 78 | * May not be set if the function is used only for any suitable node existence check (such as the existence |
| 79 | * of any choice case data). |
| 80 | * @param[in] parent Schema parent of the iterated children nodes. |
| 81 | * @param[in] module Schema module of the iterated top-level nodes. |
| 82 | * @return Next matching data node, |
| 83 | * @return NULL if last data node was already returned. |
| 84 | */ |
| 85 | struct lyd_node *lys_getnext_data(const struct lyd_node *last, const struct lyd_node *sibling, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 86 | const struct lysc_node **slast, const struct lysc_node *parent, |
| 87 | const struct lysc_module *module); |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 88 | |
| 89 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 90 | * @brief Create a term (leaf/leaf-list) node from a string value. |
| 91 | * |
| 92 | * Hash is calculated and new node flag is set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 93 | * |
| 94 | * @param[in] schema Schema node of the new data node. |
| 95 | * @param[in] value String value to be parsed. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 96 | * @param[in] value_len Length of @p value, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 97 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 98 | * @param[in] format Input format of @p value. |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 99 | * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix). |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 100 | * @param[in] hints [Value hints](@ref lydvalhints) from the parser regarding the value type. |
| 101 | * @param[out] incomplete Whether the value needs to be resolved. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 102 | * @param[out] node Created node. |
| 103 | * @return LY_SUCCESS on success. |
| 104 | * @return LY_EINCOMPLETE in case data tree is needed to finish the validation. |
| 105 | * @return LY_ERR value if an error occurred. |
| 106 | */ |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 107 | LY_ERR lyd_create_term(const struct lysc_node *schema, const char *value, size_t value_len, ly_bool *dynamic, |
| 108 | LY_PREFIX_FORMAT format, void *prefix_data, uint32_t hints, ly_bool *incomplete, struct lyd_node **node); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 109 | |
| 110 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 111 | * @brief Create a term (leaf/leaf-list) node from a parsed value by duplicating it. |
| 112 | * |
| 113 | * Hash is calculated and new node flag is set. |
| 114 | * |
| 115 | * @param[in] schema Schema node of the new data node. |
| 116 | * @param[in] val Parsed value to use. |
| 117 | * @param[out] node Created node. |
| 118 | * @return LY_SUCCESS on success. |
| 119 | * @return LY_ERR value if an error occurred. |
| 120 | */ |
| 121 | LY_ERR lyd_create_term2(const struct lysc_node *schema, const struct lyd_value *val, struct lyd_node **node); |
| 122 | |
| 123 | /** |
| 124 | * @brief Create an inner (container/list/RPC/action/notification) node. |
| 125 | * |
| 126 | * Hash is calculated and new node flag is set except |
| 127 | * for list with keys, when the hash is not calculated! |
| 128 | * Also, non-presence container has its default flag set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 129 | * |
| 130 | * @param[in] schema Schema node of the new data node. |
| 131 | * @param[out] node Created node. |
| 132 | * @return LY_SUCCESS on success. |
| 133 | * @return LY_ERR value if an error occurred. |
| 134 | */ |
| 135 | LY_ERR lyd_create_inner(const struct lysc_node *schema, struct lyd_node **node); |
| 136 | |
| 137 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 138 | * @brief Create a list with all its keys (cannot be used for key-less list). |
| 139 | * |
| 140 | * Hash is calculated and new node flag is set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 141 | * |
| 142 | * @param[in] schema Schema node of the new data node. |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 143 | * @param[in] predicates Compiled key list predicates. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 144 | * @param[out] node Created node. |
| 145 | * @return LY_SUCCESS on success. |
| 146 | * @return LY_ERR value if an error occurred. |
| 147 | */ |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 148 | LY_ERR lyd_create_list(const struct lysc_node *schema, const struct ly_path_predicate *predicates, struct lyd_node **node); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 149 | |
| 150 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 151 | * @brief Create an anyxml/anydata node. |
| 152 | * |
| 153 | * Hash is calculated and flags are properly set based on @p is_valid. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 154 | * |
| 155 | * @param[in] schema Schema node of the new data node. |
| 156 | * @param[in] value Value of the any node, is directly assigned into the data node. |
| 157 | * @param[in] value_type Value type of the value. |
| 158 | * @param[out] node Created node. |
| 159 | * @return LY_SUCCESS on success. |
| 160 | * @return LY_ERR value if an error occurred. |
| 161 | */ |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 162 | LY_ERR lyd_create_any(const struct lysc_node *schema, const void *value, LYD_ANYDATA_VALUETYPE value_type, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 163 | struct lyd_node **node); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 164 | |
| 165 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 166 | * @brief Create an opaque node. |
| 167 | * |
| 168 | * @param[in] ctx libyang context. |
| 169 | * @param[in] name Element name. |
| 170 | * @param[in] name_len Length of @p name, must be set correctly. |
| 171 | * @param[in] value String value to be parsed. |
| 172 | * @param[in] value_len Length of @p value, must be set correctly. |
| 173 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
| 174 | * @param[in] format Input format of @p value and @p ns. |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 175 | * @param[in] hints [Hints](@ref lydhints) from the parser regarding the node/value type. |
Radek Krejci | d46e46a | 2020-09-15 14:22:42 +0200 | [diff] [blame] | 176 | * @param[in] val_prefs Possible value prefixes, array is spent (even in case the function fails). |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 177 | * @param[in] prefix Element prefix. |
| 178 | * @param[in] pref_len Length of @p prefix, must be set correctly. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 179 | * @param[in] module_key Mandatory key to reference module, can be namespace or name. |
| 180 | * @param[in] module_key_len Length of @p module_key, must be set correctly. |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 181 | * @param[out] node Created node. |
| 182 | * @return LY_SUCCESS on success. |
| 183 | * @return LY_ERR value if an error occurred. |
| 184 | */ |
| 185 | LY_ERR lyd_create_opaq(const struct ly_ctx *ctx, const char *name, size_t name_len, const char *value, size_t value_len, |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 186 | ly_bool *dynamic, LYD_FORMAT format, uint32_t hints, struct ly_prefix *val_prefs, const char *prefix, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 187 | size_t pref_len, const char *module_key, size_t module_key_len, struct lyd_node **node); |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 188 | |
| 189 | /** |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 190 | * @brief Check the existence and create any non-existing implicit siblings, recursively for the created nodes. |
| 191 | * |
| 192 | * @param[in] parent Parent of the potential default values, NULL for top-level siblings. |
| 193 | * @param[in,out] first First sibling. |
| 194 | * @param[in] sparent Schema parent of the siblings, NULL if schema of @p parent can be used. |
| 195 | * @param[in] mod Module of the default values, NULL for nested siblings. |
| 196 | * @param[in] node_types Optional set to add nodes with unresolved types into. |
| 197 | * @param[in] node_when Optional set to add nodes with "when" conditions into. |
| 198 | * @param[in] impl_opts Implicit options (@ref implicitoptions). |
| 199 | * @param[in,out] diff Validation diff. |
| 200 | * @return LY_ERR value. |
| 201 | */ |
| 202 | LY_ERR lyd_new_implicit_r(struct lyd_node *parent, struct lyd_node **first, const struct lysc_node *sparent, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 203 | const struct lys_module *mod, struct ly_set *node_types, struct ly_set *node_when, |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 204 | uint32_t impl_opts, struct lyd_node **diff); |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 205 | |
| 206 | /** |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 207 | * @brief Find the next node, before which to insert the new node. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 208 | * |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 209 | * @param[in] first_sibling First sibling of the nodes to consider. |
| 210 | * @param[in] new_node Node that will be inserted. |
| 211 | * @return Node to insert after. |
| 212 | * @return NULL if the new node should be first. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 213 | */ |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 214 | struct lyd_node *lyd_insert_get_next_anchor(const struct lyd_node *first_sibling, const struct lyd_node *new_node); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 215 | |
| 216 | /** |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 217 | * @brief Insert a node into parent/siblings. Order and hashes are fully handled. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 218 | * |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 219 | * @param[in] parent Parent to insert into, NULL for top-level sibling. |
| 220 | * @param[in,out] first_sibling First sibling, NULL if no top-level sibling exist yet. Can be also NULL if @p parent is set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 221 | * @param[in] node Individual node (without siblings) to insert. |
| 222 | */ |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 223 | void lyd_insert_node(struct lyd_node *parent, struct lyd_node **first_sibling, struct lyd_node *node); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 224 | |
| 225 | /** |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 226 | * @brief Insert a metadata (last) into a parent |
| 227 | * |
| 228 | * @param[in] parent Parent of the metadata. |
| 229 | * @param[in] meta Metadata (list) to be added into the @p parent. |
| 230 | */ |
| 231 | void lyd_insert_meta(struct lyd_node *parent, struct lyd_meta *meta); |
| 232 | |
| 233 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 234 | * @brief Create and insert a metadata (last) into a parent. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 235 | * |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 236 | * @param[in] parent Parent of the metadata, can be NULL. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 237 | * @param[in,out] meta Metadata list to add at its end if @p parent is NULL, returned created attribute. |
| 238 | * @param[in] mod Metadata module (with the annotation definition). |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 239 | * @param[in] name Attribute name. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 240 | * @param[in] name_len Length of @p name, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 241 | * @param[in] value String value to be parsed. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 242 | * @param[in] value_len Length of @p value, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 243 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 244 | * @param[in] format Input format of @p value. |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 245 | * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix). |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 246 | * @param[in] hints [Value hints](@ref lydvalhints) from the parser regarding the value type. |
| 247 | * @param[out] incomplete Whether the value needs to be resolved. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 248 | * @return LY_SUCCESS on success. |
| 249 | * @return LY_EINCOMPLETE in case data tree is needed to finish the validation. |
| 250 | * @return LY_ERR value if an error occurred. |
| 251 | */ |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 252 | LY_ERR lyd_create_meta(struct lyd_node *parent, struct lyd_meta **meta, const struct lys_module *mod, const char *name, |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 253 | size_t name_len, const char *value, size_t value_len, ly_bool *dynamic, LY_PREFIX_FORMAT format, |
| 254 | void *prefix_data, uint32_t hints, ly_bool *incomplete); |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 255 | |
| 256 | /** |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 257 | * @brief Insert an attribute (last) into a parent |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 258 | * |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 259 | * @param[in] parent Parent of the attributes. |
| 260 | * @param[in] attr Attribute (list) to be added into the @p parent. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 261 | */ |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 262 | void lyd_insert_attr(struct lyd_node *parent, struct lyd_attr *attr); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 263 | |
| 264 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 265 | * @brief Create and insert a generic attribute (last) into a parent. |
| 266 | * |
| 267 | * @param[in] parent Parent of the attribute, can be NULL. |
| 268 | * @param[in,out] attr Attribute list to add at its end if @p parent is NULL, returned created attribute. |
| 269 | * @param[in] ctx libyang context. |
| 270 | * @param[in] name Attribute name. |
| 271 | * @param[in] name_len Length of @p name, must be set correctly. |
| 272 | * @param[in] value String value to be parsed. |
| 273 | * @param[in] value_len Length of @p value, must be set correctly. |
| 274 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
| 275 | * @param[in] format Input format of @p value and @p ns. |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 276 | * @param[in] hints [Hints](@ref lydhints) from the parser regarding the node/value type. |
Radek Krejci | d46e46a | 2020-09-15 14:22:42 +0200 | [diff] [blame] | 277 | * @param[in] val_prefs Possible value prefixes, array is spent (even in case the function fails). |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 278 | * @param[in] prefix Attribute prefix. |
| 279 | * @param[in] prefix_len Attribute prefix length. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 280 | * @param[in] module_key Mandatory key to reference module, can be namespace or name. |
| 281 | * @param[in] module_key_len Length of @p module_key, must be set correctly. |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 282 | * @return LY_SUCCESS on success, |
| 283 | * @return LY_ERR value on error. |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 284 | */ |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 285 | LY_ERR lyd_create_attr(struct lyd_node *parent, struct lyd_attr **attr, const struct ly_ctx *ctx, const char *name, |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 286 | size_t name_len, const char *value, size_t value_len, ly_bool *dynamic, LYD_FORMAT format, uint32_t hints, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 287 | struct ly_prefix *val_prefs, const char *prefix, size_t prefix_len, const char *module_key, size_t module_key_len); |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 288 | |
| 289 | /** |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 290 | * @brief Store and canonize the given @p value into @p val according to the schema node type rules. |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 291 | * |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 292 | * @param[in] ctx libyang context. |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 293 | * @param[in,out] val Storage for the value. |
| 294 | * @param[in] type Type of the value. |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 295 | * @param[in] value String value to be parsed, must not be NULL. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 296 | * @param[in] value_len Length of the give @p value, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 297 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 298 | * @param[in] format Input format of @p value. |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 299 | * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix). |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 300 | * @param[in] hints [Value hints](@ref lydvalhints) from the parser. |
| 301 | * @param[in] ctx_node Context schema node. |
| 302 | * @param[out] incomplete Optional, set if the value also needs to be resolved. |
| 303 | * @param[in] log_elem_type Elem type for logging. |
| 304 | * @param[in] log_elem Elem for logging. |
| 305 | * @return LY_SUCCESS on success, |
| 306 | * @return LY_ERR value on error. |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 307 | */ |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 308 | LY_ERR lyd_value_store(const struct ly_ctx *ctx, struct lyd_value *val, const struct lysc_type *type, const char *value, |
| 309 | size_t value_len, ly_bool *dynamic, LY_PREFIX_FORMAT format, void *prefix_data, uint32_t hints, |
| 310 | const struct lysc_node *ctx_node, ly_bool *incomplete, enum LY_VLOG_ELEM log_elem_type, const void *log_elem); |
| 311 | |
| 312 | /** |
| 313 | * @brief Validate previously incompletely stored value. |
| 314 | * |
| 315 | * @param[in] ctx libyang context. |
| 316 | * @param[in] type Schema type of the value (not the stored one, but the original one). |
| 317 | * @param[in,out] val Stored value to resolve. |
| 318 | * @param[in] ctx_node Context node for the resolution. |
| 319 | * @param[in] tree Data tree for the resolution. |
| 320 | * @param[in] log_elem_type Elem type for logging. |
| 321 | * @param[in] log_elem Elem for logging. |
| 322 | * @return LY_SUCCESS on success, |
| 323 | * @return LY_ERR value on error. |
| 324 | */ |
| 325 | LY_ERR lyd_value_validate_incomplete(const struct ly_ctx *ctx, const struct lysc_type *type, struct lyd_value *val, |
| 326 | const struct lyd_node *ctx_node, const struct lyd_node *tree, enum LY_VLOG_ELEM log_elem_type, const void *log_elem); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 327 | |
Michal Vasko | f937cfe | 2020-08-03 16:07:12 +0200 | [diff] [blame] | 328 | /* generic function lys_value_validate */ |
| 329 | LY_ERR _lys_value_validate(const struct ly_ctx *ctx, const struct lysc_node *node, const char *value, size_t value_len, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 330 | LY_PREFIX_FORMAT format, void *prefix_data); |
Michal Vasko | f937cfe | 2020-08-03 16:07:12 +0200 | [diff] [blame] | 331 | |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 332 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 333 | * @defgroup datahash Data nodes hash manipulation |
| 334 | * @ingroup datatree |
| 335 | */ |
| 336 | |
| 337 | /** |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 338 | * @brief Generate hash for the node. |
| 339 | * |
| 340 | * @param[in] node Data node to (re)generate hash value. |
| 341 | * @return LY_ERR value. |
| 342 | */ |
| 343 | LY_ERR lyd_hash(struct lyd_node *node); |
| 344 | |
| 345 | /** |
| 346 | * @brief Insert hash of the node into the hash table of its parent. |
| 347 | * |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 348 | * @param[in] node Data node which hash will be inserted into the ::lyd_node_inner.children_ht hash table of its parent. |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 349 | * @return LY_ERR value. |
| 350 | */ |
| 351 | LY_ERR lyd_insert_hash(struct lyd_node *node); |
| 352 | |
| 353 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 354 | * @brief Maintain node's parent's children hash table when unlinking the node. |
| 355 | * |
| 356 | * When completely freeing data tree, it is expected to free the parent's children hash table first, at once. |
| 357 | * |
| 358 | * @param[in] node The data node being unlinked from its parent. |
| 359 | */ |
| 360 | void lyd_unlink_hash(struct lyd_node *node); |
| 361 | |
| 362 | /** @} datahash */ |
| 363 | |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 364 | /** |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 365 | * @brief Iterate over implemented modules for functions that accept specific modules or the whole context. |
| 366 | * |
| 367 | * @param[in] tree Data tree. |
Michal Vasko | 26e8001 | 2020-07-08 10:55:46 +0200 | [diff] [blame] | 368 | * @param[in] module Selected module, NULL for all. |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 369 | * @param[in] ctx Context, NULL for selected modules. |
| 370 | * @param[in,out] i Iterator, set to 0 on first call. |
| 371 | * @param[out] first First sibling of the returned module. |
| 372 | * @return Next module. |
| 373 | * @return NULL if all modules were traversed. |
| 374 | */ |
Michal Vasko | 26e8001 | 2020-07-08 10:55:46 +0200 | [diff] [blame] | 375 | const struct lys_module *lyd_mod_next_module(struct lyd_node *tree, const struct lys_module *module, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 376 | const struct ly_ctx *ctx, uint32_t *i, struct lyd_node **first); |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 377 | |
| 378 | /** |
| 379 | * @brief Iterate over modules for functions that want to traverse all the top-level data. |
| 380 | * |
| 381 | * @param[in,out] next Pointer to the next module data, set to first top-level sibling on first call. |
| 382 | * @param[out] first First sibling of the returned module. |
| 383 | * @return Next module. |
| 384 | * @return NULL if all modules were traversed. |
| 385 | */ |
| 386 | const struct lys_module *lyd_data_next_module(struct lyd_node **next, struct lyd_node **first); |
| 387 | |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 388 | /** |
| 389 | * @brief Check that a list has all its keys. |
| 390 | * |
| 391 | * @param[in] node List to check. |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 392 | * @return LY_SUCCESS on success. |
| 393 | * @return LY_ENOT on a missing key. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 394 | */ |
| 395 | LY_ERR lyd_parse_check_keys(struct lyd_node *node); |
| 396 | |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 397 | /** |
| 398 | * @brief Set data flags for a newly parsed node. |
| 399 | * |
| 400 | * @param[in] node Node to use. |
| 401 | * @param[in] when_check Set of nodes with unresolved when. |
| 402 | * @param[in,out] meta Node metadata, may be removed from. |
| 403 | * @param[in] options Parse options. |
| 404 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 405 | void lyd_parse_set_data_flags(struct lyd_node *node, struct ly_set *when_check, struct lyd_meta **meta, uint32_t options); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 406 | |
| 407 | /** |
| 408 | * @brief Free value prefixes. |
| 409 | * |
| 410 | * @param[in] ctx libyang context. |
| 411 | * @param[in] val_prefis Value prefixes to free, sized array (@ref sizedarrays). |
| 412 | */ |
| 413 | void ly_free_val_prefs(const struct ly_ctx *ctx, struct ly_prefix *val_prefs); |
| 414 | |
Michal Vasko | d59035b | 2020-07-08 12:00:06 +0200 | [diff] [blame] | 415 | /** |
| 416 | * @brief Append all list key predicates to path. |
| 417 | * |
| 418 | * @param[in] node Node with keys to print. |
| 419 | * @param[in,out] buffer Buffer to print to. |
| 420 | * @param[in,out] buflen Current buffer length. |
| 421 | * @param[in,out] bufused Current number of characters used in @p buffer. |
| 422 | * @param[in] is_static Whether buffer is static or can be reallocated. |
| 423 | * @return LY_ERR |
| 424 | */ |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 425 | LY_ERR lyd_path_list_predicate(const struct lyd_node *node, char **buffer, size_t *buflen, size_t *bufused, ly_bool is_static); |
Michal Vasko | d59035b | 2020-07-08 12:00:06 +0200 | [diff] [blame] | 426 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 427 | #endif /* LY_TREE_DATA_INTERNAL_H_ */ |