libyang  1.0.253
YANG data modeling language library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
tree_data.h File Reference

libyang representation of data trees. More...

#include <stddef.h>
#include <stdint.h>
#include "libyang.h"
#include "tree_schema.h"
#include "xml.h"
Include dependency graph for tree_data.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

union  lyd_value_u
 node's value representation More...
 
struct  lyd_attr
 Attribute structure. More...
 
struct  lyd_node
 Generic structure for a data node, directly applicable to the data nodes defined as LYS_CONTAINER, LYS_LIST and LYS_CHOICE. More...
 
struct  lyd_node_leaf_list
 Structure for data nodes defined as LYS_LEAF or LYS_LEAFLIST. More...
 
union  lyd_anydata_value
 Anydata value union. More...
 
struct  lyd_node_anydata
 Structure for data nodes defined as LYS_ANYDATA or LYS_ANYXML. More...
 
struct  lyd_difflist
 Structure for the result of lyd_diff(), describing differences between two data trees. More...
 

Macros

#define LYD_VAL_OK   0x00
 
#define LYD_VAL_DUP   0x01
 
#define LYD_VAL_UNIQUE   0x02
 
#define LYD_VAL_MAND   0x04
 
#define LYD_VAL_INUSE   0x80
 
#define LY_VALUE_UNRES   0x01
 Flags for values. More...
 
#define LY_VALUE_USER   0x02
 
#define LYD_DIFFOPT_NOSIBLINGS   0x0800
 
#define LYD_DIFFOPT_WITHDEFAULTS   0x0001
 
#define LYD_OPT_DATA   0x00
 
#define LYD_OPT_CONFIG   0x01
 
#define LYD_OPT_GET   0x02
 
#define LYD_OPT_GETCONFIG   0x04
 
#define LYD_OPT_EDIT   0x08
 
#define LYD_OPT_RPC   0x10
 
#define LYD_OPT_RPCREPLY   0x20
 
#define LYD_OPT_NOTIF   0x40
 
#define LYD_OPT_NOTIF_FILTER   0x80
 
#define LYD_OPT_TYPEMASK   0x10000ff
 
#define LYD_OPT_STRICT   0x0200
 
#define LYD_OPT_DESTRUCT   0x0400
 
#define LYD_OPT_OBSOLETE   0x0800
 
#define LYD_OPT_NOSIBLINGS   0x1000
 
#define LYD_OPT_TRUSTED   0x2000
 
#define LYD_OPT_WHENAUTODEL   0x4000
 
#define LYD_OPT_NOEXTDEPS   0x8000
 
#define LYD_OPT_DATA_NO_YANGLIB   0x10000
 
#define LYD_OPT_DATA_ADD_YANGLIB   0x20000
 
#define LYD_OPT_VAL_DIFF   0x40000
 
#define LYD_OPT_LYB_MOD_UPDATE   0x80000
 
#define LYD_OPT_DATA_TEMPLATE   0x1000000
 
#define LYD_OPT_MULTI_ERRORS   0x2000000
 
#define LYD_PATH_OPT_UPDATE   0x01
 
#define LYD_PATH_OPT_NOPARENT   0x02
 
#define LYD_PATH_OPT_OUTPUT   0x04
 
#define LYD_PATH_OPT_DFLT   0x08
 
#define LYD_PATH_OPT_NOPARENTRET   0x10
 
#define LYD_PATH_OPT_EDIT   0x20
 
#define LYD_DUP_OPT_RECURSIVE   0x01
 
#define LYD_DUP_OPT_NO_ATTR   0x02
 
#define LYD_DUP_OPT_WITH_PARENTS   0x04
 
#define LYD_DUP_OPT_WITH_KEYS   0x08
 
#define LYD_DUP_OPT_WITH_WHEN   0x10
 
#define LYD_OPT_EXPLICIT   0x0100
 

Typedefs

typedef union lyd_value_u lyd_val
 node's value representation More...
 

Enumerations

enum  LYD_FORMAT { LYD_UNKNOWN, LYD_XML, LYD_JSON, LYD_LYB }
 Data input/output formats supported by libyang parser and printer functions. More...
 
enum  LYD_ANYDATA_VALUETYPE {
  LYD_ANYDATA_CONSTSTRING = 0x00, LYD_ANYDATA_STRING = 0x01, LYD_ANYDATA_JSON = 0x02, LYD_ANYDATA_JSOND = 0x03,
  LYD_ANYDATA_SXML = 0x04, LYD_ANYDATA_SXMLD = 0x05, LYD_ANYDATA_XML = 0x08, LYD_ANYDATA_DATATREE = 0x10,
  LYD_ANYDATA_LYB = 0x20, LYD_ANYDATA_LYBD = 0x21
}
 List of possible value types stored in lyd_node_anydata. More...
 
enum  LYD_DIFFTYPE {
  LYD_DIFF_END = 0, LYD_DIFF_DELETED, LYD_DIFF_CHANGED, LYD_DIFF_MOVEDAFTER1,
  LYD_DIFF_CREATED, LYD_DIFF_MOVEDAFTER2
}
 list of possible types of differences in lyd_difflist More...
 

Functions

void lyd_free_diff (struct lyd_difflist *diff)
 Free the result of lyd_diff(). It frees the structure of the lyd_diff() result, not the referenced nodes. More...
 
struct lyd_difflistlyd_diff (struct lyd_node *first, struct lyd_node *second, int options)
 Compare two data trees and provide list of differences. More...
 
char * lyd_path (const struct lyd_node *node)
 Build data path (usable as path, see howtoxpath) of the data node. More...
 
struct lyd_nodelyd_parse_mem (struct ly_ctx *ctx, const char *data, LYD_FORMAT format, int options,...)
 Parse (and validate) data from memory. More...
 
struct lyd_nodelyd_parse_fd (struct ly_ctx *ctx, int fd, LYD_FORMAT format, int options,...)
 Read (and validate) data from the given file descriptor. More...
 
struct lyd_nodelyd_parse_path (struct ly_ctx *ctx, const char *path, LYD_FORMAT format, int options,...)
 Read (and validate) data from the given file path. More...
 
struct lyd_nodelyd_parse_xml (struct ly_ctx *ctx, struct lyxml_elem **root, int options,...)
 Parse (and validate) XML tree. More...
 
struct lyd_nodelyd_new (struct lyd_node *parent, const struct lys_module *module, const char *name)
 Create a new container node in a data tree. More...
 
struct lyd_nodelyd_new_leaf (struct lyd_node *parent, const struct lys_module *module, const char *name, const char *val_str)
 Create a new leaf or leaflist node in a data tree with a string value that is converted to the actual value. More...
 
int lyd_change_leaf (struct lyd_node_leaf_list *leaf, const char *val_str)
 Change value of a leaf node. More...
 
struct lyd_nodelyd_new_anydata (struct lyd_node *parent, const struct lys_module *module, const char *name, void *value, LYD_ANYDATA_VALUETYPE value_type)
 Create a new anydata or anyxml node in a data tree. More...
 
struct lyd_nodelyd_new_output (struct lyd_node *parent, const struct lys_module *module, const char *name)
 Create a new container node in a data tree. Ignore RPC/action input nodes and instead use RPC/action output ones. More...
 
struct lyd_nodelyd_new_output_leaf (struct lyd_node *parent, const struct lys_module *module, const char *name, const char *val_str)
 Create a new leaf or leaflist node in a data tree with a string value that is converted to the actual value. Ignore RPC/action input nodes and instead use RPC/action output ones. More...
 
struct lyd_nodelyd_new_output_anydata (struct lyd_node *parent, const struct lys_module *module, const char *name, void *value, LYD_ANYDATA_VALUETYPE value_type)
 Create a new anydata or anyxml node in a data tree. Ignore RPC/action input nodes and instead use RPC/action output ones. More...
 
struct lyd_nodelyd_new_yangdata (const struct lys_module *module, const char *name_template, const char *name)
 Create a new yang-data template in a data tree. It creates container, which name is in third parameter. More...
 
struct lyd_nodelyd_new_path (struct lyd_node *data_tree, const struct ly_ctx *ctx, const char *path, void *value, LYD_ANYDATA_VALUETYPE value_type, int options)
 Create a new data node based on a simple XPath. More...
 
unsigned int lyd_list_pos (const struct lyd_node *node)
 Learn the relative instance position of a list or leaf-list within other instances of the same schema node. More...
 
struct lyd_nodelyd_dup (const struct lyd_node *node, int options)
 Create a copy of the specified data tree node. Schema references are kept the same. Use carefully, since libyang silently creates default nodes, it is always better to use lyd_dup_withsiblings() to duplicate the complete data tree. More...
 
struct lyd_nodelyd_dup_withsiblings (const struct lyd_node *node, int options)
 Create a copy of the specified data tree and all its siblings (preceding as well as following). Schema references are kept the same. More...
 
struct lyd_nodelyd_dup_to_ctx (const struct lyd_node *node, int options, struct ly_ctx *ctx)
 Create a copy of the specified data tree node in the different context. All the schema references and strings are re-mapped into the specified context. More...
 
int lyd_merge (struct lyd_node *target, const struct lyd_node *source, int options)
 Merge a (sub)tree into a data tree. More...
 
int lyd_merge_to_ctx (struct lyd_node **trg, const struct lyd_node *src, int options, struct ly_ctx *ctx)
 Same as lyd_merge(), but moves the resulting data into the specified context. More...
 
int lyd_insert (struct lyd_node *parent, struct lyd_node *node)
 Insert the node element as child to the parent element. The node is inserted as a last child of the parent. More...
 
int lyd_insert_sibling (struct lyd_node **sibling, struct lyd_node *node)
 Insert the node element as a last sibling of the specified sibling element. More...
 
int lyd_insert_before (struct lyd_node *sibling, struct lyd_node *node)
 Insert the node element after the sibling element. If node and siblings are already siblings (just moving node position). More...
 
int lyd_insert_after (struct lyd_node *sibling, struct lyd_node *node)
 Insert the node element after the sibling element. If node and siblings are already siblings (just moving node position). More...
 
int lyd_schema_sort (struct lyd_node *sibling, int recursive)
 Order siblings according to the schema node ordering. More...
 
struct ly_set * lyd_find_path (const struct lyd_node *ctx_node, const char *path)
 Search in the given data for instances of nodes matching the provided path. More...
 
struct ly_set * lyd_find_instance (const struct lyd_node *data, const struct lys_node *schema)
 Search in the given data for instances of the provided schema node. More...
 
int lyd_find_sibling (const struct lyd_node *siblings, const struct lyd_node *target, struct lyd_node **match)
 Search in the given siblings for the target instance. If cache is enabled and the siblings are NOT top-level nodes, this function finds the node in a constant time! More...
 
int lyd_find_sibling_set (const struct lyd_node *siblings, const struct lyd_node *target, struct ly_set **set)
 Search in the given siblings for all target instances. If cache is enabled and the siblings are NOT top-level nodes, this function finds the node(s) in a constant time! More...
 
int lyd_find_sibling_val (const struct lyd_node *siblings, const struct lys_node *schema, const char *key_or_value, struct lyd_node **match)
 Search in the given siblings for the schema instance. If cache is enabled and the siblings are NOT top-level nodes, this function finds the node in a constant time! More...
 
struct lyd_nodelyd_first_sibling (struct lyd_node *node)
 Get the first sibling of the given node. More...
 
int lyd_validate (struct lyd_node **node, int options, void *var_arg,...)
 Validate node data subtree. More...
 
int lyd_validate_modules (struct lyd_node **node, const struct lys_module **modules, int mod_count, int options,...)
 Validate node data tree but only subtrees that belong to the schema found in modules. All other schemas are effectively disabled for the validation. More...
 
void lyd_free_val_diff (struct lyd_difflist *diff)
 Free special diff that was returned by lyd_validate() or lyd_validate_modules(). More...
 
int lyd_validate_value (struct lys_node *node, const char *value)
 Check restrictions applicable to the particular leaf/leaf-list on the given string value. More...
 
int lyd_value_type (struct lys_node *node, const char *value, struct lys_type **type)
 Check restrictions applicable to the particular leaf/leaf-list on the given string value and optionally return its final type. More...
 
int lyd_wd_default (struct lyd_node_leaf_list *node)
 Get know if the node contain (despite implicit or explicit) default value. More...
 
int lyd_node_should_print (const struct lyd_node *node, int options)
 Learn if a node is supposed to be printed based on the options. More...
 
int lyd_unlink (struct lyd_node *node)
 Unlink the specified data subtree. All referenced namespaces are copied. More...
 
void lyd_free (struct lyd_node *node)
 Free (and unlink) the specified data subtree. Use carefully, since libyang silently creates default nodes, it is always better to use lyd_free_withsiblings() to free the complete data tree. More...
 
void lyd_free_withsiblings (struct lyd_node *node)
 Free (and unlink) the specified data tree and all its siblings (preceding as well as following). More...
 
struct lyd_attrlyd_insert_attr (struct lyd_node *parent, const struct lys_module *mod, const char *name, const char *value)
 Insert attribute into the data node. More...
 
void lyd_free_attr (struct ly_ctx *ctx, struct lyd_node *parent, struct lyd_attr *attr, int recursive)
 Destroy data attribute. More...
 
struct lys_modulelyd_node_module (const struct lyd_node *node)
 Return main module of the data tree node. More...
 
struct lys_typelyd_leaf_type (const struct lyd_node_leaf_list *leaf)
 Get the type structure of a leaf. More...
 
int lyd_print_mem (char **strp, const struct lyd_node *root, LYD_FORMAT format, int options)
 Print data tree in the specified format. More...
 
int lyd_print_fd (int fd, const struct lyd_node *root, LYD_FORMAT format, int options)
 Print data tree in the specified format. More...
 
int lyd_print_file (FILE *f, const struct lyd_node *root, LYD_FORMAT format, int options)
 Print data tree in the specified format. More...
 
int lyd_print_path (const char *path, const struct lyd_node *root, LYD_FORMAT format, int options)
 Print data tree in the specified format. More...
 
int lyd_print_clb (ssize_t(*writeclb)(void *arg, const void *buf, size_t count), void *arg, const struct lyd_node *root, LYD_FORMAT format, int options)
 Print data tree in the specified format. More...
 
double lyd_dec64_to_double (const struct lyd_node *node)
 Get the double value of a decimal64 leaf/leaf-list. More...
 
int lyd_lyb_data_length (const char *data)
 Get the length of a printed LYB data tree. More...
 

Detailed Description

libyang representation of data trees.

Author
Radek Krejci rkrej.nosp@m.ci@c.nosp@m.esnet.nosp@m..cz Copyright (c) 2015 CESNET, z.s.p.o.

This source code is licensed under BSD 3-Clause License (the "License"). You may not use this file except in compliance with the License. You may obtain a copy of the License at

https://opensource.org/licenses/BSD-3-Clause

Definition in file tree_data.h.