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 | /** |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 73 | * @brief Just like lys_getnext() but iterates over all data instances of the schema nodes. |
| 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. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 98 | * @param[in] value_hint [Hint options](@ref lydvalueparseopts) from the parser regarding the value type. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 99 | * @param[in] format Input format of @p value. |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 100 | * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix). |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 101 | * @param[out] node Created node. |
| 102 | * @return LY_SUCCESS on success. |
| 103 | * @return LY_EINCOMPLETE in case data tree is needed to finish the validation. |
| 104 | * @return LY_ERR value if an error occurred. |
| 105 | */ |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 106 | LY_ERR lyd_create_term(const struct lysc_node *schema, const char *value, size_t value_len, ly_bool *dynamic, uint32_t value_hint, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 107 | LY_PREFIX_FORMAT format, void *prefix_data, struct lyd_node **node); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 108 | |
| 109 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 110 | * @brief Create a term (leaf/leaf-list) node from a parsed value by duplicating it. |
| 111 | * |
| 112 | * Hash is calculated and new node flag is set. |
| 113 | * |
| 114 | * @param[in] schema Schema node of the new data node. |
| 115 | * @param[in] val Parsed value to use. |
| 116 | * @param[out] node Created node. |
| 117 | * @return LY_SUCCESS on success. |
| 118 | * @return LY_ERR value if an error occurred. |
| 119 | */ |
| 120 | LY_ERR lyd_create_term2(const struct lysc_node *schema, const struct lyd_value *val, struct lyd_node **node); |
| 121 | |
| 122 | /** |
| 123 | * @brief Create an inner (container/list/RPC/action/notification) node. |
| 124 | * |
| 125 | * Hash is calculated and new node flag is set except |
| 126 | * for list with keys, when the hash is not calculated! |
| 127 | * Also, non-presence container has its default flag set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 128 | * |
| 129 | * @param[in] schema Schema node of the new data node. |
| 130 | * @param[out] node Created node. |
| 131 | * @return LY_SUCCESS on success. |
| 132 | * @return LY_ERR value if an error occurred. |
| 133 | */ |
| 134 | LY_ERR lyd_create_inner(const struct lysc_node *schema, struct lyd_node **node); |
| 135 | |
| 136 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 137 | * @brief Create a list with all its keys (cannot be used for key-less list). |
| 138 | * |
| 139 | * Hash is calculated and new node flag is set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 140 | * |
| 141 | * @param[in] schema Schema node of the new data node. |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 142 | * @param[in] predicates Compiled key list predicates. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 143 | * @param[out] node Created node. |
| 144 | * @return LY_SUCCESS on success. |
| 145 | * @return LY_ERR value if an error occurred. |
| 146 | */ |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 147 | 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] | 148 | |
| 149 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 150 | * @brief Create an anyxml/anydata node. |
| 151 | * |
| 152 | * 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] | 153 | * |
| 154 | * @param[in] schema Schema node of the new data node. |
| 155 | * @param[in] value Value of the any node, is directly assigned into the data node. |
| 156 | * @param[in] value_type Value type of the value. |
| 157 | * @param[out] node Created node. |
| 158 | * @return LY_SUCCESS on success. |
| 159 | * @return LY_ERR value if an error occurred. |
| 160 | */ |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 161 | 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] | 162 | struct lyd_node **node); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 163 | |
| 164 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 165 | * @brief Create an opaque node. |
| 166 | * |
| 167 | * @param[in] ctx libyang context. |
| 168 | * @param[in] name Element name. |
| 169 | * @param[in] name_len Length of @p name, must be set correctly. |
| 170 | * @param[in] value String value to be parsed. |
| 171 | * @param[in] value_len Length of @p value, must be set correctly. |
| 172 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 173 | * @param[in] value_hint [Value hint](@ref lydvalueparseopts) from the parser regarding the value type. |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 174 | * @param[in] format Input format of @p value and @p ns. |
Radek Krejci | d46e46a | 2020-09-15 14:22:42 +0200 | [diff] [blame] | 175 | * @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] | 176 | * @param[in] prefix Element prefix. |
| 177 | * @param[in] pref_len Length of @p prefix, must be set correctly. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 178 | * @param[in] module_key Mandatory key to reference module, can be namespace or name. |
| 179 | * @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] | 180 | * @param[out] node Created node. |
| 181 | * @return LY_SUCCESS on success. |
| 182 | * @return LY_ERR value if an error occurred. |
| 183 | */ |
| 184 | LY_ERR lyd_create_opaq(const struct ly_ctx *ctx, const char *name, size_t name_len, const char *value, size_t value_len, |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 185 | ly_bool *dynamic, uint32_t value_hint, LYD_FORMAT format, struct ly_prefix *val_prefs, const char *prefix, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 186 | 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] | 187 | |
| 188 | /** |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 189 | * @brief Check the existence and create any non-existing implicit siblings, recursively for the created nodes. |
| 190 | * |
| 191 | * @param[in] parent Parent of the potential default values, NULL for top-level siblings. |
| 192 | * @param[in,out] first First sibling. |
| 193 | * @param[in] sparent Schema parent of the siblings, NULL if schema of @p parent can be used. |
| 194 | * @param[in] mod Module of the default values, NULL for nested siblings. |
| 195 | * @param[in] node_types Optional set to add nodes with unresolved types into. |
| 196 | * @param[in] node_when Optional set to add nodes with "when" conditions into. |
| 197 | * @param[in] impl_opts Implicit options (@ref implicitoptions). |
| 198 | * @param[in,out] diff Validation diff. |
| 199 | * @return LY_ERR value. |
| 200 | */ |
| 201 | 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] | 202 | 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] | 203 | uint32_t impl_opts, struct lyd_node **diff); |
Michal Vasko | a6669ba | 2020-08-06 16:14:26 +0200 | [diff] [blame] | 204 | |
| 205 | /** |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 206 | * @brief Find the next node, before which to insert the new node. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 207 | * |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 208 | * @param[in] first_sibling First sibling of the nodes to consider. |
| 209 | * @param[in] new_node Node that will be inserted. |
| 210 | * @return Node to insert after. |
| 211 | * @return NULL if the new node should be first. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 212 | */ |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 213 | 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] | 214 | |
| 215 | /** |
Michal Vasko | b104f11 | 2020-07-17 09:54:54 +0200 | [diff] [blame] | 216 | * @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] | 217 | * |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 218 | * @param[in] parent Parent to insert into, NULL for top-level sibling. |
| 219 | * @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] | 220 | * @param[in] node Individual node (without siblings) to insert. |
| 221 | */ |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 222 | 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] | 223 | |
| 224 | /** |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 225 | * @brief Insert a metadata (last) into a parent |
| 226 | * |
| 227 | * @param[in] parent Parent of the metadata. |
| 228 | * @param[in] meta Metadata (list) to be added into the @p parent. |
| 229 | */ |
| 230 | void lyd_insert_meta(struct lyd_node *parent, struct lyd_meta *meta); |
| 231 | |
| 232 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 233 | * @brief Create and insert a metadata (last) into a parent. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 234 | * |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 235 | * @param[in] parent Parent of the metadata, can be NULL. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 236 | * @param[in,out] meta Metadata list to add at its end if @p parent is NULL, returned created attribute. |
| 237 | * @param[in] mod Metadata module (with the annotation definition). |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 238 | * @param[in] name Attribute name. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 239 | * @param[in] name_len Length of @p name, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 240 | * @param[in] value String value to be parsed. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 241 | * @param[in] value_len Length of @p value, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 242 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 243 | * @param[in] value_hint [Value hint](@ref lydvalueparseopts) from the parser regarding the value type. |
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 | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 246 | * @param[in] ctx_snode Context node for value resolution in schema. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 247 | * @return LY_SUCCESS on success. |
| 248 | * @return LY_EINCOMPLETE in case data tree is needed to finish the validation. |
| 249 | * @return LY_ERR value if an error occurred. |
| 250 | */ |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 251 | LY_ERR lyd_create_meta(struct lyd_node *parent, struct lyd_meta **meta, const struct lys_module *mod, const char *name, |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 252 | size_t name_len, const char *value, size_t value_len, ly_bool *dynamic, uint32_t value_hint, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 253 | LY_PREFIX_FORMAT format, void *prefix_data, const struct lysc_node *ctx_snode); |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 254 | |
| 255 | /** |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 256 | * @brief Insert an attribute (last) into a parent |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 257 | * |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 258 | * @param[in] parent Parent of the attributes. |
| 259 | * @param[in] attr Attribute (list) to be added into the @p parent. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 260 | */ |
Michal Vasko | a5da329 | 2020-08-12 13:10:50 +0200 | [diff] [blame] | 261 | void lyd_insert_attr(struct lyd_node *parent, struct lyd_attr *attr); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 262 | |
| 263 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 264 | * @brief Create and insert a generic attribute (last) into a parent. |
| 265 | * |
| 266 | * @param[in] parent Parent of the attribute, can be NULL. |
| 267 | * @param[in,out] attr Attribute list to add at its end if @p parent is NULL, returned created attribute. |
| 268 | * @param[in] ctx libyang context. |
| 269 | * @param[in] name Attribute name. |
| 270 | * @param[in] name_len Length of @p name, must be set correctly. |
| 271 | * @param[in] value String value to be parsed. |
| 272 | * @param[in] value_len Length of @p value, must be set correctly. |
| 273 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 274 | * @param[in] value_hint [Value hint](@ref lydvalueparseopts) from the parser regarding the value type. |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 275 | * @param[in] format Input format of @p value and @p ns. |
Radek Krejci | d46e46a | 2020-09-15 14:22:42 +0200 | [diff] [blame] | 276 | * @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] | 277 | * @param[in] prefix Attribute prefix. |
| 278 | * @param[in] prefix_len Attribute prefix length. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 279 | * @param[in] module_key Mandatory key to reference module, can be namespace or name. |
| 280 | * @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] | 281 | * @return LY_SUCCESS on success. |
| 282 | * @return LY_ERR value if an error occurred. |
| 283 | */ |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 284 | LY_ERR lyd_create_attr(struct lyd_node *parent, struct lyd_attr **attr, const struct ly_ctx *ctx, const char *name, |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 285 | size_t name_len, const char *value, size_t value_len, ly_bool *dynamic, uint32_t value_hint, LYD_FORMAT format, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 286 | 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] | 287 | |
| 288 | /** |
| 289 | * @defgroup lydvalueparseopts Hint options for type plugin callbacks from the data parsers. |
| 290 | * |
| 291 | * Options applicable to ly_value_parse() |
| 292 | * @{ |
| 293 | */ |
| 294 | #define LYD_VALUE_PARSE_ISSTRING LY_TYPE_OPTS_ISSTRING /**< The input value is supposed to be a string. */ |
| 295 | #define LYD_VALUE_PARSE_ISNUMBER LY_TYPE_OPTS_ISNUMBER /**< The input value is supposed to be a number. */ |
| 296 | #define LYD_VALUE_PARSE_ISBOOLEAN LY_TYPE_OPTS_ISBOOLEAN /**< The input value is supposed to be a boolean. */ |
| 297 | #define LYD_VALUE_PARSE_ISEMPTY LY_TYPE_OPTS_ISEMPTY /**< The input value is supposed to be empty type. */ |
| 298 | |
| 299 | /** @} lydvalueparseopts */ |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 300 | |
| 301 | /** |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 302 | * @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] | 303 | * |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 304 | * @param[in] node Data node for the @p value. |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +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. |
Radek Krejci | 3c9758d | 2019-07-11 16:49:10 +0200 | [diff] [blame] | 308 | * @param[in] second Flag for the second call after returning LY_EINCOMPLETE |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 309 | * @param[in] value_hint [Value hint](@ref lydvalueparseopts) from the parser. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 310 | * @param[in] format Input format of @p value. |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 311 | * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix). |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 312 | * @param[in] tree Data tree (e.g. when validating RPC/Notification) where the required |
Radek Krejci | e553e6d | 2019-06-07 15:33:18 +0200 | [diff] [blame] | 313 | * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete, |
| 314 | * then LY_EINCOMPLETE can be returned. |
| 315 | * @return LY_SUCCESS on success |
| 316 | * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation. |
| 317 | * @return LY_ERR value if an error occurred. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 318 | */ |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 319 | LY_ERR lyd_value_parse(struct lyd_node_term *node, const char *value, size_t value_len, ly_bool *dynamic, ly_bool second, |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 320 | uint32_t value_hint, LY_PREFIX_FORMAT format, void *prefix_data, const struct lyd_node *tree); |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 321 | |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 322 | /* similar to lyd_value_parse except can be used just to store the value, hence does also not support a second call */ |
| 323 | LY_ERR lyd_value_store(struct lyd_value *val, const struct lysc_node *schema, const char *value, size_t value_len, |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 324 | ly_bool *dynamic, LY_PREFIX_FORMAT format, void *prefix_data); |
Michal Vasko | 004d315 | 2020-06-11 19:59:22 +0200 | [diff] [blame] | 325 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 326 | /** |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 327 | * @brief Validate, canonize and store the given @p value into the metadata according to the annotation type's rules. |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 328 | * |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 329 | * @param[in] ctx libyang context. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 330 | * @param[in] meta Metadata for the @p value. |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 331 | * @param[in] value String value to be parsed, must not be NULL. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 332 | * @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] | 333 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 334 | * @param[in] second Flag for the second call after returning LY_EINCOMPLETE |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 335 | * @param[in] value_hint [Value hint](@ref lydvalueparseopts) from the parser. |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 336 | * @param[in] format Input format of the data. |
Michal Vasko | c8a230d | 2020-08-14 12:17:10 +0200 | [diff] [blame] | 337 | * @param[in] prefix_data Format-specific data for resolving any prefixes (see ::ly_resolve_prefix). |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 338 | * @param[in] ctx_snode Context node for value resolution in schema. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 339 | * @param[in] tree Data tree (e.g. when validating RPC/Notification) where the required |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 340 | * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete, |
| 341 | * then LY_EINCOMPLETE can be returned. |
| 342 | * @return LY_SUCCESS on success |
| 343 | * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation. |
| 344 | * @return LY_ERR value if an error occurred. |
| 345 | */ |
Michal Vasko | 4158635 | 2020-07-13 13:54:25 +0200 | [diff] [blame] | 346 | LY_ERR lyd_value_parse_meta(const struct ly_ctx *ctx, struct lyd_meta *meta, const char *value, size_t value_len, |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 347 | ly_bool *dynamic, ly_bool second, uint32_t value_hint, LY_PREFIX_FORMAT format, void *prefix_data, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 348 | const struct lysc_node *ctx_snode, const struct lyd_node *tree); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 349 | |
Michal Vasko | f937cfe | 2020-08-03 16:07:12 +0200 | [diff] [blame] | 350 | /* generic function lys_value_validate */ |
| 351 | 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] | 352 | LY_PREFIX_FORMAT format, void *prefix_data); |
Michal Vasko | f937cfe | 2020-08-03 16:07:12 +0200 | [diff] [blame] | 353 | |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 354 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 355 | * @brief Parse XML string as YANG data tree. |
| 356 | * |
| 357 | * @param[in] ctx libyang context |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 358 | * @param[in] in Input structure. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 359 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 360 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 361 | * @param[out] tree_p Parsed data tree. Note that NULL can be a valid result. |
| 362 | * @param[out] lydctx_p Data parser context to finish validation. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 363 | * @return LY_ERR value. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 364 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 365 | LY_ERR lyd_parse_xml_data(const struct ly_ctx *ctx, struct ly_in *in, uint32_t parse_options, uint32_t validate_options, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 366 | struct lyd_node **tree_p, struct lyd_ctx **lydctx_p); |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 367 | |
| 368 | /** |
| 369 | * @brief Parse XML string as YANG RPC/action invocation. |
| 370 | * |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 371 | * Optional \<rpc\> envelope element is accepted if present. It is [checked](https://tools.ietf.org/html/rfc6241#section-4.1) and all |
| 372 | * its XML attributes are parsed. As a content of the enveloper, an RPC data or \<action\> envelope element is expected. The \<action\> envelope element is |
| 373 | * also [checked](https://tools.ietf.org/html/rfc7950#section-7.15.2) and then an action data is expected as a content of this envelope. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 374 | * |
| 375 | * @param[in] ctx libyang context. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 376 | * @param[in] in Input structure. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 377 | * @param[out] tree_p Parsed full RPC/action tree. |
| 378 | * @param[out] op_p Optional pointer to the actual operation. Useful mainly for action. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 379 | * @return LY_ERR value. |
| 380 | */ |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 381 | LY_ERR lyd_parse_xml_rpc(const struct ly_ctx *ctx, struct ly_in *in, struct lyd_node **tree_p, struct lyd_node **op_p); |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 382 | |
| 383 | /** |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 384 | * @brief Parse XML string as YANG notification. |
| 385 | * |
| 386 | * Optional \<notification\> envelope element, if present, is [checked](https://tools.ietf.org/html/rfc5277#page-25) |
| 387 | * and parsed. Specifically, its namespace and the child \<eventTime\> element and its value. |
| 388 | * |
| 389 | * @param[in] ctx libyang context. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 390 | * @param[in] in Input structure. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 391 | * @param[out] tree_p Parsed full notification tree. |
| 392 | * @param[out] op_p Optional pointer to the actual notification. Useful mainly for nested notifications. |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 393 | * @return LY_ERR value. |
| 394 | */ |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 395 | LY_ERR lyd_parse_xml_notif(const struct ly_ctx *ctx, struct ly_in *in, struct lyd_node **tree_p, struct lyd_node **ntf_p); |
Michal Vasko | a8edff0 | 2020-03-27 14:47:01 +0100 | [diff] [blame] | 396 | |
| 397 | /** |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 398 | * @brief Parse XML string as YANG RPC/action reply. |
| 399 | * |
| 400 | * Optional \<rpc-reply\> envelope element, if present, is [checked](https://tools.ietf.org/html/rfc6241#section-4.2) |
| 401 | * and all its XML attributes parsed. |
| 402 | * |
| 403 | * @param[in] request Data tree of the RPC/action request. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 404 | * @param[in] in Input structure. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 405 | * @param[out] tree_p Parsed full reply tree. It always includes duplicated operation and parents of the @p request. |
| 406 | * @param[out] op_p Optional pointer to the reply operation. Useful mainly for action. |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 407 | * @return LY_ERR value. |
| 408 | */ |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 409 | LY_ERR lyd_parse_xml_reply(const struct lyd_node *request, struct ly_in *in, struct lyd_node **tree_p, struct lyd_node **op_p); |
| 410 | |
| 411 | /** |
| 412 | * @brief Parse JSON string as YANG data tree. |
| 413 | * |
| 414 | * @param[in] ctx libyang context |
| 415 | * @param[in] in Input structure. |
| 416 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 417 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
| 418 | * @param[out] tree_p Parsed data tree. Note that NULL can be a valid result. |
| 419 | * @param[out] lydctx_p Data parser context to finish validation. |
| 420 | * @return LY_ERR value. |
| 421 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 422 | LY_ERR lyd_parse_json_data(const struct ly_ctx *ctx, struct ly_in *in, uint32_t parse_options, uint32_t validate_options, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 423 | struct lyd_node **tree_p, struct lyd_ctx **lydctx_p); |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 424 | |
| 425 | /** |
| 426 | * @brief Parse JSON string as YANG notification. |
| 427 | * |
| 428 | * Optional top-level "notification" envelope object, if present, is [checked](https://tools.ietf.org/html/rfc5277#page-25) |
| 429 | * and parsed. Specifically the child "eventTime" member and its value. |
| 430 | * |
| 431 | * @param[in] ctx libyang context. |
| 432 | * @param[in] in Input structure. |
| 433 | * @param[out] tree_p Parsed full notification tree. |
| 434 | * @param[out] ntf_p Optional pointer to the actual notification. Useful mainly for nested notifications. |
| 435 | * @return LY_ERR value. |
| 436 | */ |
| 437 | LY_ERR lyd_parse_json_notif(const struct ly_ctx *ctx, struct ly_in *in, struct lyd_node **tree_p, struct lyd_node **ntf_p); |
| 438 | |
| 439 | /** |
| 440 | * @brief Parse JSON string as YANG RPC/action invocation. |
| 441 | * |
| 442 | * Optional top-level "rpc" envelope object, if present is is [checked](https://tools.ietf.org/html/rfc6241#section-4.1) and the parser |
| 443 | * goes inside for the content, which is an RPC data or "action" envelope objects. The "action" envelope object is |
| 444 | * also [checked](https://tools.ietf.org/html/rfc7950#section-7.15.2) and then an action data is expected as a content of this envelope. |
| 445 | * |
| 446 | * @param[in] ctx libyang context. |
| 447 | * @param[in] in Input structure. |
| 448 | * @param[out] tree_p Parsed full RPC/action tree. |
| 449 | * @param[out] op_p Optional pointer to the actual operation. Useful mainly for action. |
| 450 | * @return LY_ERR value. |
| 451 | */ |
| 452 | LY_ERR lyd_parse_json_rpc(const struct ly_ctx *ctx, struct ly_in *in, struct lyd_node **tree_p, struct lyd_node **op_p); |
| 453 | |
| 454 | /** |
| 455 | * @brief Parse JSON string as YANG RPC/action reply. |
| 456 | * |
| 457 | * Optional "rpc-reply" envelope object, if present, is [checked](https://tools.ietf.org/html/rfc6241#section-4.2). |
| 458 | * |
| 459 | * @param[in] request Data tree of the RPC/action request. |
| 460 | * @param[in] in Input structure. |
| 461 | * @param[out] tree_p Parsed full reply tree. It always includes duplicated operation and parents of the @p request. |
| 462 | * @param[out] op_p Optional pointer to the reply operation. Useful mainly for action. |
| 463 | * @return LY_ERR value. |
| 464 | */ |
| 465 | LY_ERR lyd_parse_json_reply(const struct lyd_node *request, struct ly_in *in, struct lyd_node **tree_p, struct lyd_node **op_p); |
Michal Vasko | 1ce933a | 2020-03-30 12:38:22 +0200 | [diff] [blame] | 466 | |
| 467 | /** |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 468 | * @brief Parse binary data as YANG data tree. |
| 469 | * |
| 470 | * @param[in] ctx libyang context |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 471 | * @param[in] in Input structure. |
Radek Krejci | 7931b19 | 2020-06-25 17:05:03 +0200 | [diff] [blame] | 472 | * @param[in] parse_options Options for parser, see @ref dataparseroptions. |
| 473 | * @param[in] validate_options Options for the validation phase, see @ref datavalidationoptions. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 474 | * @param[out] tree_p Parsed data tree. Note that NULL can be a valid result. |
| 475 | * @param[out] lydctx_p Data parser context to finish validation. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 476 | * @return LY_ERR value. |
| 477 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 478 | LY_ERR lyd_parse_lyb_data(const struct ly_ctx *ctx, struct ly_in *in, uint32_t parse_options, uint32_t validate_options, |
Radek Krejci | 0f96988 | 2020-08-21 16:56:47 +0200 | [diff] [blame] | 479 | struct lyd_node **tree_p, struct lyd_ctx **lydctx_p); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 480 | |
| 481 | /** |
| 482 | * @brief Parse binary data as YANG RPC/action invocation. |
| 483 | * |
| 484 | * @param[in] ctx libyang context. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 485 | * @param[in] in Input structure. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 486 | * @param[out] tree_p Parsed full RPC/action tree. |
| 487 | * @param[out] op_p Optional pointer to the actual operation. Useful mainly for action. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 488 | * @return LY_ERR value. |
| 489 | */ |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 490 | LY_ERR lyd_parse_lyb_rpc(const struct ly_ctx *ctx, struct ly_in *in, struct lyd_node **tree_p, struct lyd_node **op_p); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 491 | |
| 492 | /** |
| 493 | * @brief Parse binary data as YANG notification. |
| 494 | * |
| 495 | * @param[in] ctx libyang context. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 496 | * @param[in] in Input structure. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 497 | * @param[out] tree_p Parsed full notification tree. |
| 498 | * @param[out] ntf_p Optional pointer to the actual notification. Useful mainly for nested notifications. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 499 | * @return LY_ERR value. |
| 500 | */ |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 501 | LY_ERR lyd_parse_lyb_notif(const struct ly_ctx *ctx, struct ly_in *in, struct lyd_node **tree_p, struct lyd_node **ntf_p); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 502 | |
| 503 | /** |
| 504 | * @brief Parse binary data as YANG RPC/action reply. |
| 505 | * |
| 506 | * @param[in] request Data tree of the RPC/action request. |
Michal Vasko | 63f3d84 | 2020-07-08 10:10:14 +0200 | [diff] [blame] | 507 | * @param[in] in Input structure. |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 508 | * @param[out] tree_p Parsed full reply tree. It always includes duplicated operation and parents of the @p request. |
| 509 | * @param[out] op_p Optional pointer to the reply operation. Useful mainly for action. |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 510 | * @return LY_ERR value. |
| 511 | */ |
Radek Krejci | 1798aae | 2020-07-14 13:26:06 +0200 | [diff] [blame] | 512 | LY_ERR lyd_parse_lyb_reply(const struct lyd_node *request, struct ly_in *in, struct lyd_node **tree_p, struct lyd_node **op_p); |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 513 | |
| 514 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 515 | * @defgroup datahash Data nodes hash manipulation |
| 516 | * @ingroup datatree |
| 517 | */ |
| 518 | |
| 519 | /** |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 520 | * @brief Generate hash for the node. |
| 521 | * |
| 522 | * @param[in] node Data node to (re)generate hash value. |
| 523 | * @return LY_ERR value. |
| 524 | */ |
| 525 | LY_ERR lyd_hash(struct lyd_node *node); |
| 526 | |
| 527 | /** |
| 528 | * @brief Insert hash of the node into the hash table of its parent. |
| 529 | * |
| 530 | * @param[in] node Data node which hash will be inserted into the lyd_node_inner::children_hash hash table of its parent. |
| 531 | * @return LY_ERR value. |
| 532 | */ |
| 533 | LY_ERR lyd_insert_hash(struct lyd_node *node); |
| 534 | |
| 535 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 536 | * @brief Maintain node's parent's children hash table when unlinking the node. |
| 537 | * |
| 538 | * When completely freeing data tree, it is expected to free the parent's children hash table first, at once. |
| 539 | * |
| 540 | * @param[in] node The data node being unlinked from its parent. |
| 541 | */ |
| 542 | void lyd_unlink_hash(struct lyd_node *node); |
| 543 | |
| 544 | /** @} datahash */ |
| 545 | |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 546 | /** |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 547 | * @brief Iterate over implemented modules for functions that accept specific modules or the whole context. |
| 548 | * |
| 549 | * @param[in] tree Data tree. |
Michal Vasko | 26e8001 | 2020-07-08 10:55:46 +0200 | [diff] [blame] | 550 | * @param[in] module Selected module, NULL for all. |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 551 | * @param[in] ctx Context, NULL for selected modules. |
| 552 | * @param[in,out] i Iterator, set to 0 on first call. |
| 553 | * @param[out] first First sibling of the returned module. |
| 554 | * @return Next module. |
| 555 | * @return NULL if all modules were traversed. |
| 556 | */ |
Michal Vasko | 26e8001 | 2020-07-08 10:55:46 +0200 | [diff] [blame] | 557 | 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] | 558 | const struct ly_ctx *ctx, uint32_t *i, struct lyd_node **first); |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 559 | |
| 560 | /** |
| 561 | * @brief Iterate over modules for functions that want to traverse all the top-level data. |
| 562 | * |
| 563 | * @param[in,out] next Pointer to the next module data, set to first top-level sibling on first call. |
| 564 | * @param[out] first First sibling of the returned module. |
| 565 | * @return Next module. |
| 566 | * @return NULL if all modules were traversed. |
| 567 | */ |
| 568 | const struct lys_module *lyd_data_next_module(struct lyd_node **next, struct lyd_node **first); |
| 569 | |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 570 | /** |
| 571 | * @brief Check that a list has all its keys. |
| 572 | * |
| 573 | * @param[in] node List to check. |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 574 | * @return LY_SUCCESS on success. |
| 575 | * @return LY_ENOT on a missing key. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 576 | */ |
| 577 | LY_ERR lyd_parse_check_keys(struct lyd_node *node); |
| 578 | |
Michal Vasko | 60ea635 | 2020-06-29 13:39:39 +0200 | [diff] [blame] | 579 | /** |
| 580 | * @brief Set data flags for a newly parsed node. |
| 581 | * |
| 582 | * @param[in] node Node to use. |
| 583 | * @param[in] when_check Set of nodes with unresolved when. |
| 584 | * @param[in,out] meta Node metadata, may be removed from. |
| 585 | * @param[in] options Parse options. |
| 586 | */ |
Radek Krejci | 1deb5be | 2020-08-26 16:43:36 +0200 | [diff] [blame] | 587 | 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] | 588 | |
| 589 | /** |
| 590 | * @brief Free value prefixes. |
| 591 | * |
| 592 | * @param[in] ctx libyang context. |
| 593 | * @param[in] val_prefis Value prefixes to free, sized array (@ref sizedarrays). |
| 594 | */ |
| 595 | void ly_free_val_prefs(const struct ly_ctx *ctx, struct ly_prefix *val_prefs); |
| 596 | |
Michal Vasko | d59035b | 2020-07-08 12:00:06 +0200 | [diff] [blame] | 597 | /** |
| 598 | * @brief Append all list key predicates to path. |
| 599 | * |
| 600 | * @param[in] node Node with keys to print. |
| 601 | * @param[in,out] buffer Buffer to print to. |
| 602 | * @param[in,out] buflen Current buffer length. |
| 603 | * @param[in,out] bufused Current number of characters used in @p buffer. |
| 604 | * @param[in] is_static Whether buffer is static or can be reallocated. |
| 605 | * @return LY_ERR |
| 606 | */ |
Radek Krejci | 857189e | 2020-09-01 13:26:36 +0200 | [diff] [blame] | 607 | 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] | 608 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 609 | #endif /* LY_TREE_DATA_INTERNAL_H_ */ |