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" |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 29 | #include "xml.h" |
Mislav Novakovic | e251a65 | 2015-09-29 08:40:12 +0200 | [diff] [blame] | 30 | |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 31 | #ifdef __cplusplus |
| 32 | extern "C" { |
| 33 | #endif |
| 34 | |
| 35 | /** |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 36 | * @defgroup datatree Data Tree |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 37 | * @{ |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 38 | * |
| 39 | * Data structures and functions to manipulate and access instance data tree. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 40 | */ |
| 41 | |
| 42 | /** |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 43 | * @brief Data input/output formats supported by libyang [parser](@ref howtodataparsers) and |
| 44 | * [printer](@ref howtodataprinters) functions. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 45 | */ |
| 46 | typedef enum { |
| 47 | LYD_UNKNOWN, /**< unknown format, used as return value in case of error */ |
| 48 | LYD_XML, /**< XML format of the instance data */ |
Radek Krejci | 452fb95 | 2015-10-02 16:07:46 +0200 | [diff] [blame] | 49 | 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] | 50 | LYD_JSON, /**< JSON format of the instance data */ |
| 51 | } LYD_FORMAT; |
| 52 | |
| 53 | /** |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 54 | * @brief Attribute structure. |
| 55 | * |
Radek Krejci | 5f9e8c9 | 2015-10-30 10:01:06 +0100 | [diff] [blame] | 56 | * The structure provides information about attributes of a data element. Such attributes partially |
| 57 | * maps to annotations from draft-ietf-netmod-yang-metadata. In XML, they are represented as standard |
| 58 | * XML attrbutes. In JSON, they are represented as JSON elements starting with the '@' character |
| 59 | * (for more information, see the yang metadata draft. |
| 60 | * |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 61 | */ |
| 62 | struct lyd_attr { |
Radek Krejci | 5f9e8c9 | 2015-10-30 10:01:06 +0100 | [diff] [blame] | 63 | struct lyd_attr *next; /**< pointer to the next attribute of the same element */ |
| 64 | struct lys_module *module; /**< pointer to the attribute's module. |
| 65 | TODO when annotations will be supported, point to the annotation definition |
| 66 | and validate that the attribute is really defined there. Currently, we just |
| 67 | believe that it is defined in the module it says */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 68 | const char *name; /**< attribute name */ |
| 69 | const char *value; /**< attribute value */ |
| 70 | }; |
| 71 | |
| 72 | /** |
| 73 | * @brief node's value representation |
| 74 | */ |
| 75 | typedef union lyd_value_u { |
| 76 | const char *binary; /**< base64 encoded, NULL terminated string */ |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 77 | struct lys_type_bit **bit; /**< bitmap of pointers to the schema definition of the bit value that are set, |
| 78 | its size is always the number of defined bits in the schema */ |
Radek Krejci | 489773c | 2015-12-17 13:20:03 +0100 | [diff] [blame] | 79 | int8_t bln; /**< 0 as false, 1 as true */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 80 | int64_t dec64; /**< decimal64: value = dec64 / 10^fraction-digits */ |
| 81 | 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] | 82 | struct lys_ident *ident; /**< pointer to the schema definition of the identityref value */ |
Radek Krejci | 40f17b9 | 2016-02-03 14:30:43 +0100 | [diff] [blame] | 83 | struct lyd_node *instance; /**< pointer to the instance-identifier target, note that if the tree was modified, |
| 84 | the target (address) can be invalid - the pointer is correctly checked and updated |
| 85 | by lyd_validate() */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 86 | int8_t int8; /**< 8-bit signed integer */ |
| 87 | int16_t int16; /**< 16-bit signed integer */ |
| 88 | int32_t int32; /**< 32-bit signed integer */ |
| 89 | int64_t int64; /**< 64-bit signed integer */ |
| 90 | struct lyd_node *leafref; /**< pointer to the referenced leaf/leaflist instance in data tree */ |
| 91 | const char *string; /**< string */ |
| 92 | uint8_t uint8; /**< 8-bit unsigned integer */ |
| 93 | uint16_t uint16; /**< 16-bit signed integer */ |
| 94 | uint32_t uint32; /**< 32-bit signed integer */ |
| 95 | uint64_t uint64; /**< 64-bit signed integer */ |
| 96 | } lyd_val; |
| 97 | |
| 98 | /** |
Radek Krejci | ca7efb7 | 2016-01-18 13:06:01 +0100 | [diff] [blame] | 99 | * @defgroup validityflags Validity flags |
| 100 | * @ingroup datatree |
| 101 | * |
| 102 | * Validity flags for data nodes. |
| 103 | * |
| 104 | * @{ |
| 105 | */ |
| 106 | #define LYD_VAL_OK 0x00 /**< node is successfully validated including whole subtree */ |
| 107 | #define LYD_VAL_UNIQUE 0x01 /**< Unique value(s) changed, applicable only to ::lys_node_list data nodes */ |
| 108 | #define LYD_VAL_NOT 0xff /**< node was not validated yet */ |
| 109 | /** |
| 110 | * @} |
| 111 | */ |
| 112 | |
| 113 | /** |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 114 | * @brief Generic structure for a data node, directly applicable to the data nodes defined as #LYS_CONTAINER, #LYS_LIST |
| 115 | * and #LYS_CHOICE. |
| 116 | * |
| 117 | * Completely fits to containers and choices and is compatible (can be used interchangeably except the #child member) |
| 118 | * with all other lyd_node_* structures. All data nodes are provides as ::lyd_node structure by default. |
| 119 | * 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] | 120 | * ::lyd_node_leaf_list or ::lyd_node_anyxml structures. This structure fits only to #LYS_CONTAINER, #LYS_LIST and |
| 121 | * #LYS_CHOICE values. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 122 | * |
| 123 | * To traverse through all the child elements or attributes, use #LY_TREE_FOR or #LY_TREE_FOR_SAFE macro. |
| 124 | */ |
| 125 | struct lyd_node { |
| 126 | struct lys_node *schema; /**< pointer to the schema definition of this node */ |
Radek Krejci | ca7efb7 | 2016-01-18 13:06:01 +0100 | [diff] [blame] | 127 | uint8_t validity; /**< [validity flags](@ref validityflags) */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 128 | |
| 129 | struct lyd_attr *attr; /**< pointer to the list of attributes of this node */ |
| 130 | struct lyd_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 131 | struct lyd_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is |
| 132 | never NULL. If there is no sibling node, pointer points to the node |
| 133 | itself. In case of the first node, this pointer points to the last |
| 134 | node in the list. */ |
| 135 | struct lyd_node *parent; /**< pointer to the parent node, NULL in case of root node */ |
| 136 | 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] | 137 | structures represent end nodes, this member |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 138 | is replaced in those structures. Therefore, be careful with accessing |
| 139 | this member without having information about the node type from the schema's |
| 140 | ::lys_node#nodetype member. */ |
| 141 | }; |
| 142 | |
| 143 | /** |
Michal Vasko | 4c18331 | 2015-09-25 10:41:47 +0200 | [diff] [blame] | 144 | * @brief Structure for data nodes defined as #LYS_LEAF or #LYS_LEAFLIST. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 145 | * |
Michal Vasko | 4c18331 | 2015-09-25 10:41:47 +0200 | [diff] [blame] | 146 | * Extension for ::lyd_node structure. It replaces the ::lyd_node#child member by |
| 147 | * three new members (#value, #value_str and #value_type) to provide |
| 148 | * information about the value. The first five members (#schema, #attr, #next, |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 149 | * #prev and #parent) are compatible with the ::lyd_node's members. |
| 150 | * |
| 151 | * To traverse through all the child elements or attributes, use #LY_TREE_FOR or #LY_TREE_FOR_SAFE macro. |
| 152 | */ |
Michal Vasko | 4c18331 | 2015-09-25 10:41:47 +0200 | [diff] [blame] | 153 | struct lyd_node_leaf_list { |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 154 | struct lys_node *schema; /**< pointer to the schema definition of this node which is ::lys_node_leaflist |
| 155 | structure */ |
Radek Krejci | ca7efb7 | 2016-01-18 13:06:01 +0100 | [diff] [blame] | 156 | uint8_t validity; /**< [validity flags](@ref validityflags) */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 157 | |
| 158 | struct lyd_attr *attr; /**< pointer to the list of attributes of this node */ |
| 159 | struct lyd_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 160 | struct lyd_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is |
| 161 | never NULL. If there is no sibling node, pointer points to the node |
| 162 | itself. In case of the first node, this pointer points to the last |
| 163 | node in the list. */ |
| 164 | struct lyd_node *parent; /**< pointer to the parent node, NULL in case of root node */ |
| 165 | |
| 166 | /* struct lyd_node *child; should be here, but is not */ |
| 167 | |
| 168 | /* leaflist's specific members */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 169 | const char *value_str; /**< string representation of value (for comparison, printing,...) */ |
Radek Krejci | 2323892 | 2015-10-27 17:13:34 +0100 | [diff] [blame] | 170 | lyd_val value; /**< node's value representation */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 171 | LY_DATA_TYPE value_type; /**< type of the value in the node, mainly for union to avoid repeating of type detection */ |
| 172 | }; |
| 173 | |
| 174 | /** |
| 175 | * @brief Structure for data nodes defined as #LYS_ANYXML. |
| 176 | * |
| 177 | * Extension for ::lyd_node structure - replaces the ::lyd_node#child member by new #value member. The first five |
| 178 | * members (#schema, #attr, #next, #prev and #parent) are compatible with the ::lyd_node's members. |
| 179 | * |
| 180 | * To traverse through all the child elements or attributes, use #LY_TREE_FOR or #LY_TREE_FOR_SAFE macro. |
| 181 | */ |
| 182 | struct lyd_node_anyxml { |
| 183 | struct lys_node *schema; /**< pointer to the schema definition of this node which is ::lys_node_anyxml |
| 184 | structure */ |
Radek Krejci | ca7efb7 | 2016-01-18 13:06:01 +0100 | [diff] [blame] | 185 | uint8_t validity; /**< [validity flags](@ref validityflags) */ |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 186 | |
| 187 | struct lyd_attr *attr; /**< pointer to the list of attributes of this node */ |
| 188 | struct lyd_node *next; /**< pointer to the next sibling node (NULL if there is no one) */ |
| 189 | struct lyd_node *prev; /**< pointer to the previous sibling node \note Note that this pointer is |
| 190 | never NULL. If there is no sibling node, pointer points to the node |
| 191 | itself. In case of the first node, this pointer points to the last |
| 192 | node in the list. */ |
| 193 | struct lyd_node *parent; /**< pointer to the parent node, NULL in case of root node */ |
| 194 | |
| 195 | /* struct lyd_node *child; should be here, but is not */ |
| 196 | |
| 197 | /* anyxml's specific members */ |
| 198 | struct lyxml_elem *value; /**< anyxml name is the root element of value! */ |
| 199 | }; |
| 200 | |
| 201 | /** |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 202 | * @defgroup parseroptions Data parser options |
| 203 | * @ingroup datatree |
| 204 | * |
| 205 | * Various options to change the data tree parsers behavior. |
| 206 | * |
| 207 | * Default behavior: |
| 208 | * - in case of XML, parser reads all data from its input (file, memory, XML tree) including the case of not well-formed |
| 209 | * XML document (multiple top-level elements) and if there is an unknown element, it is skipped including its subtree |
| 210 | * (see the next point). This can be changed by the #LYD_OPT_NOSIBLINGS option which make parser to read only a single |
| 211 | * tree (with a single root element) from its input. |
| 212 | * - parser silently ignores the data without a matching node in schema trees. If the caller want to stop |
| 213 | * parsing in case of presence of unknown data, the #LYD_OPT_STRICT can be used. The strict mode is useful for |
| 214 | * NETCONF servers, since NETCONF clients should always send data according to the capabilities announced by the server. |
| 215 | * On the other hand, the default non-strict mode is useful for clients receiving data from NETCONF server since |
| 216 | * clients are not required to understand everything the server does. Of course, the optimal strategy for clients is |
| 217 | * to use filtering to get only the required data. Having an unknown element of the known namespace is always an error. |
| 218 | * The behavior can be changed by #LYD_OPT_STRICT option. |
| 219 | * - using obsolete statements (status set to obsolete) just generates a warning, but the processing continues. The |
| 220 | * behavior can be changed by #LYD_OPT_OBSOLETE option. |
| 221 | * - parser expects that the provided data provides complete datastore content (both the configuration and state data) |
| 222 | * and performs data validation according to all YANG rules. This can be a problem in case of representing NETCONF's |
| 223 | * subtree filter data, edit-config's data or other type of data set - such data do not represent a complete data set |
| 224 | * and some of the validation rules can fail. Therefore there are other options (within lower 8 bits) to make parser |
| 225 | * to accept such a data. |
| 226 | * @{ |
| 227 | */ |
| 228 | |
| 229 | #define LYD_OPT_DATA 0x00 /**< Default type of data - complete datastore content with configuration as well as |
| 230 | state data. */ |
| 231 | #define LYD_OPT_CONFIG 0x01 /**< A configuration datastore - complete datastore without state data. |
| 232 | Validation modifications: |
| 233 | - status data are not allowed */ |
| 234 | #define LYD_OPT_GET 0x02 /**< Data content from a NETCONF reply message to the NETCONF \<get\> operation. |
| 235 | Validation modifications: |
| 236 | - mandatory nodes can be omitted |
| 237 | - leafrefs and instance-identifier are not resolved |
| 238 | - list's keys/unique nodes are not required (so duplication is not checked) */ |
| 239 | #define LYD_OPT_GETCONFIG 0x04 /**< Data content from a NETCONF reply message to the NETCONF \<get-config\> operation |
| 240 | Validation modifications: |
| 241 | - mandatory nodes can be omitted |
| 242 | - leafrefs and instance-identifier are not resolved |
| 243 | - list's keys/unique nodes are not required (so duplication is not checked) |
| 244 | - status data are not allowed */ |
| 245 | #define LYD_OPT_EDIT 0x08 /**< Content of the NETCONF \<edit-config\>'s config element. |
| 246 | Validation modifications: |
| 247 | - mandatory nodes can be omitted |
| 248 | - leafrefs and instance-identifier are not resolved |
| 249 | - status data are not allowed */ |
| 250 | #define LYD_OPT_RPC 0x10 /**< Data represents RPC's input parameters. */ |
| 251 | #define LYD_OPT_RPCREPLY 0x20 /**< Data represents RPC's output parameters (maps to NETCONF <rpc-reply> data). */ |
| 252 | #define LYD_OPT_NOTIF 0x40 /**< Data represents an event notification data. */ |
| 253 | #define LYD_OPT_FILTER 0x80 /**< Data represents NETCONF subtree filter. Validation modifications: |
| 254 | - leafs/leaf-lists with no data are allowed (even not allowed e.g. by length restriction) |
| 255 | - multiple instances of container/leaf/.. are allowed |
| 256 | - list's keys/unique nodes are not required |
| 257 | - mandatory nodes can be omitted |
| 258 | - leafrefs and instance-identifier are not resolved |
| 259 | - data from different choice's branches are allowed */ |
| 260 | #define LYD_OPT_TYPEMASK 0xff /**< Mask to filter data type options. Always only a single data type option (only |
| 261 | single bit from the lower 8 bits) can be set. */ |
| 262 | |
| 263 | #define LYD_OPT_STRICT 0x0100 /**< Instead of silent ignoring data without schema definition, raise an error. */ |
| 264 | #define LYD_OPT_DESTRUCT 0x0200 /**< Free the provided XML tree during parsing the data. With this option, the |
| 265 | provided XML tree is affected and all succesfully parsed data are freed. |
| 266 | This option is applicable only to lyd_parse_xml() function. */ |
| 267 | #define LYD_OPT_OBSOLETE 0x0400 /**< Raise an error when an obsolete statement (status set to obsolete) is used. */ |
| 268 | #define LYD_OPT_NOSIBLINGS 0x0800 /**< Parse only a single XML tree from the input. This option applies only to |
| 269 | XML input data. */ |
Radek Krejci | 93fab98 | 2016-02-03 15:58:19 +0100 | [diff] [blame] | 270 | #define LYD_OPT_TRUSTED 0x1000 /**< Data comes from a trusted source and it is not needed to validate them. Data |
| 271 | are connected with the schema, but the most validation checks (mandatory nodes, |
| 272 | list instance uniqueness, etc.) are not performed. This option does not make |
| 273 | sense for lyd_validate() so it is ignored by this function. */ |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 274 | |
| 275 | /**@} parseroptions */ |
| 276 | |
| 277 | /** |
| 278 | * @brief Parse (and validate according to appropriate schema from the given context) data. |
| 279 | * |
| 280 | * In case of LY_XML format, the data string is parsed completely. It means that when it contains |
| 281 | * a non well-formed XML with multiple root elements, all those sibling XML trees are parsed. The |
| 282 | * returned data node is a root of the first tree with other trees connected via the next pointer. |
| 283 | * This behavior can be changed by #LYD_OPT_NOSIBLINGS option. |
| 284 | * |
| 285 | * @param[in] ctx Context to connect with the data tree being built here. |
| 286 | * @param[in] data Serialized data in the specified format. |
| 287 | * @param[in] format Format of the input data to be parsed. |
| 288 | * @param[in] options Parser options, see @ref parseroptions. |
| 289 | * @param[in] ... Additional argument must be supplied when #LYD_OPT_RPCREPLY value is specified in \p options. The |
| 290 | * argument is supposed to provide pointer to the RPC schema node for the reply's request |
| 291 | * (const struct ::lys_node* rpc). |
| 292 | * @return Pointer to the built data tree or NULL in case of empty \p data. To free the returned structure, |
| 293 | * use lyd_free(). In these cases, the function sets #ly_errno to LY_SUCCESS. In case of error, |
| 294 | * #ly_errno contains appropriate error code (see #LY_ERR). |
| 295 | */ |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 296 | struct lyd_node *lyd_parse_mem(struct ly_ctx *ctx, const char *data, LYD_FORMAT format, int options, ...); |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 297 | |
| 298 | /** |
| 299 | * @brief Read data from the given file descriptor. |
| 300 | * |
| 301 | * \note Current implementation supports only reading data from standard (disk) file, not from sockets, pipes, etc. |
| 302 | * |
| 303 | * In case of LY_XML format, the file content is parsed completely. It means that when it contains |
| 304 | * a non well-formed XML with multiple root elements, all those sibling XML trees are parsed. The |
| 305 | * returned data node is a root of the first tree with other trees connected via the next pointer. |
| 306 | * This behavior can be changed by #LYD_OPT_NOSIBLINGS option. |
| 307 | * |
| 308 | * @param[in] ctx Context to connect with the data tree being built here. |
| 309 | * @param[in] fd The standard file descriptor of the file containing the data tree in the specified format. |
| 310 | * @param[in] format Format of the input data to be parsed. |
| 311 | * @param[in] options Parser options, see @ref parseroptions. |
| 312 | * @param[in] ... Additional argument must be supplied when #LYD_OPT_RPCREPLY value is specified in \p options. The |
| 313 | * argument is supposed to provide pointer to the RPC schema node for the reply's request |
| 314 | * (const struct ::lys_node* rpc). |
| 315 | * @return Pointer to the built data tree or NULL in case of empty file. To free the returned structure, |
| 316 | * use lyd_free(). In these cases, the function sets #ly_errno to LY_SUCCESS. In case of error, |
| 317 | * #ly_errno contains appropriate error code (see #LY_ERR). |
| 318 | */ |
| 319 | struct lyd_node *lyd_parse_fd(struct ly_ctx *ctx, int fd, LYD_FORMAT format, int options, ...); |
| 320 | |
| 321 | /** |
| 322 | * @brief Read data from the given file path. |
| 323 | * |
| 324 | * In case of LY_XML format, the file content is parsed completely. It means that when it contains |
| 325 | * a non well-formed XML with multiple root elements, all those sibling XML trees are parsed. The |
| 326 | * returned data node is a root of the first tree with other trees connected via the next pointer. |
| 327 | * This behavior can be changed by #LYD_OPT_NOSIBLINGS option. |
| 328 | * |
| 329 | * @param[in] ctx Context to connect with the data tree being built here. |
| 330 | * @param[in] path Path to the file containing the data tree in the specified format. |
| 331 | * @param[in] format Format of the input data to be parsed. |
| 332 | * @param[in] options Parser options, see @ref parseroptions. |
| 333 | * @param[in] ... Additional argument must be supplied when #LYD_OPT_RPCREPLY value is specified in \p options. The |
| 334 | * argument is supposed to provide pointer to the RPC schema node for the reply's request |
| 335 | * (const struct ::lys_node* rpc). |
| 336 | * @return Pointer to the built data tree or NULL in case of empty file. To free the returned structure, |
| 337 | * use lyd_free(). In these cases, the function sets #ly_errno to LY_SUCCESS. In case of error, |
| 338 | * #ly_errno contains appropriate error code (see #LY_ERR). |
| 339 | */ |
| 340 | struct lyd_node *lyd_parse_path(struct ly_ctx *ctx, const char *path, LYD_FORMAT format, int options, ...); |
| 341 | |
| 342 | /** |
| 343 | * @brief Parse (and validate according to appropriate schema from the given context) XML tree. |
| 344 | * |
| 345 | * The output data tree is parsed from the given XML tree previously parsed by one of the |
| 346 | * lyxml_read* functions. |
| 347 | * |
Radek Krejci | 722b007 | 2016-02-01 17:09:45 +0100 | [diff] [blame] | 348 | * If there are some sibling elements of the \p root (data were read with #LYXML_PARSE_MULTIROOT option |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 349 | * or the provided root is a root element of a subtree), all the sibling nodes (previous as well as |
| 350 | * following) are processed as well. The returned data node is a root of the first tree with other |
| 351 | * trees connected via the next pointer. This behavior can be changed by #LYD_OPT_NOSIBLINGS option. |
| 352 | * |
| 353 | * When the function is used with #LYD_OPT_DESTRUCT, all the successfully parsed data including the |
| 354 | * XML \p root and all its siblings (if #LYD_OPT_NOSIBLINGS is not used) are freed. Only with |
| 355 | * #LYD_OPT_DESTRUCT option the \p root pointer is changed - if all the data are parsed, it is set |
| 356 | * to NULL, otherwise it will hold the XML tree without the successfully parsed elements. |
| 357 | * |
| 358 | * The context must be the same as the context used to parse XML tree by lyxml_read* function. |
| 359 | * |
| 360 | * @param[in] ctx Context to connect with the data tree being built here. |
| 361 | * @param[in,out] root XML tree to parse (convert) to data tree. By default, parser do not change the XML tree. However, |
| 362 | * when #LYD_OPT_DESTRUCT is specified in \p options, parser frees all successfully parsed data. |
| 363 | * @param[in] options Parser options, see @ref parseroptions. |
| 364 | * @param[in] ... Additional argument must be supplied when #LYD_OPT_RPCREPLY value is specified in \p options. The |
| 365 | * argument is supposed to provide pointer to the RPC schema node for the reply's request |
| 366 | * (const struct ::lys_node* rpc). |
| 367 | * @return Pointer to the built data tree or NULL in case of empty \p root. To free the returned structure, |
| 368 | * use lyd_free(). In these cases, the function sets #ly_errno to LY_SUCCESS. In case of error, |
| 369 | * #ly_errno contains appropriate error code (see #LY_ERR). |
| 370 | */ |
| 371 | struct lyd_node *lyd_parse_xml(struct ly_ctx *ctx, struct lyxml_elem **root, int options,...); |
| 372 | |
| 373 | /** |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 374 | * @brief Create a new container node in a data tree. |
| 375 | * |
| 376 | * @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] | 377 | * @param[in] module Module with the node being created. |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 378 | * @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] | 379 | * #LYS_NOTIF, or #LYS_RPC. |
Michal Vasko | 1dca688 | 2015-10-22 14:29:42 +0200 | [diff] [blame] | 380 | * @return New node, NULL on error. |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 381 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 382 | 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] | 383 | |
| 384 | /** |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 385 | * @brief Create a new leaf or leaflist node in a data tree with a string value that is converted to |
| 386 | * the actual value. |
| 387 | * |
| 388 | * @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] | 389 | * @param[in] module Module with the node being created. |
| 390 | * @param[in] name Schema node name of the new data node. |
Michal Vasko | 3e671b5 | 2015-10-23 16:23:15 +0200 | [diff] [blame] | 391 | * @param[in] val_str String form of the value of the node being created. In case the type is #LY_TYPE_INST |
| 392 | * 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] | 393 | * @return New node, NULL on error. |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 394 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 395 | 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] | 396 | const char *val_str); |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 397 | |
| 398 | /** |
Radek Krejci | b9b4d00 | 2016-01-18 13:08:51 +0100 | [diff] [blame] | 399 | * @brief Change value of a leaf node. |
| 400 | * |
| 401 | * Despite the prototype allows to provide a leaflist node as \p leaf parameter, only leafs are accepted. |
| 402 | * |
| 403 | * @param[in] leaf A leaf node to change. |
| 404 | * @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 |
| 405 | * or #LY_TYPE_IDENT, JSON node-id format is expected (nodes are prefixed with module names, not XML namespaces). |
| 406 | * @return 0 on success, non-zero on error. |
| 407 | */ |
| 408 | int lyd_change_leaf(struct lyd_node_leaf_list *leaf, const char *val_str); |
| 409 | |
| 410 | /** |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 411 | * @brief Create a new anyxml node in a data tree. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 412 | * |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 413 | * @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] | 414 | * @param[in] module Module with the node being created. |
| 415 | * @param[in] name Schema node name of the new data node. |
Michal Vasko | 8ea2b7f | 2015-09-29 14:30:53 +0200 | [diff] [blame] | 416 | * @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] | 417 | * @return New node, NULL on error. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 418 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 419 | 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] | 420 | const char *val_xml); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 421 | |
| 422 | /** |
Michal Vasko | 50c0a87 | 2016-01-13 14:34:11 +0100 | [diff] [blame] | 423 | * @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] | 424 | * |
Michal Vasko | 50c0a87 | 2016-01-13 14:34:11 +0100 | [diff] [blame] | 425 | * @param[in] schema Schema node of the container. |
Michal Vasko | 0df122f | 2015-12-14 13:38:21 +0100 | [diff] [blame] | 426 | * @return New node, NULL on error. |
| 427 | */ |
Michal Vasko | 50c0a87 | 2016-01-13 14:34:11 +0100 | [diff] [blame] | 428 | struct lyd_node *lyd_output_new(const struct lys_node *schema); |
| 429 | |
| 430 | /** |
| 431 | * @brief Create a new leaf or leaflist node in a data tree, whose schema parent is #LYS_OUTPUT. |
| 432 | * |
| 433 | * @param[in] schema Schema node of the leaf. |
| 434 | * @param[in] val_str String form of the value of the node being created. In case the type is #LY_TYPE_INST |
| 435 | * or #LY_TYPE_IDENT, JSON node-id format is expected (nodes are prefixed with module names, not XML namespaces). |
| 436 | * @return New node, NULL on error. |
| 437 | */ |
| 438 | struct lyd_node *lyd_output_new_leaf(const struct lys_node *schema, const char *val_str); |
| 439 | |
| 440 | /** |
| 441 | * @brief Create a new anyxml node in a data tree, whose schema parent is #LYS_OUTPUT. |
| 442 | * |
| 443 | * @param[in] schema Schema node of the leaf. |
| 444 | * @param[in] val_xml Value of the node being created. Must be a well-formed XML. |
| 445 | * @return New node, NULL on error. |
| 446 | */ |
| 447 | 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] | 448 | |
| 449 | /** |
Michal Vasko | c0797f8 | 2015-10-14 15:51:25 +0200 | [diff] [blame] | 450 | * @brief Create a copy of the specified data tree \p node. Namespaces are copied as needed, |
| 451 | * schema references are kept the same. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 452 | * |
| 453 | * @param[in] node Data tree node to be duplicated. |
| 454 | * @param[in] recursive 1 if all children are supposed to be also duplicated. |
| 455 | * @return Created copy of the provided data \p node. |
| 456 | */ |
Michal Vasko | 1e62a09 | 2015-12-01 12:27:20 +0100 | [diff] [blame] | 457 | struct lyd_node *lyd_dup(const struct lyd_node *node, int recursive); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 458 | |
| 459 | /** |
| 460 | * @brief Insert the \p node element as child to the \p parent element. The \p node is inserted as a last child of the |
| 461 | * \p parent. |
| 462 | * |
| 463 | * If the node is part of some other tree, it is automatically unlinked. |
| 464 | * If the node is the first node of a node list (with no parent), all |
| 465 | * the subsequent nodes are also inserted. |
| 466 | * |
| 467 | * @param[in] parent Parent node for the \p node being inserted. |
| 468 | * @param[in] node The node being inserted. |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 469 | * @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] | 470 | * in the data tree. |
| 471 | */ |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 472 | int lyd_insert(struct lyd_node *parent, struct lyd_node *node); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 473 | |
| 474 | /** |
Michal Vasko | 3f7dba1 | 2015-10-15 13:09:27 +0200 | [diff] [blame] | 475 | * @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] | 476 | * siblings (just moving \p node position), skip validation. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 477 | * |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 478 | * @param[in] sibling The data tree node before which the \p node will be inserted. |
| 479 | * @param[in] node The data tree node to be inserted. |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 480 | * @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] | 481 | * in the data tree. |
| 482 | */ |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 483 | int lyd_insert_before(struct lyd_node *sibling, struct lyd_node *node); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 484 | |
| 485 | /** |
| 486 | * @brief Insert the \p node element after the \p sibling element. |
| 487 | * |
Michal Vasko | 3f7dba1 | 2015-10-15 13:09:27 +0200 | [diff] [blame] | 488 | * @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] | 489 | * are already siblings (just moving \p node position), skip validation. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 490 | * @param[in] node The data tree node to be inserted. |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 491 | * @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] | 492 | * in the data tree. |
| 493 | */ |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 494 | int lyd_insert_after(struct lyd_node *sibling, struct lyd_node *node); |
| 495 | |
| 496 | /** |
Michal Vasko | 105cef1 | 2016-02-04 12:06:26 +0100 | [diff] [blame] | 497 | * @brief Search in the given data for instances of nodes matching the provided XPath expression. |
| 498 | * |
| 499 | * The \p data is used to find the data root and function then searches in the whole tree and all sibling trees. |
| 500 | * |
| 501 | * @param[in] data A node in the data tree considered the context node. If the node is a configuration one, |
| 502 | * any state nodes in its tree are not accessible! |
| 503 | * @param[in] expr XPath expression filtering the matching nodes. |
| 504 | * @return Set of found data nodes (use dset member of ::ly_set). If no nodes are matching \p expr or the result |
| 505 | * would be a number, a string, or a boolean, the returned set is empty. In case of an error, NULL is returned. |
| 506 | */ |
| 507 | struct ly_set *lyd_get_node(const struct lyd_node *data, const char *expr); |
| 508 | |
| 509 | /** |
Radek Krejci | c5b6b91 | 2016-01-18 16:35:35 +0100 | [diff] [blame] | 510 | * @brief Search in the given data for instances of the provided schema node. |
| 511 | * |
| 512 | * The \p data is used to find the data root and function then searches in the whole tree and all sibling trees. |
| 513 | * |
| 514 | * @param[in] data A node in the data tree to search. |
| 515 | * @param[in] schema Schema node of the data nodes caller want to find. |
Radek Krejci | 2342cf6 | 2016-01-29 16:48:23 +0100 | [diff] [blame] | 516 | * @return Set of found data nodes (use dset member of ::ly_set). If no data node is found, the returned set is empty. |
Radek Krejci | c5b6b91 | 2016-01-18 16:35:35 +0100 | [diff] [blame] | 517 | * In case of error, NULL is returned. |
| 518 | */ |
Michal Vasko | 105cef1 | 2016-02-04 12:06:26 +0100 | [diff] [blame] | 519 | struct ly_set *lyd_get_node2(const struct lyd_node *data, const struct lys_node *schema); |
Radek Krejci | c5b6b91 | 2016-01-18 16:35:35 +0100 | [diff] [blame] | 520 | |
| 521 | /** |
Michal Vasko | 6a1ab6f | 2016-02-04 12:08:11 +0100 | [diff] [blame^] | 522 | * @brief Get all key nodes of a \p list instance. |
| 523 | * |
| 524 | * @param[in] list List node, whose keys will be searched for. |
| 525 | * @return Set of list keys (use dset member of ::ly_set). If no keys are found/defined, the returned set is empty. |
| 526 | * In case of error, NULL is returned. |
| 527 | */ |
| 528 | struct ly_set *lyd_get_list_keys(const struct lyd_node *list); |
| 529 | |
| 530 | /** |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 531 | * @brief Validate \p node data subtree. |
| 532 | * |
Radek Krejci | 15c733d | 2016-01-27 16:31:17 +0100 | [diff] [blame] | 533 | * @param[in] node Data tree to be validated. |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 534 | * @param[in] options Options for the inserting data to the target data tree options, see @ref parseroptions. |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 535 | * @param[in] ... libyang context for the data (used only in case the \p node is NULL, so in case of checking empty data tree) |
| 536 | * @return 0 on success (if options include #LYD_OPT_FILTER, some nodes can be deleted as an |
Radek Krejci | 15c733d | 2016-01-27 16:31:17 +0100 | [diff] [blame] | 537 | * optimization, which can have a bad consequences when the \p node stores a subtree instead of a tree with |
| 538 | * a top-level node(s)), nonzero in case of an error. |
Michal Vasko | 2433739 | 2015-10-16 09:58:16 +0200 | [diff] [blame] | 539 | */ |
Radek Krejci | 2342cf6 | 2016-01-29 16:48:23 +0100 | [diff] [blame] | 540 | int lyd_validate(struct lyd_node *node, int options, ...); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 541 | |
| 542 | /** |
Michal Vasko | 55f60be | 2015-10-14 13:12:58 +0200 | [diff] [blame] | 543 | * @brief Unlink the specified data subtree. All referenced namespaces are copied. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 544 | * |
| 545 | * Note, that the node's connection with the schema tree is kept. Therefore, in case of |
| 546 | * reconnecting the node to a data tree using lyd_paste() it is necessary to paste it |
| 547 | * to the appropriate place in the data tree following the schema. |
| 548 | * |
| 549 | * @param[in] node Data tree node to be unlinked (together with all children). |
| 550 | * @return 0 for success, nonzero for error |
| 551 | */ |
| 552 | int lyd_unlink(struct lyd_node *node); |
| 553 | |
| 554 | /** |
| 555 | * @brief Free (and unlink) the specified data (sub)tree. |
| 556 | * |
| 557 | * @param[in] node Root of the (sub)tree to be freed. |
| 558 | */ |
| 559 | void lyd_free(struct lyd_node *node); |
| 560 | |
| 561 | /** |
Radek Krejci | 8146840 | 2016-01-07 13:52:40 +0100 | [diff] [blame] | 562 | * @brief Free (and unlink) the specified data (sub)tree and all its siblings (preceding as well as following). |
| 563 | * |
| 564 | * @param[in] node One of the siblings root element of the (sub)trees to be freed. |
| 565 | */ |
| 566 | void lyd_free_withsiblings(struct lyd_node *node); |
| 567 | |
| 568 | /** |
Radek Krejci | 134610e | 2015-10-20 17:15:34 +0200 | [diff] [blame] | 569 | * @brief Insert attribute into the data node. |
| 570 | * |
| 571 | * @param[in] parent Data node where to place the attribute |
Radek Krejci | 5f9e8c9 | 2015-10-30 10:01:06 +0100 | [diff] [blame] | 572 | * @param[in] name Attribute name including the prefix (prefix:name). Prefix must be the name of one of the |
| 573 | * schema in the \p parent's context. |
Radek Krejci | 134610e | 2015-10-20 17:15:34 +0200 | [diff] [blame] | 574 | * @param[in] value Attribute value |
| 575 | * @return pointer to the created attribute (which is already connected in \p parent) or NULL on error. |
| 576 | */ |
| 577 | struct lyd_attr *lyd_insert_attr(struct lyd_node *parent, const char *name, const char *value); |
| 578 | |
| 579 | /** |
Radek Krejci | 88f2930 | 2015-10-30 15:42:33 +0100 | [diff] [blame] | 580 | * @brief Destroy data attribute |
| 581 | * |
| 582 | * If the attribute to destroy is a member of a node attribute list, it is necessary to |
| 583 | * provide the node itself as \p parent to keep the list consistent. |
| 584 | * |
| 585 | * @param[in] ctx Context where the attribute was created (usually it is the context of the \p parent) |
| 586 | * @param[in] parent Parent node where the attribute is placed |
| 587 | * @param[in] attr Attribute to destroy |
| 588 | * @param[in] recursive Zero to destroy only the attribute, non-zero to destroy also all the subsequent attributes |
| 589 | * in the list. |
| 590 | */ |
| 591 | void lyd_free_attr(struct ly_ctx *ctx, struct lyd_node *parent, struct lyd_attr *attr, int recursive); |
| 592 | |
| 593 | /** |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 594 | * @brief Print data tree in the specified format. |
| 595 | * |
| 596 | * Same as lyd_print(), but it allocates memory and store the data into it. |
| 597 | * It is up to caller to free the returned string by free(). |
| 598 | * |
| 599 | * @param[out] strp Pointer to store the resulting dump. |
| 600 | * @param[in] root Root node of the data tree to print. It can be actually any (not only real root) |
| 601 | * node of the data tree to print the specific subtree. |
| 602 | * @param[in] format Data output format. |
| 603 | * @param[in] options [printer flags](@ref printerflags). |
| 604 | * @return 0 on success, 1 on failure (#ly_errno is set). |
| 605 | */ |
| 606 | int lyd_print_mem(char **strp, const struct lyd_node *root, LYD_FORMAT format, int options); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 607 | |
| 608 | /** |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 609 | * @brief Print data tree in the specified format. |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 610 | * |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 611 | * Same as lyd_print(), but output is written into the specified file descriptor. |
| 612 | * |
| 613 | * @param[in] root Root node of the data tree to print. It can be actually any (not only real root) |
| 614 | * node of the data tree to print the specific subtree. |
| 615 | * @param[in] fd File descriptor where to print the data. |
| 616 | * @param[in] format Data output format. |
| 617 | * @param[in] options [printer flags](@ref printerflags). |
| 618 | * @return 0 on success, 1 on failure (#ly_errno is set). |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 619 | */ |
Radek Krejci | def5002 | 2016-02-01 16:38:32 +0100 | [diff] [blame] | 620 | int lyd_print_fd(int fd, const struct lyd_node *root, LYD_FORMAT format, int options); |
| 621 | |
| 622 | /** |
| 623 | * @brief Print data tree in the specified format. |
| 624 | * |
| 625 | * To write data into a file descriptor, use lyd_print_fd(). |
| 626 | * |
| 627 | * @param[in] root Root node of the data tree to print. It can be actually any (not only real root) |
| 628 | * node of the data tree to print the specific subtree. |
| 629 | * @param[in] f File stream where to print the data. |
| 630 | * @param[in] format Data output format. |
| 631 | * @param[in] options [printer flags](@ref printerflags). |
| 632 | * @return 0 on success, 1 on failure (#ly_errno is set). |
| 633 | */ |
| 634 | int lyd_print_file(FILE *f, const struct lyd_node *root, LYD_FORMAT format, int options); |
| 635 | |
| 636 | /** |
| 637 | * @brief Print data tree in the specified format. |
| 638 | * |
| 639 | * Same as lyd_print(), but output is written via provided callback. |
| 640 | * |
| 641 | * @param[in] root Root node of the data tree to print. It can be actually any (not only real root) |
| 642 | * node of the data tree to print the specific subtree. |
| 643 | * @param[in] writeclb Callback function to write the data (see write(1)). |
| 644 | * @param[in] arg Optional caller-specific argument to be passed to the \p writeclb callback. |
| 645 | * @param[in] format Data output format. |
| 646 | * @param[in] options [printer flags](@ref printerflags). |
| 647 | * @return 0 on success, 1 on failure (#ly_errno is set). |
| 648 | */ |
| 649 | int lyd_print_clb(ssize_t (*writeclb)(void *arg, const void *buf, size_t count), void *arg, |
| 650 | const struct lyd_node *root, LYD_FORMAT format, int options); |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 651 | |
Michal Vasko | 2d162e1 | 2015-09-24 14:33:29 +0200 | [diff] [blame] | 652 | /**@} */ |
| 653 | |
| 654 | #ifdef __cplusplus |
| 655 | } |
| 656 | #endif |
| 657 | |
| 658 | #endif /* LY_TREE_DATA_H_ */ |