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