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 | f13b87b | 2020-12-01 22:02:17 +0100 | [diff] [blame] | 29 | #define LY_XML_SUFFIX ".xml" |
| 30 | #define LY_XML_SUFFIX_LEN 4 |
| 31 | #define LY_JSON_SUFFIX ".json" |
| 32 | #define LY_JSON_SUFFIX_LEN 5 |
| 33 | #define LY_LYB_SUFFIX ".lyb" |
| 34 | #define LY_LYB_SUFFIX_LEN 4 |
| 35 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 36 | /** |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 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 | d3bb12f | 2020-12-04 14:33:09 +0100 | [diff] [blame] | 56 | * @brief Check whether a node to be deleted is the root node, move it if it is. |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 57 | * |
Michal Vasko | d3bb12f | 2020-12-04 14:33:09 +0100 | [diff] [blame] | 58 | * @param[in] root Root sibling. |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 59 | * @param[in] to_del Node to be deleted. |
Michal Vasko | d3bb12f | 2020-12-04 14:33:09 +0100 | [diff] [blame] | 60 | * @param[in] mod If set, it is expected @p tree should point to the first node of @p mod. Otherwise it will simply be |
| 61 | * the first top-level sibling. |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 62 | */ |
Michal Vasko | d3bb12f | 2020-12-04 14:33:09 +0100 | [diff] [blame] | 63 | void lyd_del_move_root(struct lyd_node **root, const struct lyd_node *to_del, const struct lys_module *mod); |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 64 | |
| 65 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 66 | * @brief Get address of a node's child pointer if any. |
| 67 | * |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 68 | * @param[in] node Node to check. |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 69 | * @return Address of the node's child member, |
| 70 | * @return NULL if there is no child pointer. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 71 | */ |
Michal Vasko | e066574 | 2021-02-11 11:08:44 +0100 | [diff] [blame] | 72 | struct lyd_node **lyd_node_child_p(struct lyd_node *node); |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 73 | |
| 74 | /** |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 75 | * @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] | 76 | * |
| 77 | * @param[in] last Last returned data node. |
| 78 | * @param[in] sibling Data node sibling to search in. |
| 79 | * @param[in,out] slast Schema last node, set to NULL for first call and do not change afterwards. |
| 80 | * May not be set if the function is used only for any suitable node existence check (such as the existence |
| 81 | * of any choice case data). |
| 82 | * @param[in] parent Schema parent of the iterated children nodes. |
| 83 | * @param[in] module Schema module of the iterated top-level nodes. |
| 84 | * @return Next matching data node, |
| 85 | * @return NULL if last data node was already returned. |
| 86 | */ |
| 87 | 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] | 88 | const struct lysc_node **slast, const struct lysc_node *parent, |
| 89 | const struct lysc_module *module); |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 90 | |
| 91 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 92 | * @brief Create a term (leaf/leaf-list) node from a string value. |
| 93 | * |
| 94 | * Hash is calculated and new node flag is set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 95 | * |
| 96 | * @param[in] schema Schema node of the new data node. |
| 97 | * @param[in] value String value to be parsed. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 98 | * @param[in] value_len Length of @p value, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 99 | * @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] | 100 | * @param[in] format Input format of @p value. |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 101 | * @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] | 102 | * @param[in] hints [Value hints](@ref lydvalhints) from the parser regarding the value type. |
| 103 | * @param[out] incomplete Whether the value needs to be resolved. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 104 | * @param[out] node Created node. |
| 105 | * @return LY_SUCCESS on success. |
| 106 | * @return LY_EINCOMPLETE in case data tree is needed to finish the validation. |
| 107 | * @return LY_ERR value if an error occurred. |
| 108 | */ |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 109 | LY_ERR lyd_create_term(const struct lysc_node *schema, const char *value, size_t value_len, ly_bool *dynamic, |
| 110 | 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] | 111 | |
| 112 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 113 | * @brief Create a term (leaf/leaf-list) node from a parsed value by duplicating it. |
| 114 | * |
| 115 | * Hash is calculated and new node flag is set. |
| 116 | * |
| 117 | * @param[in] schema Schema node of the new data node. |
| 118 | * @param[in] val Parsed value to use. |
| 119 | * @param[out] node Created node. |
| 120 | * @return LY_SUCCESS on success. |
| 121 | * @return LY_ERR value if an error occurred. |
| 122 | */ |
| 123 | LY_ERR lyd_create_term2(const struct lysc_node *schema, const struct lyd_value *val, struct lyd_node **node); |
| 124 | |
| 125 | /** |
| 126 | * @brief Create an inner (container/list/RPC/action/notification) node. |
| 127 | * |
| 128 | * Hash is calculated and new node flag is set except |
| 129 | * for list with keys, when the hash is not calculated! |
| 130 | * Also, non-presence container has its default flag set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 131 | * |
| 132 | * @param[in] schema Schema node of the new data node. |
| 133 | * @param[out] node Created node. |
| 134 | * @return LY_SUCCESS on success. |
| 135 | * @return LY_ERR value if an error occurred. |
| 136 | */ |
| 137 | LY_ERR lyd_create_inner(const struct lysc_node *schema, struct lyd_node **node); |
| 138 | |
| 139 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 140 | * @brief Create a list with all its keys (cannot be used for key-less list). |
| 141 | * |
| 142 | * Hash is calculated and new node flag is set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 143 | * |
| 144 | * @param[in] schema Schema node of the new data node. |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 145 | * @param[in] predicates Compiled key list predicates. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 146 | * @param[out] node Created node. |
| 147 | * @return LY_SUCCESS on success. |
| 148 | * @return LY_ERR value if an error occurred. |
| 149 | */ |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 150 | 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] | 151 | |
| 152 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 153 | * @brief Create an anyxml/anydata node. |
| 154 | * |
| 155 | * 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] | 156 | * |
| 157 | * @param[in] schema Schema node of the new data node. |
Michal Vasko | 366a4a1 | 2020-12-04 16:23:57 +0100 | [diff] [blame] | 158 | * @param[in] value Value of the any node. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 159 | * @param[in] value_type Value type of the value. |
Michal Vasko | 366a4a1 | 2020-12-04 16:23:57 +0100 | [diff] [blame] | 160 | * @param[in] use_value Whether to directly assign (eat) the value or duplicate it. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 161 | * @param[out] node Created node. |
| 162 | * @return LY_SUCCESS on success. |
| 163 | * @return LY_ERR value if an error occurred. |
| 164 | */ |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 165 | LY_ERR lyd_create_any(const struct lysc_node *schema, const void *value, LYD_ANYDATA_VALUETYPE value_type, |
Michal Vasko | 366a4a1 | 2020-12-04 16:23:57 +0100 | [diff] [blame] | 166 | ly_bool use_value, struct lyd_node **node); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 167 | |
| 168 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 169 | * @brief Create an opaque node. |
| 170 | * |
| 171 | * @param[in] ctx libyang context. |
| 172 | * @param[in] name Element name. |
| 173 | * @param[in] name_len Length of @p name, must be set correctly. |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 174 | * @param[in] prefix Element prefix. |
| 175 | * @param[in] pref_len Length of @p prefix, must be set correctly. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 176 | * @param[in] module_key Mandatory key to reference module, can be namespace or name. |
| 177 | * @param[in] module_key_len Length of @p module_key, must be set correctly. |
Michal Vasko | 501af03 | 2020-11-11 20:27:44 +0100 | [diff] [blame] | 178 | * @param[in] value String value to be parsed. |
| 179 | * @param[in] value_len Length of @p value, must be set correctly. |
| 180 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
| 181 | * @param[in] format Input format of @p value and @p ns. |
Radek Krejci | ec9ad60 | 2021-01-04 10:46:30 +0100 | [diff] [blame] | 182 | * @param[in] val_prefix_data Format-specific prefix data, param is spent (even in case the function fails): |
| 183 | * LY_PREF_SCHEMA - const struct lysp_module * (module used for resolving prefixes from imports) |
| 184 | * LY_PREF_SCHEMA_RESOLVED - struct lyd_value_prefix * (sized array of pairs: prefix - module) |
| 185 | * LY_PREF_XML - const struct ly_set * (set with defined namespaces stored as ::lyxml_ns) |
| 186 | * LY_PREF_JSON - NULL |
Michal Vasko | 501af03 | 2020-11-11 20:27:44 +0100 | [diff] [blame] | 187 | * @param[in] hints [Hints](@ref lydhints) from the parser regarding the node/value type. |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 188 | * @param[out] node Created node. |
| 189 | * @return LY_SUCCESS on success. |
| 190 | * @return LY_ERR value if an error occurred. |
| 191 | */ |
Michal Vasko | 501af03 | 2020-11-11 20:27:44 +0100 | [diff] [blame] | 192 | LY_ERR lyd_create_opaq(const struct ly_ctx *ctx, const char *name, size_t name_len, const char *prefix, size_t pref_len, |
| 193 | const char *module_key, size_t module_key_len, const char *value, size_t value_len, ly_bool *dynamic, |
| 194 | LY_PREFIX_FORMAT format, void *val_prefix_data, uint32_t hints, struct lyd_node **node); |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 195 | |
| 196 | /** |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 197 | * @brief Check the existence and create any non-existing implicit siblings, recursively for the created nodes. |
| 198 | * |
| 199 | * @param[in] parent Parent of the potential default values, NULL for top-level siblings. |
| 200 | * @param[in,out] first First sibling. |
| 201 | * @param[in] sparent Schema parent of the siblings, NULL if schema of @p parent can be used. |
| 202 | * @param[in] mod Module of the default values, NULL for nested siblings. |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 203 | * @param[in] node_when Optional set to add nodes with "when" conditions into. |
Radek Krejci | 4f2e3e5 | 2021-03-30 14:20:28 +0200 | [diff] [blame] | 204 | * @param[in] node_exts Optional set to add nodes and extension instances having own validation plugin callback into it. |
Michal Vasko | c43c8ab | 2021-03-05 13:32:44 +0100 | [diff] [blame] | 205 | * @param[in] node_types Optional set to add nodes with unresolved types into. |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 206 | * @param[in] impl_opts Implicit options (@ref implicitoptions). |
| 207 | * @param[in,out] diff Validation diff. |
| 208 | * @return LY_ERR value. |
| 209 | */ |
| 210 | LY_ERR lyd_new_implicit_r(struct lyd_node *parent, struct lyd_node **first, const struct lysc_node *sparent, |
Radek Krejci | 4f2e3e5 | 2021-03-30 14:20:28 +0200 | [diff] [blame] | 211 | const struct lys_module *mod, struct ly_set *node_when, struct ly_set *node_exts, struct ly_set *node_types, |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 212 | uint32_t impl_opts, struct lyd_node **diff); |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 213 | |
| 214 | /** |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 215 | * @brief Find the next node, before which to insert the new node. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 216 | * |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 217 | * @param[in] first_sibling First sibling of the nodes to consider. |
| 218 | * @param[in] new_node Node that will be inserted. |
| 219 | * @return Node to insert after. |
| 220 | * @return NULL if the new node should be first. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 221 | */ |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 222 | 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] | 223 | |
| 224 | /** |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 225 | * @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] | 226 | * |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 227 | * @param[in] parent Parent to insert into, NULL for top-level sibling. |
| 228 | * @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] | 229 | * @param[in] node Individual node (without siblings) to insert. |
| 230 | */ |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 231 | 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] | 232 | |
| 233 | /** |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 234 | * @brief Insert a metadata (last) into a parent |
| 235 | * |
| 236 | * @param[in] parent Parent of the metadata. |
| 237 | * @param[in] meta Metadata (list) to be added into the @p parent. |
Michal Vasko | 871a025 | 2020-11-11 18:35:24 +0100 | [diff] [blame] | 238 | * @param[in] clear_dflt Whether to clear dflt flag starting from @p parent, recursively all NP containers. |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 239 | */ |
Michal Vasko | 871a025 | 2020-11-11 18:35:24 +0100 | [diff] [blame] | 240 | void lyd_insert_meta(struct lyd_node *parent, struct lyd_meta *meta, ly_bool clear_dflt); |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 241 | |
| 242 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 243 | * @brief Create and insert a metadata (last) into a parent. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 244 | * |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 245 | * @param[in] parent Parent of the metadata, can be NULL. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 246 | * @param[in,out] meta Metadata list to add at its end if @p parent is NULL, returned created attribute. |
| 247 | * @param[in] mod Metadata module (with the annotation definition). |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 248 | * @param[in] name Attribute name. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 249 | * @param[in] name_len Length of @p name, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 250 | * @param[in] value String value to be parsed. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 251 | * @param[in] value_len Length of @p value, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 252 | * @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] | 253 | * @param[in] format Input format of @p value. |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 254 | * @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] | 255 | * @param[in] hints [Value hints](@ref lydvalhints) from the parser regarding the value type. |
Michal Vasko | 871a025 | 2020-11-11 18:35:24 +0100 | [diff] [blame] | 256 | * @param[in] clear_dflt Whether to clear dflt flag starting from @p parent, recursively all NP containers. |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 257 | * @param[out] incomplete Whether the value needs to be resolved. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 258 | * @return LY_SUCCESS on success. |
| 259 | * @return LY_EINCOMPLETE in case data tree is needed to finish the validation. |
| 260 | * @return LY_ERR value if an error occurred. |
| 261 | */ |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 262 | 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] | 263 | size_t name_len, const char *value, size_t value_len, ly_bool *dynamic, LY_PREFIX_FORMAT format, |
Michal Vasko | 871a025 | 2020-11-11 18:35:24 +0100 | [diff] [blame] | 264 | void *prefix_data, uint32_t hints, ly_bool clear_dlft, ly_bool *incomplete); |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 265 | |
| 266 | /** |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 267 | * @brief Insert an attribute (last) into a parent |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 268 | * |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 269 | * @param[in] parent Parent of the attributes. |
| 270 | * @param[in] attr Attribute (list) to be added into the @p parent. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 271 | */ |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 272 | void lyd_insert_attr(struct lyd_node *parent, struct lyd_attr *attr); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 273 | |
| 274 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 275 | * @brief Create and insert a generic attribute (last) into a parent. |
| 276 | * |
| 277 | * @param[in] parent Parent of the attribute, can be NULL. |
| 278 | * @param[in,out] attr Attribute list to add at its end if @p parent is NULL, returned created attribute. |
| 279 | * @param[in] ctx libyang context. |
| 280 | * @param[in] name Attribute name. |
| 281 | * @param[in] name_len Length of @p name, must be set correctly. |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 282 | * @param[in] prefix Attribute prefix. |
| 283 | * @param[in] prefix_len Attribute prefix length. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 284 | * @param[in] module_key Mandatory key to reference module, can be namespace or name. |
| 285 | * @param[in] module_key_len Length of @p module_key, must be set correctly. |
Michal Vasko | 501af03 | 2020-11-11 20:27:44 +0100 | [diff] [blame] | 286 | * @param[in] value String value to be parsed. |
| 287 | * @param[in] value_len Length of @p value, must be set correctly. |
| 288 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
| 289 | * @param[in] format Input format of @p value and @p ns. |
| 290 | * @param[in] val_prefix_data Format-specific prefix data, param is spent (even in case the function fails). |
| 291 | * @param[in] hints [Hints](@ref lydhints) from the parser regarding the node/value type. |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 292 | * @return LY_SUCCESS on success, |
| 293 | * @return LY_ERR value on error. |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 294 | */ |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 295 | LY_ERR lyd_create_attr(struct lyd_node *parent, struct lyd_attr **attr, const struct ly_ctx *ctx, const char *name, |
Michal Vasko | 501af03 | 2020-11-11 20:27:44 +0100 | [diff] [blame] | 296 | size_t name_len, const char *prefix, size_t prefix_len, const char *module_key, size_t module_key_len, |
| 297 | const char *value, size_t value_len, ly_bool *dynamic, LY_PREFIX_FORMAT format, void *val_prefix_data, uint32_t hints); |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 298 | |
| 299 | /** |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 300 | * @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] | 301 | * |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 302 | * @param[in] ctx libyang context. |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 303 | * @param[in,out] val Storage for the value. |
| 304 | * @param[in] type Type of the value. |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 305 | * @param[in] value String value to be parsed, must not be NULL. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 306 | * @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] | 307 | * @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] | 308 | * @param[in] format Input format of @p value. |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 309 | * @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] | 310 | * @param[in] hints [Value hints](@ref lydvalhints) from the parser. |
| 311 | * @param[in] ctx_node Context schema node. |
| 312 | * @param[out] incomplete Optional, set if the value also needs to be resolved. |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 313 | * @return LY_SUCCESS on success, |
| 314 | * @return LY_ERR value on error. |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 315 | */ |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 316 | LY_ERR lyd_value_store(const struct ly_ctx *ctx, struct lyd_value *val, const struct lysc_type *type, const char *value, |
| 317 | size_t value_len, ly_bool *dynamic, LY_PREFIX_FORMAT format, void *prefix_data, uint32_t hints, |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 318 | const struct lysc_node *ctx_node, ly_bool *incomplete); |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 319 | |
| 320 | /** |
| 321 | * @brief Validate previously incompletely stored value. |
| 322 | * |
| 323 | * @param[in] ctx libyang context. |
| 324 | * @param[in] type Schema type of the value (not the stored one, but the original one). |
| 325 | * @param[in,out] val Stored value to resolve. |
| 326 | * @param[in] ctx_node Context node for the resolution. |
| 327 | * @param[in] tree Data tree for the resolution. |
Michal Vasko | feca4fb | 2020-10-05 08:58:40 +0200 | [diff] [blame] | 328 | * @return LY_SUCCESS on success, |
| 329 | * @return LY_ERR value on error. |
| 330 | */ |
| 331 | LY_ERR lyd_value_validate_incomplete(const struct ly_ctx *ctx, const struct lysc_type *type, struct lyd_value *val, |
Radek Krejci | 2efc45b | 2020-12-22 16:25:44 +0100 | [diff] [blame] | 332 | const struct lyd_node *ctx_node, const struct lyd_node *tree); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 333 | |
Michal Vasko | f937cfe | 2020-08-03 16:07:12 +0200 | [diff] [blame] | 334 | /* generic function lys_value_validate */ |
| 335 | 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] | 336 | LY_PREFIX_FORMAT format, void *prefix_data); |
Michal Vasko | f937cfe | 2020-08-03 16:07:12 +0200 | [diff] [blame] | 337 | |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 338 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 339 | * @defgroup datahash Data nodes hash manipulation |
| 340 | * @ingroup datatree |
| 341 | */ |
| 342 | |
| 343 | /** |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 344 | * @brief Generate hash for the node. |
| 345 | * |
| 346 | * @param[in] node Data node to (re)generate hash value. |
| 347 | * @return LY_ERR value. |
| 348 | */ |
| 349 | LY_ERR lyd_hash(struct lyd_node *node); |
| 350 | |
| 351 | /** |
| 352 | * @brief Insert hash of the node into the hash table of its parent. |
| 353 | * |
Radek Krejci | 8678fa4 | 2020-08-18 16:07:28 +0200 | [diff] [blame] | 354 | * @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] | 355 | * @return LY_ERR value. |
| 356 | */ |
| 357 | LY_ERR lyd_insert_hash(struct lyd_node *node); |
| 358 | |
| 359 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 360 | * @brief Maintain node's parent's children hash table when unlinking the node. |
| 361 | * |
| 362 | * When completely freeing data tree, it is expected to free the parent's children hash table first, at once. |
| 363 | * |
| 364 | * @param[in] node The data node being unlinked from its parent. |
| 365 | */ |
| 366 | void lyd_unlink_hash(struct lyd_node *node); |
| 367 | |
| 368 | /** @} datahash */ |
| 369 | |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 370 | /** |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 371 | * @brief Iterate over implemented modules for functions that accept specific modules or the whole context. |
| 372 | * |
| 373 | * @param[in] tree Data tree. |
Michal Vasko | 26e8001 | 2020-07-08 10:55:46 +0200 | [diff] [blame] | 374 | * @param[in] module Selected module, NULL for all. |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 375 | * @param[in] ctx Context, NULL for selected modules. |
| 376 | * @param[in,out] i Iterator, set to 0 on first call. |
| 377 | * @param[out] first First sibling of the returned module. |
| 378 | * @return Next module. |
| 379 | * @return NULL if all modules were traversed. |
| 380 | */ |
Michal Vasko | 26e8001 | 2020-07-08 10:55:46 +0200 | [diff] [blame] | 381 | 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] | 382 | const struct ly_ctx *ctx, uint32_t *i, struct lyd_node **first); |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 383 | |
| 384 | /** |
| 385 | * @brief Iterate over modules for functions that want to traverse all the top-level data. |
| 386 | * |
| 387 | * @param[in,out] next Pointer to the next module data, set to first top-level sibling on first call. |
| 388 | * @param[out] first First sibling of the returned module. |
| 389 | * @return Next module. |
| 390 | * @return NULL if all modules were traversed. |
| 391 | */ |
| 392 | const struct lys_module *lyd_data_next_module(struct lyd_node **next, struct lyd_node **first); |
| 393 | |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 394 | /** |
| 395 | * @brief Check that a list has all its keys. |
| 396 | * |
| 397 | * @param[in] node List to check. |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 398 | * @return LY_SUCCESS on success. |
| 399 | * @return LY_ENOT on a missing key. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 400 | */ |
| 401 | LY_ERR lyd_parse_check_keys(struct lyd_node *node); |
| 402 | |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 403 | /** |
| 404 | * @brief Set data flags for a newly parsed node. |
| 405 | * |
| 406 | * @param[in] node Node to use. |
Radek Krejci | 4f2e3e5 | 2021-03-30 14:20:28 +0200 | [diff] [blame] | 407 | * @param[in,out] when_check Set of nodes with unresolved when. |
| 408 | * @param[in,out] exts_check Set of nodes and their extension instances if they have own validation callback. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 409 | * @param[in,out] meta Node metadata, may be removed from. |
| 410 | * @param[in] options Parse options. |
| 411 | */ |
Radek Krejci | 4f2e3e5 | 2021-03-30 14:20:28 +0200 | [diff] [blame] | 412 | void lyd_parse_set_data_flags(struct lyd_node *node, struct ly_set *when_check, struct ly_set *exts_check, |
| 413 | struct lyd_meta **meta, uint32_t options); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 414 | |
| 415 | /** |
Michal Vasko | d59035b | 2020-07-08 12:00:06 +0200 | [diff] [blame] | 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 | |
Michal Vasko | 6b5cb2a | 2020-11-11 19:11:21 +0100 | [diff] [blame] | 427 | /** |
| 428 | * @brief Free stored prefix data. |
| 429 | * |
| 430 | * @param[in] format Format of the prefixes. |
Radek Krejci | ec9ad60 | 2021-01-04 10:46:30 +0100 | [diff] [blame] | 431 | * @param[in] prefix_data Format-specific data to free: |
| 432 | * LY_PREF_SCHEMA - const struct lysp_module * (module used for resolving prefixes from imports) |
| 433 | * LY_PREF_SCHEMA_RESOLVED - struct lyd_value_prefix * (sized array of pairs: prefix - module) |
| 434 | * LY_PREF_XML - const struct ly_set * (set with defined namespaces stored as ::lyxml_ns) |
| 435 | * LY_PREF_JSON - NULL |
Michal Vasko | 6b5cb2a | 2020-11-11 19:11:21 +0100 | [diff] [blame] | 436 | */ |
| 437 | void ly_free_prefix_data(LY_PREFIX_FORMAT format, void *prefix_data); |
| 438 | |
| 439 | /** |
| 440 | * @brief Duplicate prefix data. |
| 441 | * |
| 442 | * @param[in] ctx libyang context. |
| 443 | * @param[in] format Format of the prefixes in the value. |
| 444 | * @param[in] prefix_data Prefix data to duplicate. |
| 445 | * @param[out] prefix_data_p Duplicated prefix data. |
| 446 | * @return LY_ERR value. |
| 447 | */ |
| 448 | LY_ERR ly_dup_prefix_data(const struct ly_ctx *ctx, LY_PREFIX_FORMAT format, const void *prefix_data, void **prefix_data_p); |
| 449 | |
| 450 | /** |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 451 | * @brief Store used prefixes in a string. |
| 452 | * |
| 453 | * If @p prefix_data_p are non-NULL, they are treated as valid according to the @p format_p and new possible |
| 454 | * prefixes are simply added. This way it is possible to store prefix data for several strings together. |
Michal Vasko | 6b5cb2a | 2020-11-11 19:11:21 +0100 | [diff] [blame] | 455 | * |
| 456 | * @param[in] ctx libyang context. |
| 457 | * @param[in] value Value string to be parsed. |
| 458 | * @param[in] value_len Length of the @p value string. |
| 459 | * @param[in] format Format of the prefixes in the value. |
| 460 | * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix). |
Michal Vasko | fc2cd07 | 2021-02-24 13:17:17 +0100 | [diff] [blame] | 461 | * @param[in,out] format_p Resulting format of the prefixes. |
| 462 | * @param[in,out] prefix_data_p Resulting prefix data for the value in format @p format_p. |
Michal Vasko | 6b5cb2a | 2020-11-11 19:11:21 +0100 | [diff] [blame] | 463 | * @return LY_ERR value. |
| 464 | */ |
| 465 | LY_ERR ly_store_prefix_data(const struct ly_ctx *ctx, const char *value, size_t value_len, LY_PREFIX_FORMAT format, |
Radek Krejci | d64d646 | 2021-03-16 15:58:00 +0100 | [diff] [blame] | 466 | const void *prefix_data, LY_PREFIX_FORMAT *format_p, void **prefix_data_p); |
Michal Vasko | 6b5cb2a | 2020-11-11 19:11:21 +0100 | [diff] [blame] | 467 | |
Michal Vasko | 7ed1fcb | 2020-12-03 14:15:22 +0100 | [diff] [blame] | 468 | /** |
| 469 | * @brief Get string name of the format. |
| 470 | * |
| 471 | * @param[in] format Format whose name to get. |
| 472 | * @return Format string name. |
| 473 | */ |
| 474 | const char *ly_format2str(LY_PREFIX_FORMAT format); |
| 475 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 476 | #endif /* LY_TREE_DATA_INTERNAL_H_ */ |