Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 1 | /** |
Radek Krejci | aa429e4 | 2015-10-09 15:52:37 +0200 | [diff] [blame] | 2 | * @file tree_data.h |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 3 | * @author Radek Krejci <rkrejci@cesnet.cz> |
Radek Krejci | aa429e4 | 2015-10-09 15:52:37 +0200 | [diff] [blame] | 4 | * @brief libyang representation of data trees. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 5 | * |
| 6 | * Copyright (c) 2015 CESNET, z.s.p.o. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in |
| 15 | * the documentation and/or other materials provided with the |
| 16 | * distribution. |
| 17 | * 3. Neither the name of the Company nor the names of its contributors |
| 18 | * may be used to endorse or promote products derived from this |
| 19 | * software without specific prior written permission. |
| 20 | */ |
| 21 | |
| 22 | #ifndef LY_TREE_DATA_H_ |
| 23 | #define LY_TREE_DATA_H_ |
| 24 | |
| 25 | #include <stddef.h> |
| 26 | #include <stdint.h> |
| 27 | |
Mislav Novakovic | e251a65 | 2015-09-29 08:40:12 +0200 | [diff] [blame] | 28 | #include "tree_schema.h" |
| 29 | |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 30 | #ifdef __cplusplus |
| 31 | extern "C" { |
| 32 | #endif |
| 33 | |
| 34 | /** |
| 35 | * @addtogroup datatree |
| 36 | * @{ |
| 37 | */ |
| 38 | |
| 39 | /** |
| 40 | * @brief Data input/output formats supported by libyang [parser](@ref parsers) and [printer](@ref printers) functions. |
| 41 | */ |
| 42 | typedef enum { |
| 43 | LYD_UNKNOWN, /**< unknown format, used as return value in case of error */ |
| 44 | LYD_XML, /**< XML format of the instance data */ |
Radek Krejci | 452fb95 | 2015-10-02 16:07:46 +0200 | [diff] [blame] | 45 | LYD_XML_FORMAT, /**< For input data, it is interchangeable with #LYD_XML, for output it formats XML with indentantion */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 46 | LYD_JSON, /**< JSON format of the instance data */ |
| 47 | } LYD_FORMAT; |
| 48 | |
| 49 | /** |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 50 | * @brief Attribute structure. |
| 51 | * |
Radek Krejci | 5f9e8c9 | 2015-10-30 10:01:06 +0100 | [diff] [blame] | 52 | * The structure provides information about attributes of a data element. Such attributes partially |
| 53 | * maps to annotations from draft-ietf-netmod-yang-metadata. In XML, they are represented as standard |
| 54 | * XML attrbutes. In JSON, they are represented as JSON elements starting with the '@' character |
| 55 | * (for more information, see the yang metadata draft. |
| 56 | * |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 57 | */ |
| 58 | struct lyd_attr { |
Radek Krejci | 5f9e8c9 | 2015-10-30 10:01:06 +0100 | [diff] [blame] | 59 | struct lyd_attr *next; /**< pointer to the next attribute of the same element */ |
| 60 | struct lys_module *module; /**< pointer to the attribute's module. |
| 61 | TODO when annotations will be supported, point to the annotation definition |
| 62 | and validate that the attribute is really defined there. Currently, we just |
| 63 | believe that it is defined in the module it says */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 64 | const char *name; /**< attribute name */ |
| 65 | const char *value; /**< attribute value */ |
| 66 | }; |
| 67 | |
| 68 | /** |
| 69 | * @brief node's value representation |
| 70 | */ |
| 71 | typedef union lyd_value_u { |
| 72 | const char *binary; /**< base64 encoded, NULL terminated string */ |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 73 | struct lys_type_bit **bit; /**< bitmap of pointers to the schema definition of the bit value that are set, |
| 74 | its size is always the number of defined bits in the schema */ |
Radek Krejci | 489773c | 2015-12-17 13:20:03 +0100 | [diff] [blame] | 75 | int8_t bln; /**< 0 as false, 1 as true */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 76 | int64_t dec64; /**< decimal64: value = dec64 / 10^fraction-digits */ |
| 77 | struct lys_type_enum *enm; /**< pointer to the schema definition of the enumeration value */ |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 78 | struct lys_ident *ident; /**< pointer to the schema definition of the identityref value */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 79 | struct lyd_node *instance; /**< instance-identifier, pointer to the referenced data tree node */ |
| 80 | int8_t int8; /**< 8-bit signed integer */ |
| 81 | int16_t int16; /**< 16-bit signed integer */ |
| 82 | int32_t int32; /**< 32-bit signed integer */ |
| 83 | int64_t int64; /**< 64-bit signed integer */ |
| 84 | struct lyd_node *leafref; /**< pointer to the referenced leaf/leaflist instance in data tree */ |
| 85 | const char *string; /**< string */ |
| 86 | uint8_t uint8; /**< 8-bit unsigned integer */ |
| 87 | uint16_t uint16; /**< 16-bit signed integer */ |
| 88 | uint32_t uint32; /**< 32-bit signed integer */ |
| 89 | uint64_t uint64; /**< 64-bit signed integer */ |
| 90 | } lyd_val; |
| 91 | |
| 92 | /** |
Radek Krejci | ca7efb7 | 2016-01-18 13:06:01 +0100 | [diff] [blame] | 93 | * @defgroup validityflags Validity flags |
| 94 | * @ingroup datatree |
| 95 | * |
| 96 | * Validity flags for data nodes. |
| 97 | * |
| 98 | * @{ |
| 99 | */ |
| 100 | #define LYD_VAL_OK 0x00 /**< node is successfully validated including whole subtree */ |
| 101 | #define LYD_VAL_UNIQUE 0x01 /**< Unique value(s) changed, applicable only to ::lys_node_list data nodes */ |
| 102 | #define LYD_VAL_NOT 0xff /**< node was not validated yet */ |
| 103 | /** |
| 104 | * @} |
| 105 | */ |
| 106 | |
| 107 | /** |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 108 | * @brief Generic structure for a data node, directly applicable to the data nodes defined as #LYS_CONTAINER, #LYS_LIST |
| 109 | * and #LYS_CHOICE. |
| 110 | * |
| 111 | * Completely fits to containers and choices and is compatible (can be used interchangeably except the #child member) |
| 112 | * with all other lyd_node_* structures. All data nodes are provides as ::lyd_node structure by default. |
| 113 | * According to the schema's ::lys_node#nodetype member, the specific object is supposed to be cast to |
Radek Krejci | ca7efb7 | 2016-01-18 13:06:01 +0100 | [diff] [blame] | 114 | * ::lyd_node_leaf_list or ::lyd_node_anyxml structures. This structure fits only to #LYS_CONTAINER, #LYS_LIST and |
| 115 | * #LYS_CHOICE values. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 116 | * |
| 117 | * To traverse through all the child elements or attributes, use #LY_TREE_FOR or #LY_TREE_FOR_SAFE macro. |
| 118 | */ |
| 119 | struct lyd_node { |
| 120 | struct lys_node *schema; /**< pointer to the schema definition of this node */ |
Radek Krejci | ca7efb7 | 2016-01-18 13:06:01 +0100 | [diff] [blame] | 121 | uint8_t validity; /**< [validity flags](@ref validityflags) */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 122 | |
| 123 | struct lyd_attr *attr; /**< pointer to the list of attributes of this node */ |
| 124 | struct lyd_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 125 | struct lyd_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is |
| 126 | never NULL. If there is no sibling node, pointer points to the node |
| 127 | itself. In case of the first node, this pointer points to the last |
| 128 | node in the list. */ |
| 129 | struct lyd_node *parent; /**< pointer to the parent node, NULL in case of root node */ |
| 130 | struct lyd_node *child; /**< pointer to the first child node \note Since other lyd_node_* |
Radek Krejci | ee36089 | 2015-10-06 11:23:14 +0200 | [diff] [blame] | 131 | structures represent end nodes, this member |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 132 | is replaced in those structures. Therefore, be careful with accessing |
| 133 | this member without having information about the node type from the schema's |
| 134 | ::lys_node#nodetype member. */ |
| 135 | }; |
| 136 | |
| 137 | /** |
Michal Vasko | 4c18331 | 2015-09-25 10:41:47 +0200 | [diff] [blame] | 138 | * @brief Structure for data nodes defined as #LYS_LEAF or #LYS_LEAFLIST. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 139 | * |
Michal Vasko | 4c18331 | 2015-09-25 10:41:47 +0200 | [diff] [blame] | 140 | * Extension for ::lyd_node structure. It replaces the ::lyd_node#child member by |
| 141 | * three new members (#value, #value_str and #value_type) to provide |
| 142 | * information about the value. The first five members (#schema, #attr, #next, |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 143 | * #prev and #parent) are compatible with the ::lyd_node's members. |
| 144 | * |
| 145 | * To traverse through all the child elements or attributes, use #LY_TREE_FOR or #LY_TREE_FOR_SAFE macro. |
| 146 | */ |
Michal Vasko | 4c18331 | 2015-09-25 10:41:47 +0200 | [diff] [blame] | 147 | struct lyd_node_leaf_list { |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 148 | struct lys_node *schema; /**< pointer to the schema definition of this node which is ::lys_node_leaflist |
| 149 | structure */ |
Radek Krejci | ca7efb7 | 2016-01-18 13:06:01 +0100 | [diff] [blame] | 150 | uint8_t validity; /**< [validity flags](@ref validityflags) */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 151 | |
| 152 | struct lyd_attr *attr; /**< pointer to the list of attributes of this node */ |
| 153 | struct lyd_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 154 | struct lyd_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is |
| 155 | never NULL. If there is no sibling node, pointer points to the node |
| 156 | itself. In case of the first node, this pointer points to the last |
| 157 | node in the list. */ |
| 158 | struct lyd_node *parent; /**< pointer to the parent node, NULL in case of root node */ |
| 159 | |
| 160 | /* struct lyd_node *child; should be here, but is not */ |
| 161 | |
| 162 | /* leaflist's specific members */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 163 | const char *value_str; /**< string representation of value (for comparison, printing,...) */ |
Radek Krejci | 2323892 | 2015-10-27 17:13:34 +0100 | [diff] [blame] | 164 | lyd_val value; /**< node's value representation */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 165 | LY_DATA_TYPE value_type; /**< type of the value in the node, mainly for union to avoid repeating of type detection */ |
| 166 | }; |
| 167 | |
| 168 | /** |
| 169 | * @brief Structure for data nodes defined as #LYS_ANYXML. |
| 170 | * |
| 171 | * Extension for ::lyd_node structure - replaces the ::lyd_node#child member by new #value member. The first five |
| 172 | * members (#schema, #attr, #next, #prev and #parent) are compatible with the ::lyd_node's members. |
| 173 | * |
| 174 | * To traverse through all the child elements or attributes, use #LY_TREE_FOR or #LY_TREE_FOR_SAFE macro. |
| 175 | */ |
| 176 | struct lyd_node_anyxml { |
| 177 | struct lys_node *schema; /**< pointer to the schema definition of this node which is ::lys_node_anyxml |
| 178 | structure */ |
Radek Krejci | ca7efb7 | 2016-01-18 13:06:01 +0100 | [diff] [blame] | 179 | uint8_t validity; /**< [validity flags](@ref validityflags) */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 180 | |
| 181 | struct lyd_attr *attr; /**< pointer to the list of attributes of this node */ |
| 182 | struct lyd_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 183 | struct lyd_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is |
| 184 | never NULL. If there is no sibling node, pointer points to the node |
| 185 | itself. In case of the first node, this pointer points to the last |
| 186 | node in the list. */ |
| 187 | struct lyd_node *parent; /**< pointer to the parent node, NULL in case of root node */ |
| 188 | |
| 189 | /* struct lyd_node *child; should be here, but is not */ |
| 190 | |
| 191 | /* anyxml's specific members */ |
| 192 | struct lyxml_elem *value; /**< anyxml name is the root element of value! */ |
| 193 | }; |
| 194 | |
| 195 | /** |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 196 | * @brief Create a new container node in a data tree. |
| 197 | * |
| 198 | * @param[in] parent Parent node for the node being created. NULL in case of creating top level element. |
Radek Krejci | ee36089 | 2015-10-06 11:23:14 +0200 | [diff] [blame] | 199 | * @param[in] module Module with the node being created. |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 200 | * @param[in] name Schema node name of the new data node. The node can be #LYS_CONTAINER, #LYS_LIST, |
Michal Vasko | a45cf2b | 2015-10-23 09:45:36 +0200 | [diff] [blame] | 201 | * #LYS_NOTIF, or #LYS_RPC. |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 202 | * @return New node, NULL on error. |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 203 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 204 | struct lyd_node *lyd_new(struct lyd_node *parent, const struct lys_module *module, const char *name); |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 205 | |
| 206 | /** |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 207 | * @brief Create a new leaf or leaflist node in a data tree with a string value that is converted to |
| 208 | * the actual value. |
| 209 | * |
| 210 | * @param[in] parent Parent node for the node being created. NULL in case of creating top level element. |
Radek Krejci | ee36089 | 2015-10-06 11:23:14 +0200 | [diff] [blame] | 211 | * @param[in] module Module with the node being created. |
| 212 | * @param[in] name Schema node name of the new data node. |
Michal Vasko | 3e671b5 | 2015-10-23 16:23:15 +0200 | [diff] [blame] | 213 | * @param[in] val_str String form of the value of the node being created. In case the type is #LY_TYPE_INST |
| 214 | * or #LY_TYPE_IDENT, JSON node-id format is expected (nodes are prefixed with module names, not XML namespaces). |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 215 | * @return New node, NULL on error. |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 216 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 217 | struct lyd_node *lyd_new_leaf(struct lyd_node *parent, const struct lys_module *module, const char *name, |
Michal Vasko | 3e671b5 | 2015-10-23 16:23:15 +0200 | [diff] [blame] | 218 | const char *val_str); |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 219 | |
| 220 | /** |
Radek Krejci | b9b4d00 | 2016-01-18 13:08:51 +0100 | [diff] [blame] | 221 | * @brief Change value of a leaf node. |
| 222 | * |
| 223 | * Despite the prototype allows to provide a leaflist node as \p leaf parameter, only leafs are accepted. |
| 224 | * |
| 225 | * @param[in] leaf A leaf node to change. |
| 226 | * @param[in] val_str String form of the new value to be set to the \p leaf. In case the type is #LY_TYPE_INST |
| 227 | * or #LY_TYPE_IDENT, JSON node-id format is expected (nodes are prefixed with module names, not XML namespaces). |
| 228 | * @return 0 on success, non-zero on error. |
| 229 | */ |
| 230 | int lyd_change_leaf(struct lyd_node_leaf_list *leaf, const char *val_str); |
| 231 | |
| 232 | /** |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 233 | * @brief Create a new anyxml node in a data tree. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 234 | * |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 235 | * @param[in] parent Parent node for the node being created. NULL in case of creating top level element. |
Radek Krejci | ee36089 | 2015-10-06 11:23:14 +0200 | [diff] [blame] | 236 | * @param[in] module Module with the node being created. |
| 237 | * @param[in] name Schema node name of the new data node. |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 238 | * @param[in] val_xml Value of the node being created. Must be a well-formed XML. |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 239 | * @return New node, NULL on error. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 240 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 241 | struct lyd_node *lyd_new_anyxml(struct lyd_node *parent, const struct lys_module *module, const char *name, |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 242 | const char *val_xml); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 243 | |
| 244 | /** |
Michal Vasko | 50c0a87 | 2016-01-13 14:34:11 +0100 | [diff] [blame] | 245 | * @brief Create a new container node in a data tree, whose schema parent is #LYS_OUTPUT. |
Michal Vasko | 0df122f | 2015-12-14 13:38:21 +0100 | [diff] [blame] | 246 | * |
Michal Vasko | 50c0a87 | 2016-01-13 14:34:11 +0100 | [diff] [blame] | 247 | * @param[in] schema Schema node of the container. |
Michal Vasko | 0df122f | 2015-12-14 13:38:21 +0100 | [diff] [blame] | 248 | * @return New node, NULL on error. |
| 249 | */ |
Michal Vasko | 50c0a87 | 2016-01-13 14:34:11 +0100 | [diff] [blame] | 250 | struct lyd_node *lyd_output_new(const struct lys_node *schema); |
| 251 | |
| 252 | /** |
| 253 | * @brief Create a new leaf or leaflist node in a data tree, whose schema parent is #LYS_OUTPUT. |
| 254 | * |
| 255 | * @param[in] schema Schema node of the leaf. |
| 256 | * @param[in] val_str String form of the value of the node being created. In case the type is #LY_TYPE_INST |
| 257 | * or #LY_TYPE_IDENT, JSON node-id format is expected (nodes are prefixed with module names, not XML namespaces). |
| 258 | * @return New node, NULL on error. |
| 259 | */ |
| 260 | struct lyd_node *lyd_output_new_leaf(const struct lys_node *schema, const char *val_str); |
| 261 | |
| 262 | /** |
| 263 | * @brief Create a new anyxml node in a data tree, whose schema parent is #LYS_OUTPUT. |
| 264 | * |
| 265 | * @param[in] schema Schema node of the leaf. |
| 266 | * @param[in] val_xml Value of the node being created. Must be a well-formed XML. |
| 267 | * @return New node, NULL on error. |
| 268 | */ |
| 269 | struct lyd_node *lyd_output_new_anyxml(const struct lys_node *schema, const char *val_xml); |
Michal Vasko | 0df122f | 2015-12-14 13:38:21 +0100 | [diff] [blame] | 270 | |
| 271 | /** |
Michal Vasko | c0797f8 | 2015-10-14 15:51:25 +0200 | [diff] [blame] | 272 | * @brief Create a copy of the specified data tree \p node. Namespaces are copied as needed, |
| 273 | * schema references are kept the same. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 274 | * |
| 275 | * @param[in] node Data tree node to be duplicated. |
| 276 | * @param[in] recursive 1 if all children are supposed to be also duplicated. |
| 277 | * @return Created copy of the provided data \p node. |
| 278 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 279 | struct lyd_node *lyd_dup(const struct lyd_node *node, int recursive); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 280 | |
| 281 | /** |
| 282 | * @brief Insert the \p node element as child to the \p parent element. The \p node is inserted as a last child of the |
| 283 | * \p parent. |
| 284 | * |
| 285 | * If the node is part of some other tree, it is automatically unlinked. |
| 286 | * If the node is the first node of a node list (with no parent), all |
| 287 | * the subsequent nodes are also inserted. |
| 288 | * |
| 289 | * @param[in] parent Parent node for the \p node being inserted. |
| 290 | * @param[in] node The node being inserted. |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 291 | * @return 0 on success, nonzero in case of error, e.g. when the node is being inserted to an inappropriate place |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 292 | * in the data tree. |
| 293 | */ |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 294 | int lyd_insert(struct lyd_node *parent, struct lyd_node *node); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 295 | |
| 296 | /** |
Michal Vasko | 3f7dba1 | 2015-10-15 13:09:27 +0200 | [diff] [blame] | 297 | * @brief Insert the \p node element after the \p sibling element. If \p node and \p siblings are already |
Radek Krejci | ca7efb7 | 2016-01-18 13:06:01 +0100 | [diff] [blame] | 298 | * siblings (just moving \p node position), skip validation. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 299 | * |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 300 | * @param[in] sibling The data tree node before which the \p node will be inserted. |
| 301 | * @param[in] node The data tree node to be inserted. |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 302 | * @return 0 on success, nonzero in case of error, e.g. when the node is being inserted to an inappropriate place |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 303 | * in the data tree. |
| 304 | */ |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 305 | int lyd_insert_before(struct lyd_node *sibling, struct lyd_node *node); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 306 | |
| 307 | /** |
| 308 | * @brief Insert the \p node element after the \p sibling element. |
| 309 | * |
Michal Vasko | 3f7dba1 | 2015-10-15 13:09:27 +0200 | [diff] [blame] | 310 | * @param[in] sibling The data tree node before which the \p node will be inserted. If \p node and \p siblings |
Radek Krejci | ca7efb7 | 2016-01-18 13:06:01 +0100 | [diff] [blame] | 311 | * are already siblings (just moving \p node position), skip validation. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 312 | * @param[in] node The data tree node to be inserted. |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 313 | * @return 0 on success, nonzero in case of error, e.g. when the node is being inserted to an inappropriate place |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 314 | * in the data tree. |
| 315 | */ |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 316 | int lyd_insert_after(struct lyd_node *sibling, struct lyd_node *node); |
| 317 | |
| 318 | /** |
Radek Krejci | c5b6b91 | 2016-01-18 16:35:35 +0100 | [diff] [blame] | 319 | * @brief Search in the given data for instances of the provided schema node. |
| 320 | * |
| 321 | * The \p data is used to find the data root and function then searches in the whole tree and all sibling trees. |
| 322 | * |
| 323 | * @param[in] data A node in the data tree to search. |
| 324 | * @param[in] schema Schema node of the data nodes caller want to find. |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 325 | * @return Set of found data nodes (use ::ly_set#dset). If no data node is found, the returned set is empty. |
Radek Krejci | c5b6b91 | 2016-01-18 16:35:35 +0100 | [diff] [blame] | 326 | * In case of error, NULL is returned. |
| 327 | */ |
Radek Krejci | dc15443 | 2016-01-21 11:10:59 +0100 | [diff] [blame] | 328 | struct ly_set *lyd_get_node(const struct lyd_node *data, const struct lys_node *schema); |
Radek Krejci | c5b6b91 | 2016-01-18 16:35:35 +0100 | [diff] [blame] | 329 | |
| 330 | /** |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 331 | * @brief Validate \p node data subtree. |
| 332 | * |
| 333 | * @param[in] node Data subtree to be validated. |
| 334 | * @param[in] options Options for the inserting data to the target data tree options, see @ref parseroptions. |
| 335 | * @return 0 on success (if options include #LYD_OPT_FILTER, some nodes could still have been deleted as an optimization), |
| 336 | * nonzero in case of an error. |
| 337 | */ |
| 338 | int lyd_validate(struct lyd_node *node, int options); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 339 | |
| 340 | /** |
Michal Vasko | 55f60be | 2015-10-14 13:12:58 +0200 | [diff] [blame] | 341 | * @brief Unlink the specified data subtree. All referenced namespaces are copied. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 342 | * |
| 343 | * Note, that the node's connection with the schema tree is kept. Therefore, in case of |
| 344 | * reconnecting the node to a data tree using lyd_paste() it is necessary to paste it |
| 345 | * to the appropriate place in the data tree following the schema. |
| 346 | * |
| 347 | * @param[in] node Data tree node to be unlinked (together with all children). |
| 348 | * @return 0 for success, nonzero for error |
| 349 | */ |
| 350 | int lyd_unlink(struct lyd_node *node); |
| 351 | |
| 352 | /** |
| 353 | * @brief Free (and unlink) the specified data (sub)tree. |
| 354 | * |
| 355 | * @param[in] node Root of the (sub)tree to be freed. |
| 356 | */ |
| 357 | void lyd_free(struct lyd_node *node); |
| 358 | |
| 359 | /** |
Radek Krejci | 8146840 | 2016-01-07 13:52:40 +0100 | [diff] [blame] | 360 | * @brief Free (and unlink) the specified data (sub)tree and all its siblings (preceding as well as following). |
| 361 | * |
| 362 | * @param[in] node One of the siblings root element of the (sub)trees to be freed. |
| 363 | */ |
| 364 | void lyd_free_withsiblings(struct lyd_node *node); |
| 365 | |
| 366 | /** |
Radek Krejci | 134610e | 2015-10-20 17:15:34 +0200 | [diff] [blame] | 367 | * @brief Insert attribute into the data node. |
| 368 | * |
| 369 | * @param[in] parent Data node where to place the attribute |
Radek Krejci | 5f9e8c9 | 2015-10-30 10:01:06 +0100 | [diff] [blame] | 370 | * @param[in] name Attribute name including the prefix (prefix:name). Prefix must be the name of one of the |
| 371 | * schema in the \p parent's context. |
Radek Krejci | 134610e | 2015-10-20 17:15:34 +0200 | [diff] [blame] | 372 | * @param[in] value Attribute value |
| 373 | * @return pointer to the created attribute (which is already connected in \p parent) or NULL on error. |
| 374 | */ |
| 375 | struct lyd_attr *lyd_insert_attr(struct lyd_node *parent, const char *name, const char *value); |
| 376 | |
| 377 | /** |
Radek Krejci | 88f2930 | 2015-10-30 15:42:33 +0100 | [diff] [blame] | 378 | * @brief Destroy data attribute |
| 379 | * |
| 380 | * If the attribute to destroy is a member of a node attribute list, it is necessary to |
| 381 | * provide the node itself as \p parent to keep the list consistent. |
| 382 | * |
| 383 | * @param[in] ctx Context where the attribute was created (usually it is the context of the \p parent) |
| 384 | * @param[in] parent Parent node where the attribute is placed |
| 385 | * @param[in] attr Attribute to destroy |
| 386 | * @param[in] recursive Zero to destroy only the attribute, non-zero to destroy also all the subsequent attributes |
| 387 | * in the list. |
| 388 | */ |
| 389 | void lyd_free_attr(struct ly_ctx *ctx, struct lyd_node *parent, struct lyd_attr *attr, int recursive); |
| 390 | |
| 391 | /** |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 392 | * @brief Opaque internal structure, do not access it from outside. |
| 393 | */ |
| 394 | struct lyxml_elem; |
| 395 | |
| 396 | /** |
| 397 | * @brief Serialize anyxml content for further processing. |
| 398 | * |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 399 | * @param[in] anyxml Anyxml content from ::lyd_node_anyxml#value to serialize ax XML string |
Michal Vasko | ff4c283 | 2015-10-15 13:30:50 +0200 | [diff] [blame] | 400 | * @return Serialized content of the anyxml or NULL in case of error. Need to be freed after |
| 401 | * done using. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 402 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 403 | char *lyxml_serialize(const struct lyxml_elem *anyxml); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 404 | |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 405 | /**@} */ |
| 406 | |
| 407 | #ifdef __cplusplus |
| 408 | } |
| 409 | #endif |
| 410 | |
| 411 | #endif /* LY_TREE_DATA_H_ */ |