Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @file tree_data_internal.h |
| 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
| 4 | * @brief internal functions for YANG schema trees. |
| 5 | * |
| 6 | * Copyright (c) 2015 - 2019 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * This source code is licensed under BSD 3-Clause License (the "License"). |
| 9 | * You may not use this file except in compliance with the License. |
| 10 | * You may obtain a copy of the License at |
| 11 | * |
| 12 | * https://opensource.org/licenses/BSD-3-Clause |
| 13 | */ |
| 14 | |
| 15 | #ifndef LY_TREE_DATA_INTERNAL_H_ |
| 16 | #define LY_TREE_DATA_INTERNAL_H_ |
| 17 | |
| 18 | #include "tree_data.h" |
Radek Krejci | aca7403 | 2019-06-04 08:53:06 +0200 | [diff] [blame] | 19 | #include "plugins_types.h" |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 20 | |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 21 | #include <stddef.h> |
| 22 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 23 | /** |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 24 | * @brief Check whether a node to be deleted is the first top-level sibling. |
| 25 | * |
| 26 | * @param[in] first First sibling. |
| 27 | * @param[in] to_del Node to be deleted. |
| 28 | */ |
| 29 | #define LYD_DEL_IS_ROOT(first, to_del) (((first) == (to_del)) && !(first)->parent && !(first)->prev->next) |
| 30 | |
| 31 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 32 | * @brief Get address of a node's child pointer if any. |
| 33 | * |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 34 | * @param[in] node Node to check. |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 35 | * @return Address of the node's child member, |
| 36 | * @return NULL if there is no child pointer. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 37 | */ |
| 38 | struct lyd_node **lyd_node_children_p(struct lyd_node *node); |
| 39 | |
| 40 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 41 | * @brief Create a term (leaf/leaf-list) node from a string value. |
| 42 | * |
| 43 | * Hash is calculated and new node flag is set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 44 | * |
| 45 | * @param[in] schema Schema node of the new data node. |
| 46 | * @param[in] value String value to be parsed. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 47 | * @param[in] value_len Length of @p value, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 48 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
| 49 | * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string. |
| 50 | * @param[in] prefix_data User data for @p get_prefix. |
| 51 | * @param[in] format Input format of @p value. |
| 52 | * @param[out] node Created node. |
| 53 | * @return LY_SUCCESS on success. |
| 54 | * @return LY_EINCOMPLETE in case data tree is needed to finish the validation. |
| 55 | * @return LY_ERR value if an error occurred. |
| 56 | */ |
| 57 | LY_ERR lyd_create_term(const struct lysc_node *schema, const char *value, size_t value_len, int *dynamic, |
| 58 | ly_clb_resolve_prefix get_prefix, void *prefix_data, LYD_FORMAT format, struct lyd_node **node); |
| 59 | |
| 60 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 61 | * @brief Create a term (leaf/leaf-list) node from a parsed value by duplicating it. |
| 62 | * |
| 63 | * Hash is calculated and new node flag is set. |
| 64 | * |
| 65 | * @param[in] schema Schema node of the new data node. |
| 66 | * @param[in] val Parsed value to use. |
| 67 | * @param[out] node Created node. |
| 68 | * @return LY_SUCCESS on success. |
| 69 | * @return LY_ERR value if an error occurred. |
| 70 | */ |
| 71 | LY_ERR lyd_create_term2(const struct lysc_node *schema, const struct lyd_value *val, struct lyd_node **node); |
| 72 | |
| 73 | /** |
| 74 | * @brief Create an inner (container/list/RPC/action/notification) node. |
| 75 | * |
| 76 | * Hash is calculated and new node flag is set except |
| 77 | * for list with keys, when the hash is not calculated! |
| 78 | * Also, non-presence container has its default flag set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 79 | * |
| 80 | * @param[in] schema Schema node of the new data node. |
| 81 | * @param[out] node Created node. |
| 82 | * @return LY_SUCCESS on success. |
| 83 | * @return LY_ERR value if an error occurred. |
| 84 | */ |
| 85 | LY_ERR lyd_create_inner(const struct lysc_node *schema, struct lyd_node **node); |
| 86 | |
| 87 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 88 | * @brief Create a list with all its keys (cannot be used for key-less list). |
| 89 | * |
| 90 | * Hash is calculated and new node flag is set. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 91 | * |
| 92 | * @param[in] schema Schema node of the new data node. |
| 93 | * @param[in] keys_str List instance key values in the form of "[key1='val1'][key2='val2']...". |
| 94 | * The keys do not have to be ordered but all of them must be set. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 95 | * @param[in] keys_len Length of @p keys_str, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 96 | * @param[out] node Created node. |
| 97 | * @return LY_SUCCESS on success. |
| 98 | * @return LY_ERR value if an error occurred. |
| 99 | */ |
| 100 | LY_ERR lyd_create_list(const struct lysc_node *schema, const char *keys_str, size_t keys_len, struct lyd_node **node); |
| 101 | |
| 102 | /** |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 103 | * @brief Create an anyxml/anydata node. |
| 104 | * |
| 105 | * 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] | 106 | * |
| 107 | * @param[in] schema Schema node of the new data node. |
| 108 | * @param[in] value Value of the any node, is directly assigned into the data node. |
| 109 | * @param[in] value_type Value type of the value. |
| 110 | * @param[out] node Created node. |
| 111 | * @return LY_SUCCESS on success. |
| 112 | * @return LY_ERR value if an error occurred. |
| 113 | */ |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 114 | LY_ERR lyd_create_any(const struct lysc_node *schema, const void *value, LYD_ANYDATA_VALUETYPE value_type, |
| 115 | struct lyd_node **node); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 116 | |
| 117 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 118 | * @brief Create an opaque node. |
| 119 | * |
| 120 | * @param[in] ctx libyang context. |
| 121 | * @param[in] name Element name. |
| 122 | * @param[in] name_len Length of @p name, must be set correctly. |
| 123 | * @param[in] value String value to be parsed. |
| 124 | * @param[in] value_len Length of @p value, must be set correctly. |
| 125 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
| 126 | * @param[in] format Input format of @p value and @p ns. |
| 127 | * @param[in] val_prefs Possible value prefixes, array is spent. |
| 128 | * @param[in] prefix Element prefix. |
| 129 | * @param[in] pref_len Length of @p prefix, must be set correctly. |
| 130 | * @param[in] ns Node namespace, meaning depends on @p format. |
| 131 | * @param[out] node Created node. |
| 132 | * @return LY_SUCCESS on success. |
| 133 | * @return LY_ERR value if an error occurred. |
| 134 | */ |
| 135 | LY_ERR lyd_create_opaq(const struct ly_ctx *ctx, const char *name, size_t name_len, const char *value, size_t value_len, |
| 136 | int *dynamic, LYD_FORMAT format, struct ly_prefix *val_prefs, const char *prefix, size_t pref_len, |
| 137 | const char *ns, struct lyd_node **node); |
| 138 | |
| 139 | /** |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 140 | * @brief Find the key after which to insert the new key. |
| 141 | * |
| 142 | * @param[in] first_sibling List first sibling. |
| 143 | * @param[in] new_key Key that will be inserted. |
| 144 | * @return Key to insert after. |
| 145 | * @return NULL if the new key should be first. |
| 146 | */ |
| 147 | struct lyd_node *lyd_get_prev_key_anchor(const struct lyd_node *first_sibling, const struct lysc_node *new_key); |
| 148 | |
| 149 | /** |
| 150 | * @brief Insert a node into parent/siblings. In case a key is being inserted into a list, the correct position |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 151 | * is found, inserted into, and if it is the last key, parent list hash is calculated. Also, in case we are inserting |
| 152 | * into top-level siblings, insert it as the last sibling of all the module data siblings. Otherwise it is inserted at |
| 153 | * the very last place. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 154 | * |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 155 | * @param[in] parent Parent to insert into, NULL for top-level sibling. |
| 156 | * @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] | 157 | * @param[in] node Individual node (without siblings) to insert. |
| 158 | */ |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 159 | 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] | 160 | |
| 161 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 162 | * @brief Create and insert a metadata (last) into a parent. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 163 | * |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 164 | * @param[in] parent Parent of the metadata, can be NULL. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 165 | * @param[in,out] meta Metadata list to add at its end if @p parent is NULL, returned created attribute. |
| 166 | * @param[in] mod Metadata module (with the annotation definition). |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 167 | * @param[in] name Attribute name. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 168 | * @param[in] name_len Length of @p name, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 169 | * @param[in] value String value to be parsed. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 170 | * @param[in] value_len Length of @p value, must be set correctly. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 171 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 172 | * @param[in] resolve_prefix Parser-specific getter to resolve prefixes used in the @p value string. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 173 | * @param[in] prefix_data User data for @p get_prefix. |
| 174 | * @param[in] format Input format of @p value. |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 175 | * @param[in] ctx_snode Context node for value resolution in schema. |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 176 | * @return LY_SUCCESS on success. |
| 177 | * @return LY_EINCOMPLETE in case data tree is needed to finish the validation. |
| 178 | * @return LY_ERR value if an error occurred. |
| 179 | */ |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 180 | LY_ERR lyd_create_meta(struct lyd_node *parent, struct lyd_meta **meta, const struct lys_module *mod, const char *name, |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 181 | size_t name_len, const char *value, size_t value_len, int *dynamic, ly_clb_resolve_prefix resolve_prefix, |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 182 | void *prefix_data, LYD_FORMAT format, const struct lysc_node *ctx_snode); |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 183 | |
| 184 | /** |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 185 | * @brief Create and insert a generic attribute (last) into a parent. |
| 186 | * |
| 187 | * @param[in] parent Parent of the attribute, can be NULL. |
| 188 | * @param[in,out] attr Attribute list to add at its end if @p parent is NULL, returned created attribute. |
| 189 | * @param[in] ctx libyang context. |
| 190 | * @param[in] name Attribute name. |
| 191 | * @param[in] name_len Length of @p name, must be set correctly. |
| 192 | * @param[in] value String value to be parsed. |
| 193 | * @param[in] value_len Length of @p value, must be set correctly. |
| 194 | * @param[in,out] dynamic Flag if @p value is dynamically allocated, is adjusted when @p value is consumed. |
| 195 | * @param[in] format Input format of @p value and @p ns. |
| 196 | * @param[in] val_prefs Possible value prefixes, array is spent. |
| 197 | * @param[in] prefix Attribute prefix. |
| 198 | * @param[in] prefix_len Attribute prefix length. |
| 199 | * @param[in] ns Attribute namespace, meaning depends on @p format. |
| 200 | * @return LY_SUCCESS on success. |
| 201 | * @return LY_ERR value if an error occurred. |
| 202 | */ |
| 203 | LY_ERR ly_create_attr(struct lyd_node *parent, struct ly_attr **attr, const struct ly_ctx *ctx, const char *name, |
| 204 | size_t name_len, const char *value, size_t value_len, int *dynamic, LYD_FORMAT format, |
| 205 | struct ly_prefix *val_prefs, const char *prefix, size_t prefix_len, const char *ns); |
| 206 | |
| 207 | /** |
Radek Krejci | 5819f7c | 2019-05-31 14:53:29 +0200 | [diff] [blame] | 208 | * @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] | 209 | * |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 210 | * @param[in] node Data node for the @p value. |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 211 | * @param[in] value String value to be parsed, must not be NULL. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 212 | * @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] | 213 | * @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] | 214 | * @param[in] second Flag for the second call after returning LY_EINCOMPLETE |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 215 | * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string. |
Radek Krejci | aca7403 | 2019-06-04 08:53:06 +0200 | [diff] [blame] | 216 | * @param[in] parser Parser's data for @p get_prefix |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 217 | * @param[in] format Input format of @p value. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 218 | * @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] | 219 | * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete, |
| 220 | * then LY_EINCOMPLETE can be returned. |
| 221 | * @return LY_SUCCESS on success |
| 222 | * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation. |
| 223 | * @return LY_ERR value if an error occurred. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 224 | */ |
Michal Vasko | 90932a9 | 2020-02-12 14:33:03 +0100 | [diff] [blame] | 225 | LY_ERR lyd_value_parse(struct lyd_node_term *node, const char *value, size_t value_len, int *dynamic, int second, |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 226 | ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format, const struct lyd_node *tree); |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 227 | |
| 228 | /** |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 229 | * @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] | 230 | * |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 231 | * @param[in] ctx libyang context. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 232 | * @param[in] meta Metadata for the @p value. |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 233 | * @param[in] value String value to be parsed, must not be NULL. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 234 | * @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] | 235 | * @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] | 236 | * @param[in] second Flag for the second call after returning LY_EINCOMPLETE |
| 237 | * @param[in] get_prefix Parser-specific getter to resolve prefixes used in the @p value string. |
| 238 | * @param[in] parser Parser's data for @p get_prefix |
| 239 | * @param[in] format Input format of the data. |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 240 | * @param[in] ctx_snode Context node for value resolution in schema. |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 241 | * @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] | 242 | * data instance (leafref target, instance-identifier) can be placed. NULL in case the data tree are not yet complete, |
| 243 | * then LY_EINCOMPLETE can be returned. |
| 244 | * @return LY_SUCCESS on success |
| 245 | * @return LY_EINCOMPLETE in case the @p trees is not provided and it was needed to finish the validation. |
| 246 | * @return LY_ERR value if an error occurred. |
| 247 | */ |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 248 | LY_ERR lyd_value_parse_meta(struct ly_ctx *ctx, struct lyd_meta *meta, const char *value, size_t value_len, int *dynamic, |
Michal Vasko | 8d54425 | 2020-03-02 10:19:52 +0100 | [diff] [blame] | 249 | int second, ly_clb_resolve_prefix get_prefix, void *parser, LYD_FORMAT format, |
Michal Vasko | f03ed03 | 2020-03-04 13:31:44 +0100 | [diff] [blame] | 250 | const struct lysc_node *ctx_snode, const struct lyd_node *tree); |
Radek Krejci | 38d8536 | 2019-09-05 16:26:38 +0200 | [diff] [blame] | 251 | |
| 252 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 253 | * @brief Parse XML string as YANG data tree. |
| 254 | * |
| 255 | * @param[in] ctx libyang context |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 256 | * @param[in] data Pointer to the XML data to parse. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 257 | * @param[in] options @ref dataparseroptions |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 258 | * @param[out] tree Parsed data tree. Note that NULL can be a valid result. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 259 | * @return LY_ERR value. |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 260 | */ |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 261 | LY_ERR lyd_parse_xml_data(struct ly_ctx *ctx, const char *data, int options, struct lyd_node **tree); |
| 262 | |
| 263 | /** |
| 264 | * @brief Parse XML string as YANG RPC/action invocation. |
| 265 | * |
| 266 | * Optional \<rpc\> envelope element, if present, is [checked](https://tools.ietf.org/html/rfc6241#section-4.1) and all |
| 267 | * its XML attributes returned. In that case an RPC is expected to be parsed. |
| 268 | * |
| 269 | * Can be followed by optional \<action\> envelope element, which is also |
| 270 | * [checked](https://tools.ietf.org/html/rfc7950#section-7.15.2) and then an action is expected to be parsed. |
| 271 | * |
| 272 | * @param[in] ctx libyang context. |
| 273 | * @param[in] data Pointer to the XML data to parse. |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame^] | 274 | * @param[out] tree Parsed full RPC/action tree. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 275 | * @param[out] op Pointer to the actual operation. Useful mainly for action. |
| 276 | * @return LY_ERR value. |
| 277 | */ |
Michal Vasko | b36053d | 2020-03-26 15:49:30 +0100 | [diff] [blame^] | 278 | //LY_ERR lyd_parse_xml_rpc(struct ly_ctx *ctx, const char *data, struct lyd_node **tree, struct lyd_node **op); |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 279 | |
| 280 | /** |
| 281 | * @defgroup datahash Data nodes hash manipulation |
| 282 | * @ingroup datatree |
| 283 | */ |
| 284 | |
| 285 | /** |
Radek Krejci | 1f05b6a | 2019-07-18 16:15:06 +0200 | [diff] [blame] | 286 | * @brief Generate hash for the node. |
| 287 | * |
| 288 | * @param[in] node Data node to (re)generate hash value. |
| 289 | * @return LY_ERR value. |
| 290 | */ |
| 291 | LY_ERR lyd_hash(struct lyd_node *node); |
| 292 | |
| 293 | /** |
| 294 | * @brief Insert hash of the node into the hash table of its parent. |
| 295 | * |
| 296 | * @param[in] node Data node which hash will be inserted into the lyd_node_inner::children_hash hash table of its parent. |
| 297 | * @return LY_ERR value. |
| 298 | */ |
| 299 | LY_ERR lyd_insert_hash(struct lyd_node *node); |
| 300 | |
| 301 | /** |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 302 | * @brief Maintain node's parent's children hash table when unlinking the node. |
| 303 | * |
| 304 | * When completely freeing data tree, it is expected to free the parent's children hash table first, at once. |
| 305 | * |
| 306 | * @param[in] node The data node being unlinked from its parent. |
| 307 | */ |
| 308 | void lyd_unlink_hash(struct lyd_node *node); |
| 309 | |
| 310 | /** @} datahash */ |
| 311 | |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 312 | /** |
| 313 | * @brief Free path (target) structure of the lyd_value. |
| 314 | * |
| 315 | * @param[in] ctx libyang context. |
| 316 | * @param[in] path The structure ([sized array](@ref sizedarrays)) to free. |
| 317 | */ |
Michal Vasko | 52927e2 | 2020-03-16 17:26:14 +0100 | [diff] [blame] | 318 | void lyd_value_free_path(const struct ly_ctx *ctx, struct lyd_value_path *path); |
Radek Krejci | 084289f | 2019-07-09 17:35:30 +0200 | [diff] [blame] | 319 | |
Michal Vasko | 9b368d3 | 2020-02-14 13:53:31 +0100 | [diff] [blame] | 320 | /** |
| 321 | * @brief Find the node, in the list, satisfying the given restrictions. |
| 322 | * Does **not** use hashes - should not be used unless necessary for best performance. |
| 323 | * |
| 324 | * @param[in] first Starting sibling node for search, only succeeding ones are searched. |
| 325 | * @param[in] schema Schema node of the data node to find. |
| 326 | * @param[in] key_or_value Expected value depends on the type of @p schema: |
| 327 | * LYS_CONTAINER: |
| 328 | * LYS_ANYXML: |
| 329 | * LYS_ANYDATA: |
| 330 | * LYS_NOTIF: |
| 331 | * LYS_RPC: |
| 332 | * LYS_ACTION: |
| 333 | * NULL should be always set, will be ignored. |
| 334 | * LYS_LEAF: |
| 335 | * LYS_LEAFLIST: |
| 336 | * Optional restriction on the specific leaf(-list) value. |
| 337 | * LYS_LIST: |
| 338 | * Optional keys values of the matching list instances in the form of "[key1='val1'][key2='val2']...". |
| 339 | * The keys do not have to be ordered and not all keys need to be specified. |
| 340 | * |
| 341 | * Note that any explicit values (leaf, leaf-list or list key values) will be canonized first |
| 342 | * before comparison. But values that do not have a canonical value are expected to be in the |
| 343 | * JSON format! |
| 344 | * @param[in] val_len Optional length of the @p key_or_value argument in case it is not NULL-terminated string. |
| 345 | * @param[out] match Can be NULL, otherwise the found data node. |
| 346 | * @return LY_SUCCESS on success, @p match set. |
| 347 | * @return LY_ENOTFOUND if not found, @p match set to NULL. |
| 348 | * @return LY_ERR value if another error occurred. |
| 349 | */ |
| 350 | LY_ERR lyd_find_sibling_next2(const struct lyd_node *first, const struct lysc_node *schema, const char *key_or_value, |
| 351 | size_t val_len, struct lyd_node **match); |
| 352 | |
| 353 | /** |
Michal Vasko | b1b5c26 | 2020-03-05 14:29:47 +0100 | [diff] [blame] | 354 | * @brief Iterate over implemented modules for functions that accept specific modules or the whole context. |
| 355 | * |
| 356 | * @param[in] tree Data tree. |
| 357 | * @param[in] modules Selected modules, NULL for all. |
| 358 | * @param[in] mod_count Count of @p modules. |
| 359 | * @param[in] ctx Context, NULL for selected modules. |
| 360 | * @param[in,out] i Iterator, set to 0 on first call. |
| 361 | * @param[out] first First sibling of the returned module. |
| 362 | * @return Next module. |
| 363 | * @return NULL if all modules were traversed. |
| 364 | */ |
| 365 | const struct lys_module *lyd_mod_next_module(struct lyd_node *tree, const struct lys_module **modules, int mod_count, |
| 366 | const struct ly_ctx *ctx, uint32_t *i, struct lyd_node **first); |
| 367 | |
| 368 | /** |
| 369 | * @brief Iterate over modules for functions that want to traverse all the top-level data. |
| 370 | * |
| 371 | * @param[in,out] next Pointer to the next module data, set to first top-level sibling on first call. |
| 372 | * @param[out] first First sibling of the returned module. |
| 373 | * @return Next module. |
| 374 | * @return NULL if all modules were traversed. |
| 375 | */ |
| 376 | const struct lys_module *lyd_data_next_module(struct lyd_node **next, struct lyd_node **first); |
| 377 | |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 378 | /** |
| 379 | * @brief Check that a list has all its keys. |
| 380 | * |
| 381 | * @param[in] node List to check. |
Michal Vasko | 44685da | 2020-03-17 15:38:06 +0100 | [diff] [blame] | 382 | * @return LY_SUCCESS on success. |
| 383 | * @return LY_ENOT on a missing key. |
Michal Vasko | 9f96a05 | 2020-03-10 09:41:45 +0100 | [diff] [blame] | 384 | */ |
| 385 | LY_ERR lyd_parse_check_keys(struct lyd_node *node); |
| 386 | |
Radek Krejci | e7b9509 | 2019-05-15 11:03:07 +0200 | [diff] [blame] | 387 | #endif /* LY_TREE_DATA_INTERNAL_H_ */ |