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 | /** |
| 93 | * @brief Generic structure for a data node, directly applicable to the data nodes defined as #LYS_CONTAINER, #LYS_LIST |
| 94 | * and #LYS_CHOICE. |
| 95 | * |
| 96 | * Completely fits to containers and choices and is compatible (can be used interchangeably except the #child member) |
| 97 | * with all other lyd_node_* structures. All data nodes are provides as ::lyd_node structure by default. |
| 98 | * According to the schema's ::lys_node#nodetype member, the specific object is supposed to be cast to |
Radek Krejci | ee36089 | 2015-10-06 11:23:14 +0200 | [diff] [blame] | 99 | * ::lyd_node_leaf_list or ::lyd_node_anyxml structures. This structure fits only to |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 100 | * #LYS_CONTAINER and #LYS_CHOICE values. |
| 101 | * |
| 102 | * To traverse through all the child elements or attributes, use #LY_TREE_FOR or #LY_TREE_FOR_SAFE macro. |
| 103 | */ |
| 104 | struct lyd_node { |
| 105 | struct lys_node *schema; /**< pointer to the schema definition of this node */ |
| 106 | |
| 107 | struct lyd_attr *attr; /**< pointer to the list of attributes of this node */ |
| 108 | struct lyd_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 109 | struct lyd_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is |
| 110 | never NULL. If there is no sibling node, pointer points to the node |
| 111 | itself. In case of the first node, this pointer points to the last |
| 112 | node in the list. */ |
| 113 | struct lyd_node *parent; /**< pointer to the parent node, NULL in case of root node */ |
| 114 | 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] | 115 | structures represent end nodes, this member |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 116 | is replaced in those structures. Therefore, be careful with accessing |
| 117 | this member without having information about the node type from the schema's |
| 118 | ::lys_node#nodetype member. */ |
| 119 | }; |
| 120 | |
| 121 | /** |
Michal Vasko | 4c18331 | 2015-09-25 10:41:47 +0200 | [diff] [blame] | 122 | * @brief Structure for data nodes defined as #LYS_LEAF or #LYS_LEAFLIST. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 123 | * |
Michal Vasko | 4c18331 | 2015-09-25 10:41:47 +0200 | [diff] [blame] | 124 | * Extension for ::lyd_node structure. It replaces the ::lyd_node#child member by |
| 125 | * three new members (#value, #value_str and #value_type) to provide |
| 126 | * information about the value. The first five members (#schema, #attr, #next, |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 127 | * #prev and #parent) are compatible with the ::lyd_node's members. |
| 128 | * |
| 129 | * To traverse through all the child elements or attributes, use #LY_TREE_FOR or #LY_TREE_FOR_SAFE macro. |
| 130 | */ |
Michal Vasko | 4c18331 | 2015-09-25 10:41:47 +0200 | [diff] [blame] | 131 | struct lyd_node_leaf_list { |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 132 | struct lys_node *schema; /**< pointer to the schema definition of this node which is ::lys_node_leaflist |
| 133 | structure */ |
| 134 | |
| 135 | struct lyd_attr *attr; /**< pointer to the list of attributes of this node */ |
| 136 | struct lyd_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 137 | struct lyd_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is |
| 138 | never NULL. If there is no sibling node, pointer points to the node |
| 139 | itself. In case of the first node, this pointer points to the last |
| 140 | node in the list. */ |
| 141 | struct lyd_node *parent; /**< pointer to the parent node, NULL in case of root node */ |
| 142 | |
| 143 | /* struct lyd_node *child; should be here, but is not */ |
| 144 | |
| 145 | /* leaflist's specific members */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 146 | const char *value_str; /**< string representation of value (for comparison, printing,...) */ |
Radek Krejci | 2323892 | 2015-10-27 17:13:34 +0100 | [diff] [blame] | 147 | lyd_val value; /**< node's value representation */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 148 | LY_DATA_TYPE value_type; /**< type of the value in the node, mainly for union to avoid repeating of type detection */ |
| 149 | }; |
| 150 | |
| 151 | /** |
| 152 | * @brief Structure for data nodes defined as #LYS_ANYXML. |
| 153 | * |
| 154 | * Extension for ::lyd_node structure - replaces the ::lyd_node#child member by new #value member. The first five |
| 155 | * members (#schema, #attr, #next, #prev and #parent) are compatible with the ::lyd_node's members. |
| 156 | * |
| 157 | * To traverse through all the child elements or attributes, use #LY_TREE_FOR or #LY_TREE_FOR_SAFE macro. |
| 158 | */ |
| 159 | struct lyd_node_anyxml { |
| 160 | struct lys_node *schema; /**< pointer to the schema definition of this node which is ::lys_node_anyxml |
| 161 | structure */ |
| 162 | |
| 163 | struct lyd_attr *attr; /**< pointer to the list of attributes of this node */ |
| 164 | struct lyd_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 165 | struct lyd_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is |
| 166 | never NULL. If there is no sibling node, pointer points to the node |
| 167 | itself. In case of the first node, this pointer points to the last |
| 168 | node in the list. */ |
| 169 | struct lyd_node *parent; /**< pointer to the parent node, NULL in case of root node */ |
| 170 | |
| 171 | /* struct lyd_node *child; should be here, but is not */ |
| 172 | |
| 173 | /* anyxml's specific members */ |
| 174 | struct lyxml_elem *value; /**< anyxml name is the root element of value! */ |
| 175 | }; |
| 176 | |
| 177 | /** |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 178 | * @brief Create a new container node in a data tree. |
| 179 | * |
| 180 | * @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] | 181 | * @param[in] module Module with the node being created. |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 182 | * @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] | 183 | * #LYS_NOTIF, or #LYS_RPC. |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 184 | * @return New node, NULL on error. |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 185 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 186 | 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] | 187 | |
| 188 | /** |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 189 | * @brief Create a new leaf or leaflist node in a data tree with a string value that is converted to |
| 190 | * the actual value. |
| 191 | * |
| 192 | * @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] | 193 | * @param[in] module Module with the node being created. |
| 194 | * @param[in] name Schema node name of the new data node. |
Michal Vasko | 3e671b5 | 2015-10-23 16:23:15 +0200 | [diff] [blame] | 195 | * @param[in] val_str String form of the value of the node being created. In case the type is #LY_TYPE_INST |
| 196 | * 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] | 197 | * @return New node, NULL on error. |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 198 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 199 | 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] | 200 | const char *val_str); |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 201 | |
| 202 | /** |
| 203 | * @brief Create a new anyxml node in a data tree. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 204 | * |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 205 | * @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] | 206 | * @param[in] module Module with the node being created. |
| 207 | * @param[in] name Schema node name of the new data node. |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 208 | * @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] | 209 | * @return New node, NULL on error. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 210 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 211 | 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] | 212 | const char *val_xml); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 213 | |
| 214 | /** |
Michal Vasko | 50c0a87 | 2016-01-13 14:34:11 +0100 | [diff] [blame^] | 215 | * @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] | 216 | * |
Michal Vasko | 50c0a87 | 2016-01-13 14:34:11 +0100 | [diff] [blame^] | 217 | * @param[in] schema Schema node of the container. |
Michal Vasko | 0df122f | 2015-12-14 13:38:21 +0100 | [diff] [blame] | 218 | * @return New node, NULL on error. |
| 219 | */ |
Michal Vasko | 50c0a87 | 2016-01-13 14:34:11 +0100 | [diff] [blame^] | 220 | struct lyd_node *lyd_output_new(const struct lys_node *schema); |
| 221 | |
| 222 | /** |
| 223 | * @brief Create a new leaf or leaflist node in a data tree, whose schema parent is #LYS_OUTPUT. |
| 224 | * |
| 225 | * @param[in] schema Schema node of the leaf. |
| 226 | * @param[in] val_str String form of the value of the node being created. 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 New node, NULL on error. |
| 229 | */ |
| 230 | struct lyd_node *lyd_output_new_leaf(const struct lys_node *schema, const char *val_str); |
| 231 | |
| 232 | /** |
| 233 | * @brief Create a new anyxml node in a data tree, whose schema parent is #LYS_OUTPUT. |
| 234 | * |
| 235 | * @param[in] schema Schema node of the leaf. |
| 236 | * @param[in] val_xml Value of the node being created. Must be a well-formed XML. |
| 237 | * @return New node, NULL on error. |
| 238 | */ |
| 239 | 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] | 240 | |
| 241 | /** |
Michal Vasko | c0797f8 | 2015-10-14 15:51:25 +0200 | [diff] [blame] | 242 | * @brief Create a copy of the specified data tree \p node. Namespaces are copied as needed, |
| 243 | * schema references are kept the same. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 244 | * |
| 245 | * @param[in] node Data tree node to be duplicated. |
| 246 | * @param[in] recursive 1 if all children are supposed to be also duplicated. |
| 247 | * @return Created copy of the provided data \p node. |
| 248 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 249 | struct lyd_node *lyd_dup(const struct lyd_node *node, int recursive); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 250 | |
| 251 | /** |
| 252 | * @brief Insert the \p node element as child to the \p parent element. The \p node is inserted as a last child of the |
| 253 | * \p parent. |
| 254 | * |
| 255 | * If the node is part of some other tree, it is automatically unlinked. |
| 256 | * If the node is the first node of a node list (with no parent), all |
| 257 | * the subsequent nodes are also inserted. |
| 258 | * |
| 259 | * @param[in] parent Parent node for the \p node being inserted. |
| 260 | * @param[in] node The node being inserted. |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 261 | * @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] | 262 | * in the data tree. |
| 263 | */ |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 264 | int lyd_insert(struct lyd_node *parent, struct lyd_node *node); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 265 | |
| 266 | /** |
Michal Vasko | 3f7dba1 | 2015-10-15 13:09:27 +0200 | [diff] [blame] | 267 | * @brief Insert the \p node element after the \p sibling element. If \p node and \p siblings are already |
| 268 | * siblings (just moving \p node position), skip validation (\p options are ignored). |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 269 | * |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 270 | * @param[in] sibling The data tree node before which the \p node will be inserted. |
| 271 | * @param[in] node The data tree node to be inserted. |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 272 | * @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] | 273 | * in the data tree. |
| 274 | */ |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 275 | int lyd_insert_before(struct lyd_node *sibling, struct lyd_node *node); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 276 | |
| 277 | /** |
| 278 | * @brief Insert the \p node element after the \p sibling element. |
| 279 | * |
Michal Vasko | 3f7dba1 | 2015-10-15 13:09:27 +0200 | [diff] [blame] | 280 | * @param[in] sibling The data tree node before which the \p node will be inserted. If \p node and \p siblings |
| 281 | * are already siblings (just moving \p node position), skip validation (\p options are ignored). |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 282 | * @param[in] node The data tree node to be inserted. |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 283 | * @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] | 284 | * in the data tree. |
| 285 | */ |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 286 | int lyd_insert_after(struct lyd_node *sibling, struct lyd_node *node); |
| 287 | |
| 288 | /** |
| 289 | * @brief Validate \p node data subtree. |
| 290 | * |
| 291 | * @param[in] node Data subtree to be validated. |
| 292 | * @param[in] options Options for the inserting data to the target data tree options, see @ref parseroptions. |
| 293 | * @return 0 on success (if options include #LYD_OPT_FILTER, some nodes could still have been deleted as an optimization), |
| 294 | * nonzero in case of an error. |
| 295 | */ |
| 296 | int lyd_validate(struct lyd_node *node, int options); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 297 | |
| 298 | /** |
Michal Vasko | 55f60be | 2015-10-14 13:12:58 +0200 | [diff] [blame] | 299 | * @brief Unlink the specified data subtree. All referenced namespaces are copied. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 300 | * |
| 301 | * Note, that the node's connection with the schema tree is kept. Therefore, in case of |
| 302 | * reconnecting the node to a data tree using lyd_paste() it is necessary to paste it |
| 303 | * to the appropriate place in the data tree following the schema. |
| 304 | * |
| 305 | * @param[in] node Data tree node to be unlinked (together with all children). |
| 306 | * @return 0 for success, nonzero for error |
| 307 | */ |
| 308 | int lyd_unlink(struct lyd_node *node); |
| 309 | |
| 310 | /** |
| 311 | * @brief Free (and unlink) the specified data (sub)tree. |
| 312 | * |
| 313 | * @param[in] node Root of the (sub)tree to be freed. |
| 314 | */ |
| 315 | void lyd_free(struct lyd_node *node); |
| 316 | |
| 317 | /** |
Radek Krejci | 8146840 | 2016-01-07 13:52:40 +0100 | [diff] [blame] | 318 | * @brief Free (and unlink) the specified data (sub)tree and all its siblings (preceding as well as following). |
| 319 | * |
| 320 | * @param[in] node One of the siblings root element of the (sub)trees to be freed. |
| 321 | */ |
| 322 | void lyd_free_withsiblings(struct lyd_node *node); |
| 323 | |
| 324 | /** |
Radek Krejci | 134610e | 2015-10-20 17:15:34 +0200 | [diff] [blame] | 325 | * @brief Insert attribute into the data node. |
| 326 | * |
| 327 | * @param[in] parent Data node where to place the attribute |
Radek Krejci | 5f9e8c9 | 2015-10-30 10:01:06 +0100 | [diff] [blame] | 328 | * @param[in] name Attribute name including the prefix (prefix:name). Prefix must be the name of one of the |
| 329 | * schema in the \p parent's context. |
Radek Krejci | 134610e | 2015-10-20 17:15:34 +0200 | [diff] [blame] | 330 | * @param[in] value Attribute value |
| 331 | * @return pointer to the created attribute (which is already connected in \p parent) or NULL on error. |
| 332 | */ |
| 333 | struct lyd_attr *lyd_insert_attr(struct lyd_node *parent, const char *name, const char *value); |
| 334 | |
| 335 | /** |
Radek Krejci | 88f2930 | 2015-10-30 15:42:33 +0100 | [diff] [blame] | 336 | * @brief Destroy data attribute |
| 337 | * |
| 338 | * If the attribute to destroy is a member of a node attribute list, it is necessary to |
| 339 | * provide the node itself as \p parent to keep the list consistent. |
| 340 | * |
| 341 | * @param[in] ctx Context where the attribute was created (usually it is the context of the \p parent) |
| 342 | * @param[in] parent Parent node where the attribute is placed |
| 343 | * @param[in] attr Attribute to destroy |
| 344 | * @param[in] recursive Zero to destroy only the attribute, non-zero to destroy also all the subsequent attributes |
| 345 | * in the list. |
| 346 | */ |
| 347 | void lyd_free_attr(struct ly_ctx *ctx, struct lyd_node *parent, struct lyd_attr *attr, int recursive); |
| 348 | |
| 349 | /** |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 350 | * @brief Opaque internal structure, do not access it from outside. |
| 351 | */ |
| 352 | struct lyxml_elem; |
| 353 | |
| 354 | /** |
| 355 | * @brief Serialize anyxml content for further processing. |
| 356 | * |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 357 | * @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] | 358 | * @return Serialized content of the anyxml or NULL in case of error. Need to be freed after |
| 359 | * done using. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 360 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 361 | char *lyxml_serialize(const struct lyxml_elem *anyxml); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 362 | |
| 363 | /** |
| 364 | * @brief Structure to hold a set of (not necessary somehow connected) ::lyd_node objects. |
| 365 | * |
| 366 | * To free the structure, use lyd_set_free() function, to manipulate with the structure, use other |
| 367 | * lyd_set_* functions. |
| 368 | */ |
| 369 | struct lyd_set { |
| 370 | unsigned int size; /**< allocated size of the set array */ |
| 371 | unsigned int number; /**< number of elements in (used size of) the set array */ |
| 372 | struct lyd_node **set; /**< array of pointers to a ::lyd_node objects */ |
| 373 | }; |
| 374 | |
| 375 | /** |
| 376 | * @brief Create and initiate new ::lyd_set structure. |
| 377 | * |
| 378 | * @return Created ::lyd_set structure or NULL in case of error. |
| 379 | */ |
| 380 | struct lyd_set *lyd_set_new(void); |
| 381 | |
| 382 | /** |
| 383 | * @brief Add a ::lyd_node object into the set |
| 384 | * |
| 385 | * @param[in] set Set where the \p node will be added. |
| 386 | * @param[in] node The ::lyd_node object to be added into the \p set; |
| 387 | * @return 0 on success |
| 388 | */ |
| 389 | int lyd_set_add(struct lyd_set *set, struct lyd_node *node); |
| 390 | |
| 391 | /** |
| 392 | * @brief Free the ::lyd_set data. Frees only the set structure content, not the referred data. |
| 393 | * |
| 394 | * @param[in] set The set to be freed. |
| 395 | */ |
| 396 | void lyd_set_free(struct lyd_set *set); |
| 397 | |
| 398 | /**@} */ |
| 399 | |
| 400 | #ifdef __cplusplus |
| 401 | } |
| 402 | #endif |
| 403 | |
| 404 | #endif /* LY_TREE_DATA_H_ */ |