libyang  2.0.112
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
tree_data.h
Go to the documentation of this file.
1 
16 #ifndef LY_TREE_DATA_H_
17 #define LY_TREE_DATA_H_
18 
19 #include <arpa/inet.h>
20 #if defined (__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__)
21 #include <netinet/in.h>
22 #include <sys/socket.h>
23 #endif
24 #include <stddef.h>
25 #include <stdint.h>
26 #include <time.h>
27 
28 #include "config.h"
29 #include "log.h"
30 #include "tree.h"
31 #include "tree_schema.h"
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 struct ly_ctx;
38 struct ly_path;
39 struct ly_set;
40 struct lyd_node;
41 struct lyd_node_opaq;
42 struct lyd_node_term;
43 struct timespec;
44 struct lyxp_var;
45 
398 /* *INDENT-OFF* */
399 
425 #define LYD_TREE_DFS_BEGIN(START, ELEM) \
426  { ly_bool LYD_TREE_DFS_continue = 0; struct lyd_node *LYD_TREE_DFS_next; \
427  for ((ELEM) = (LYD_TREE_DFS_next) = (struct lyd_node *)(START); \
428  (ELEM); \
429  (ELEM) = (LYD_TREE_DFS_next), LYD_TREE_DFS_continue = 0)
430 
445 #define LYD_TREE_DFS_END(START, ELEM) \
446  /* select element for the next run - children first */ \
447  if (LYD_TREE_DFS_continue) { \
448  (LYD_TREE_DFS_next) = NULL; \
449  } else { \
450  (LYD_TREE_DFS_next) = lyd_child(ELEM); \
451  }\
452  if (!(LYD_TREE_DFS_next)) { \
453  /* no children */ \
454  if ((ELEM) == (struct lyd_node *)(START)) { \
455  /* we are done, (START) has no children */ \
456  break; \
457  } \
458  /* try siblings */ \
459  (LYD_TREE_DFS_next) = (ELEM)->next; \
460  } \
461  while (!(LYD_TREE_DFS_next)) { \
462  /* parent is already processed, go to its sibling */ \
463  (ELEM) = (struct lyd_node *)(ELEM)->parent; \
464  /* no siblings, go back through parents */ \
465  if ((ELEM)->parent == (START)->parent) { \
466  /* we are done, no next element to process */ \
467  break; \
468  } \
469  (LYD_TREE_DFS_next) = (ELEM)->next; \
470  } }
471 
479 #define LYD_LIST_FOR_INST(START, SCHEMA, ELEM) \
480  for (lyd_find_sibling_val(START, SCHEMA, NULL, 0, &(ELEM)); \
481  (ELEM) && ((ELEM)->schema == (SCHEMA)); \
482  (ELEM) = (ELEM)->next)
483 
492 #define LYD_LIST_FOR_INST_SAFE(START, SCHEMA, NEXT, ELEM) \
493  for (lyd_find_sibling_val(START, SCHEMA, NULL, 0, &(ELEM)); \
494  (ELEM) && ((ELEM)->schema == (SCHEMA)) ? ((NEXT) = (ELEM)->next, 1) : 0; \
495  (ELEM) = (NEXT))
496 
497 /* *INDENT-ON* */
498 
502 #define LYD_CTX(node) ((node)->schema ? (node)->schema->module->ctx : ((const struct lyd_node_opaq *)(node))->ctx)
503 
508 typedef enum {
513 } LYD_FORMAT;
514 
518 typedef enum {
529 
535 struct lyd_value {
536  const char *_canonical;
539  const struct lysc_type *realtype;
547  union {
548  int8_t boolean;
549  int64_t dec64;
550  int8_t int8;
551  int16_t int16;
552  int32_t int32;
553  int64_t int64;
554  uint8_t uint8;
555  uint16_t uint16;
556  uint32_t uint32;
557  uint64_t uint64;
558  struct lysc_type_bitenum_item *enum_item;
559  struct lysc_ident *ident;
560  struct ly_path *target;
562  struct lyd_value_union *subvalue;
564  void *dyn_mem;
565  uint8_t fixed_mem[LYD_VALUE_FIXED_MEM_SIZE];
566  };
568 };
569 
578 #define LYD_VALUE_GET(value, type_val) \
579  ((sizeof *(type_val) > LYD_VALUE_FIXED_MEM_SIZE) \
580  ? ((type_val) = (((value)->dyn_mem))) \
581  : ((type_val) = ((void *)((value)->fixed_mem))))
582 
591  struct lyd_value value;
593  void *original;
594  size_t orig_len;
595  uint32_t hints;
599  void *prefix_data;
600  const struct lysc_node *ctx_node;
601 };
602 
607  char *bitmap;
612 };
613 
618  void *data;
619  size_t size;
620 };
621 
626  struct in_addr addr;
627 };
628 
633  struct in_addr addr;
634  const char *zone;
635 };
636 
641  struct in_addr addr;
642  uint8_t prefix;
643 };
644 
649  struct in6_addr addr;
650 };
651 
656  struct in6_addr addr;
657  const char *zone;
658 };
659 
664  struct in6_addr addr;
665  uint8_t prefix;
666 };
667 
672  time_t time;
673  char *fractions_s;
674 };
675 
686 struct lyd_meta {
687  struct lyd_node *parent;
688  struct lyd_meta *next;
690  const char *name;
691  struct lyd_value value;
692 };
693 
701 struct ly_opaq_name {
702  const char *name;
703  const char *prefix;
704  union {
705  const char *module_ns;
706  const char *module_name;
707  };
708 };
709 
713 struct lyd_attr {
715  struct lyd_attr *next;
717  const char *value;
718  uint32_t hints;
721 };
722 
723 #define LYD_NODE_INNER (LYS_CONTAINER|LYS_LIST|LYS_RPC|LYS_ACTION|LYS_NOTIF)
724 #define LYD_NODE_TERM (LYS_LEAF|LYS_LEAFLIST)
725 #define LYD_NODE_ANY (LYS_ANYDATA)
750 #define LYD_DEFAULT 0x01
751 #define LYD_WHEN_TRUE 0x02
752 #define LYD_NEW 0x04
759 struct lyd_node {
760  uint32_t hash;
764  uint32_t flags;
765  const struct lysc_node *schema;
767  struct lyd_node *next;
768  struct lyd_node *prev;
772  struct lyd_meta *meta;
773  void *priv;
774 };
775 
780  union {
781  struct lyd_node node;
782  struct {
783  uint32_t hash;
788  uint32_t flags;
789  const struct lysc_node *schema;
790  struct lyd_node_inner *parent;
791  struct lyd_node *next;
792  struct lyd_node *prev;
796  struct lyd_meta *meta;
797  void *priv;
798  };
799  };
801  struct lyd_node *child;
802  struct hash_table *children_ht;
803 #define LYD_HT_MIN_ITEMS 4
804 };
805 
810  union {
811  struct lyd_node node;
812  struct {
813  uint32_t hash;
818  uint32_t flags;
819  const struct lysc_node *schema;
820  struct lyd_node_inner *parent;
821  struct lyd_node *next;
822  struct lyd_node *prev;
826  struct lyd_meta *meta;
827  void *priv;
828  };
829  };
831  struct lyd_value value;
832 };
833 
838  struct lyd_node *tree;
839  const char *str;
840  const char *xml;
841  const char *json;
842  char *mem;
843 };
844 
849 struct lyd_node_any {
850  union {
851  struct lyd_node node;
852  struct {
853  uint32_t hash;
858  uint32_t flags;
859  const struct lysc_node *schema;
860  struct lyd_node_inner *parent;
861  struct lyd_node *next;
862  struct lyd_node *prev;
866  struct lyd_meta *meta;
867  void *priv;
868  };
869  };
871  union lyd_any_value value;
873 };
874 
881 #define LYD_NAME(node) ((node)->schema ? (node)->schema->name : ((struct lyd_node_opaq *)node)->name.name)
882 
892 #define LYD_VALHINT_STRING 0x0001
893 #define LYD_VALHINT_DECNUM 0x0002
894 #define LYD_VALHINT_OCTNUM 0x0004
895 #define LYD_VALHINT_HEXNUM 0x0008
896 #define LYD_VALHINT_NUM64 0x0010
897 #define LYD_VALHINT_BOOLEAN 0x0020
898 #define LYD_VALHINT_EMPTY 0x0040
912 #define LYD_NODEHINT_LIST 0x0080
913 #define LYD_NODEHINT_LEAFLIST 0x0100
928 #define LYD_HINT_DATA 0x01F3
932 #define LYD_HINT_SCHEMA 0x01FF
943 struct lyd_node_opaq {
944  union {
945  struct lyd_node node;
946  struct {
947  uint32_t hash;
948  uint32_t flags;
949  const struct lysc_node *schema;
950  struct lyd_node_inner *parent;
951  struct lyd_node *next;
952  struct lyd_node *prev;
956  struct lyd_meta *meta;
957  void *priv;
958  };
959  };
961  struct lyd_node *child;
963  struct ly_opaq_name name;
964  const char *value;
965  uint32_t hints;
966  LY_VALUE_FORMAT format;
967  void *val_prefix_data;
969  struct lyd_attr *attr;
970  const struct ly_ctx *ctx;
971 };
980 static inline struct lyd_node *
981 lyd_parent(const struct lyd_node *node)
982 {
983  if (!node || !node->parent) {
984  return NULL;
985  }
986 
987  return &node->parent->node;
988 }
989 
1000 static inline struct lyd_node *
1001 lyd_child(const struct lyd_node *node)
1002 {
1003  if (!node) {
1004  return NULL;
1005  }
1006 
1007  if (!node->schema) {
1008  /* opaq node */
1009  return ((const struct lyd_node_opaq *)node)->child;
1010  }
1011 
1012  switch (node->schema->nodetype) {
1013  case LYS_CONTAINER:
1014  case LYS_LIST:
1015  case LYS_RPC:
1016  case LYS_ACTION:
1017  case LYS_NOTIF:
1018  return ((const struct lyd_node_inner *)node)->child;
1019  default:
1020  return NULL;
1021  }
1022 }
1023 
1034 struct lyd_node *lyd_child_no_keys(const struct lyd_node *node);
1035 
1045 const struct lys_module *lyd_owner_module(const struct lyd_node *node);
1046 
1053 ly_bool lyd_is_default(const struct lyd_node *node);
1054 
1062 uint32_t lyd_list_pos(const struct lyd_node *instance);
1063 
1070 struct lyd_node *lyd_first_sibling(const struct lyd_node *node);
1071 
1079 int lyd_lyb_data_length(const char *data);
1080 
1090 const char *lyd_value_get_canonical(const struct ly_ctx *ctx, const struct lyd_value *value);
1091 
1098 static inline const char *
1099 lyd_get_value(const struct lyd_node *node)
1100 {
1101  if (!node) {
1102  return NULL;
1103  }
1104 
1105  if (!node->schema) {
1106  return ((const struct lyd_node_opaq *)node)->value;
1107  } else if (node->schema->nodetype & LYD_NODE_TERM) {
1108  const struct lyd_value *value = &((const struct lyd_node_term *)node)->value;
1109  return value->_canonical ? value->_canonical : lyd_value_get_canonical(LYD_CTX(node), value);
1110  }
1111 
1112  return NULL;
1113 }
1114 
1121 static inline const char *
1122 lyd_get_meta_value(const struct lyd_meta *meta)
1123 {
1124  if (meta) {
1125  const struct lyd_value *value = &meta->value;
1126  return value->_canonical ? value->_canonical : lyd_value_get_canonical(meta->annotation->module->ctx, value);
1127  }
1128 
1129  return NULL;
1130 }
1131 
1139 LY_ERR lyd_any_value_str(const struct lyd_node *any, char **value_str);
1140 
1149 LY_ERR lyd_any_copy_value(struct lyd_node *trg, const union lyd_any_value *value, LYD_ANYDATA_VALUETYPE value_type);
1150 
1166 LY_ERR lyd_new_inner(struct lyd_node *parent, const struct lys_module *module, const char *name, ly_bool output,
1167  struct lyd_node **node);
1168 
1182 LY_ERR lyd_new_ext_inner(const struct lysc_ext_instance *ext, const char *name, struct lyd_node **node);
1183 
1198 LY_ERR lyd_new_list(struct lyd_node *parent, const struct lys_module *module, const char *name, ly_bool output,
1199  struct lyd_node **node, ...);
1200 
1214 LY_ERR lyd_new_list_bin(struct lyd_node *parent, const struct lys_module *module, const char *name, ly_bool output,
1215  struct lyd_node **node, ...);
1216 
1230 LY_ERR lyd_new_list_canon(struct lyd_node *parent, const struct lys_module *module, const char *name, ly_bool output,
1231  struct lyd_node **node, ...);
1232 
1247 LY_ERR lyd_new_ext_list(const struct lysc_ext_instance *ext, const char *name, struct lyd_node **node, ...);
1248 
1263 LY_ERR lyd_new_list2(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *keys,
1264  ly_bool output, struct lyd_node **node);
1265 
1280 LY_ERR lyd_new_term(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *val_str,
1281  ly_bool output, struct lyd_node **node);
1282 
1296 LY_ERR lyd_new_term_bin(struct lyd_node *parent, const struct lys_module *module, const char *name, const void *value,
1297  size_t value_len, ly_bool output, struct lyd_node **node);
1298 
1311 LY_ERR lyd_new_term_canon(struct lyd_node *parent, const struct lys_module *module, const char *name,
1312  const char *val_str, ly_bool output, struct lyd_node **node);
1313 
1327 LY_ERR lyd_new_ext_term(const struct lysc_ext_instance *ext, const char *name, const char *val_str, struct lyd_node **node);
1328 
1345 LY_ERR lyd_new_any(struct lyd_node *parent, const struct lys_module *module, const char *name, const void *value,
1346  ly_bool use_value, LYD_ANYDATA_VALUETYPE value_type, ly_bool output, struct lyd_node **node);
1347 
1362 LY_ERR lyd_new_ext_any(const struct lysc_ext_instance *ext, const char *name, const void *value, ly_bool use_value,
1363  LYD_ANYDATA_VALUETYPE value_type, struct lyd_node **node);
1364 
1379 LY_ERR lyd_new_meta(const struct ly_ctx *ctx, struct lyd_node *parent, const struct lys_module *module, const char *name,
1380  const char *val_str, ly_bool clear_dflt, struct lyd_meta **meta);
1381 
1394 LY_ERR lyd_new_meta2(const struct ly_ctx *ctx, struct lyd_node *parent, ly_bool clear_dflt, const struct lyd_attr *attr,
1395  struct lyd_meta **meta);
1396 
1409 LY_ERR lyd_new_opaq(struct lyd_node *parent, const struct ly_ctx *ctx, const char *name, const char *value,
1410  const char *prefix, const char *module_name, struct lyd_node **node);
1411 
1424 LY_ERR lyd_new_opaq2(struct lyd_node *parent, const struct ly_ctx *ctx, const char *name, const char *value,
1425  const char *prefix, const char *module_ns, struct lyd_node **node);
1426 
1440 LY_ERR lyd_new_attr(struct lyd_node *parent, const char *module_name, const char *name, const char *value,
1441  struct lyd_attr **attr);
1442 
1455 LY_ERR lyd_new_attr2(struct lyd_node *parent, const char *module_ns, const char *name, const char *value,
1456  struct lyd_attr **attr);
1457 
1471 #define LYD_NEW_PATH_UPDATE 0x01
1475 #define LYD_NEW_PATH_OUTPUT 0x02
1477 #define LYD_NEW_PATH_OPAQ 0x04
1480 #define LYD_NEW_PATH_BIN_VALUE 0x08
1482 #define LYD_NEW_PATH_CANON_VALUE 0x10
1512 LY_ERR lyd_new_path(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const char *value,
1513  uint32_t options, struct lyd_node **node);
1514 
1535 LY_ERR lyd_new_path2(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const void *value,
1536  size_t value_len, LYD_ANYDATA_VALUETYPE value_type, uint32_t options, struct lyd_node **new_parent,
1537  struct lyd_node **new_node);
1538 
1557 LY_ERR lyd_new_ext_path(struct lyd_node *parent, const struct lysc_ext_instance *ext, const char *path, const void *value,
1558  uint32_t options, struct lyd_node **node);
1559 
1573 #define LYD_IMPLICIT_NO_STATE 0x01
1574 #define LYD_IMPLICIT_NO_CONFIG 0x02
1575 #define LYD_IMPLICIT_OUTPUT 0x04
1576 #define LYD_IMPLICIT_NO_DEFAULTS 0x08
1589 LY_ERR lyd_new_implicit_tree(struct lyd_node *tree, uint32_t implicit_options, struct lyd_node **diff);
1602 LY_ERR lyd_new_implicit_all(struct lyd_node **tree, const struct ly_ctx *ctx, uint32_t implicit_options, struct lyd_node **diff);
1603 
1615 LY_ERR lyd_new_implicit_module(struct lyd_node **tree, const struct lys_module *module, uint32_t implicit_options,
1616  struct lyd_node **diff);
1617 
1631 LY_ERR lyd_change_term(struct lyd_node *term, const char *val_str);
1632 
1647 LY_ERR lyd_change_term_bin(struct lyd_node *term, const void *value, size_t value_len);
1648 
1663 LY_ERR lyd_change_term_canon(struct lyd_node *term, const char *val_str);
1664 
1674 LY_ERR lyd_change_meta(struct lyd_meta *meta, const char *val_str);
1675 
1687 LY_ERR lyd_insert_child(struct lyd_node *parent, struct lyd_node *node);
1688 
1701 LY_ERR lyd_insert_sibling(struct lyd_node *sibling, struct lyd_node *node, struct lyd_node **first);
1702 
1714 LY_ERR lyd_insert_before(struct lyd_node *sibling, struct lyd_node *node);
1715 
1727 LY_ERR lyd_insert_after(struct lyd_node *sibling, struct lyd_node *node);
1728 
1734 void lyd_unlink_siblings(struct lyd_node *node);
1735 
1741 void lyd_unlink_tree(struct lyd_node *node);
1742 
1748 void lyd_free_all(struct lyd_node *node);
1749 
1755 void lyd_free_siblings(struct lyd_node *node);
1756 
1762 void lyd_free_tree(struct lyd_node *node);
1763 
1769 void lyd_free_meta_single(struct lyd_meta *meta);
1770 
1776 void lyd_free_meta_siblings(struct lyd_meta *meta);
1777 
1784 void lyd_free_attr_single(const struct ly_ctx *ctx, struct lyd_attr *attr);
1785 
1792 void lyd_free_attr_siblings(const struct ly_ctx *ctx, struct lyd_attr *attr);
1793 
1812 LY_ERR lyd_value_validate(const struct ly_ctx *ctx, const struct lysc_node *schema, const char *value, size_t value_len,
1813  const struct lyd_node *ctx_node, const struct lysc_type **realtype, const char **canonical);
1814 
1827 LY_ERR lyd_value_compare(const struct lyd_node_term *node, const char *value, size_t value_len);
1828 
1835 #define LYD_COMPARE_FULL_RECURSION 0x01 /* lists and containers are the same only in case all they children
1836  (subtree, so direct as well as indirect children) are the same. By default,
1837  containers are the same in case of the same schema node and lists are the same
1838  in case of equal keys (keyless lists do the full recursion comparison all the time). */
1839 #define LYD_COMPARE_DEFAULTS 0x02 /* By default, implicit and explicit default nodes are considered to be equal. This flag
1840  changes this behavior and implicit (automatically created default node) and explicit
1841  (explicitly created node with the default value) default nodes are considered different. */
1842 
1853 LY_ERR lyd_compare_single(const struct lyd_node *node1, const struct lyd_node *node2, uint32_t options);
1854 
1864 LY_ERR lyd_compare_siblings(const struct lyd_node *node1, const struct lyd_node *node2, uint32_t options);
1865 
1874 LY_ERR lyd_compare_meta(const struct lyd_meta *meta1, const struct lyd_meta *meta2);
1875 
1888 #define LYD_DUP_RECURSIVE 0x01
1890 #define LYD_DUP_NO_META 0x02
1891 #define LYD_DUP_WITH_PARENTS 0x04
1893 #define LYD_DUP_WITH_FLAGS 0x08
1910 LY_ERR lyd_dup_single(const struct lyd_node *node, struct lyd_node_inner *parent, uint32_t options, struct lyd_node **dup);
1924 LY_ERR lyd_dup_siblings(const struct lyd_node *node, struct lyd_node_inner *parent, uint32_t options, struct lyd_node **dup);
1925 
1934 LY_ERR lyd_dup_meta_single(const struct lyd_meta *meta, struct lyd_node *parent, struct lyd_meta **dup);
1935 
1950 #define LYD_MERGE_DESTRUCT 0x01
1951 #define LYD_MERGE_DEFAULTS 0x02
1952 #define LYD_MERGE_WITH_FLAGS 0x04
1976 LY_ERR lyd_merge_tree(struct lyd_node **target, const struct lyd_node *source, uint16_t options);
1977 
1999 LY_ERR lyd_merge_siblings(struct lyd_node **target, const struct lyd_node *source, uint16_t options);
2000 
2010 typedef LY_ERR (*lyd_merge_cb)(struct lyd_node *trg_node, const struct lyd_node *src_node, void *cb_data);
2011 
2027 LY_ERR lyd_merge_module(struct lyd_node **target, const struct lyd_node *source, const struct lys_module *mod,
2028  lyd_merge_cb merge_cb, void *cb_data, uint16_t options);
2041 #define LYD_DIFF_DEFAULTS 0x01
2072 LY_ERR lyd_diff_tree(const struct lyd_node *first, const struct lyd_node *second, uint16_t options, struct lyd_node **diff);
2073 
2086 LY_ERR lyd_diff_siblings(const struct lyd_node *first, const struct lyd_node *second, uint16_t options, struct lyd_node **diff);
2087 
2096 typedef LY_ERR (*lyd_diff_cb)(const struct lyd_node *diff_node, struct lyd_node *data_node, void *cb_data);
2097 
2114 LY_ERR lyd_diff_apply_module(struct lyd_node **data, const struct lyd_node *diff, const struct lys_module *mod,
2115  lyd_diff_cb diff_cb, void *cb_data);
2116 
2127 LY_ERR lyd_diff_apply_all(struct lyd_node **data, const struct lyd_node *diff);
2128 
2140 #define LYD_DIFF_MERGE_DEFAULTS 0x01
2168 LY_ERR lyd_diff_merge_module(struct lyd_node **diff, const struct lyd_node *src_diff, const struct lys_module *mod,
2169  lyd_diff_cb diff_cb, void *cb_data, uint16_t options);
2170 
2187 LY_ERR lyd_diff_merge_tree(struct lyd_node **diff_first, struct lyd_node *diff_parent, const struct lyd_node *src_sibling,
2188  lyd_diff_cb diff_cb, void *cb_data, uint16_t options);
2189 
2201 LY_ERR lyd_diff_merge_all(struct lyd_node **diff, const struct lyd_node *src_diff, uint16_t options);
2202 
2212 LY_ERR lyd_diff_reverse_all(const struct lyd_node *src_diff, struct lyd_node **diff);
2213 
2222 const struct lyd_node_term *lyd_target(const struct ly_path *path, const struct lyd_node *tree);
2223 
2227 typedef enum {
2228  LYD_PATH_STD,
2232 } LYD_PATH_TYPE;
2233 
2245 char *lyd_path(const struct lyd_node *node, LYD_PATH_TYPE pathtype, char *buffer, size_t buflen);
2246 
2256 struct lyd_meta *lyd_find_meta(const struct lyd_meta *first, const struct lys_module *module, const char *name);
2257 
2269 LY_ERR lyd_find_sibling_first(const struct lyd_node *siblings, const struct lyd_node *target, struct lyd_node **match);
2270 
2295 LY_ERR lyd_find_sibling_val(const struct lyd_node *siblings, const struct lysc_node *schema, const char *key_or_value,
2296  size_t val_len, struct lyd_node **match);
2297 
2309 LY_ERR lyd_find_sibling_dup_inst_set(const struct lyd_node *siblings, const struct lyd_node *target, struct ly_set **set);
2310 
2321 LY_ERR lyd_find_sibling_opaq_next(const struct lyd_node *first, const char *name, struct lyd_node **match);
2322 
2334 LY_ERR lyxp_vars_set(struct lyxp_var **vars, const char *name, const char *value);
2335 
2341 void lyxp_vars_free(struct lyxp_var *vars);
2342 
2358 LY_ERR lyd_find_xpath(const struct lyd_node *ctx_node, const char *xpath, struct ly_set **set);
2359 
2373 LY_ERR lyd_find_xpath2(const struct lyd_node *ctx_node, const char *xpath,
2374  const struct lyxp_var *vars, struct ly_set **set);
2375 
2387 LY_ERR lyd_eval_xpath(const struct lyd_node *ctx_node, const char *xpath, ly_bool *result);
2388 
2401 LY_ERR lyd_eval_xpath2(const struct lyd_node *ctx_node, const char *xpath,
2402  const struct lyxp_var *vars, ly_bool *result);
2403 
2419 LY_ERR lyd_find_path(const struct lyd_node *ctx_node, const char *path, ly_bool output, struct lyd_node **match);
2420 
2431 LY_ERR lyd_find_target(const struct ly_path *path, const struct lyd_node *tree, struct lyd_node **match);
2432 
2441 LY_ERR ly_time_str2time(const char *value, time_t *time, char **fractions_s);
2442 
2451 LY_ERR ly_time_time2str(time_t time, const char *fractions_s, char **str);
2452 
2460 LY_ERR ly_time_str2ts(const char *value, struct timespec *ts);
2461 
2469 LY_ERR ly_time_ts2str(const struct timespec *ts, char **str);
2470 
2471 #ifdef __cplusplus
2472 }
2473 #endif
2474 
2475 #endif /* LY_TREE_DATA_H_ */
LY_ERR lyd_new_ext_list(const struct lysc_ext_instance *ext, const char *name, struct lyd_node **node,...)
Create a new top-level list node defined in the given extension instance.
struct in_addr addr
Definition: tree_data.h:641
struct lysc_type * realtype
Definition: tree_data.h:539
LY_ERR lyd_new_opaq(struct lyd_node *parent, const struct ly_ctx *ctx, const char *name, const char *value, const char *prefix, const char *module_name, struct lyd_node **node)
Create a new JSON opaque node in the data tree. To create an XML opaque node, use lyd_new_opaq2()...
LY_ERR lyd_new_ext_any(const struct lysc_ext_instance *ext, const char *name, const void *value, ly_bool use_value, LYD_ANYDATA_VALUETYPE value_type, struct lyd_node **node)
Create a new top-level any node defined in the given extension instance.
Compiled YANG data node.
Definition: tree_schema.h:1666
LY_ERR(* lyd_merge_cb)(struct lyd_node *trg_node, const struct lyd_node *src_node, void *cb_data)
Callback for matching merge nodes.
Definition: tree_data.h:2029
uint32_t lyd_list_pos(const struct lyd_node *instance)
Learn the relative position of a list or leaf-list instance within other instances of the same schema...
LY_ERR lyd_compare_siblings(const struct lyd_node *node1, const struct lyd_node *node2, uint32_t options)
Compare 2 lists of siblings if they are equivalent.
struct ly_ctx * ctx
Definition: tree_schema.h:2343
union for anydata/anyxml value representation.
Definition: tree_data.h:837
#define LYS_CONTAINER
Definition: tree_schema.h:239
void lyd_free_meta_single(struct lyd_meta *meta)
Free a single metadata instance.
Generic prefix and namespace mapping, meaning depends on the format.
Definition: tree_data.h:701
LY_ERR ly_time_ts2str(const struct timespec *ts, char **str)
Convert timespec into date-and-time string value.
const char * zone
Definition: tree_data.h:657
const char * str
Definition: tree_data.h:839
LY_ERR lyd_new_term(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *val_str, ly_bool output, struct lyd_node **node)
Create a new term node in the data tree.
const char * prefix
Definition: tree_data.h:703
LY_ERR lyd_new_attr2(struct lyd_node *parent, const char *module_ns, const char *name, const char *value, struct lyd_attr **attr)
Create new XML attribute for an opaque data node. To create a JSON attribute, use lyd_new_attr()...
LY_ERR lyd_diff_apply_all(struct lyd_node **data, const struct lyd_node *diff)
Apply the whole diff tree on a data tree.
struct in_addr addr
Definition: tree_data.h:633
Generic structure for a data node.
Definition: tree_data.h:759
struct lys_module * lyd_owner_module(const struct lyd_node *node)
Get the owner module of the data node. It is the module of the top-level schema node. Generally, in case of augments it is the target module, recursively, otherwise it is the module where the data node is defined.
uint32_t hash
Definition: tree_data.h:760
const char * xml
Definition: tree_data.h:840
LY_ERR lyd_new_term_bin(struct lyd_node *parent, const struct lys_module *module, const char *name, const void *value, size_t value_len, ly_bool output, struct lyd_node **node)
Create a new term node in the data tree.
const char * zone
Definition: tree_data.h:634
YANG extension instance.
Definition: tree_schema.h:1445
struct lyd_node_opaq * parent
Definition: tree_data.h:714
LY_ERR lyd_any_copy_value(struct lyd_node *trg, const union lyd_any_value *value, LYD_ANYDATA_VALUETYPE value_type)
Copy anydata value from one node to another. Target value is freed first.
void * priv
Definition: tree_data.h:773
uint8_t ly_bool
Type to indicate boolean value.
Definition: log.h:25
LYD_PATH_TYPE
Types of the different data paths.
Definition: tree_data.h:2248
LY_ERR lyd_find_sibling_opaq_next(const struct lyd_node *first, const char *name, struct lyd_node **match)
Search the given siblings for an opaque node with a specific name.
LY_ERR lyd_new_meta2(const struct ly_ctx *ctx, struct lyd_node *parent, ly_bool clear_dflt, const struct lyd_attr *attr, struct lyd_meta **meta)
Create new metadata from an opaque node attribute if possible.
LY_ERR lyd_new_meta(const struct ly_ctx *ctx, struct lyd_node *parent, const struct lys_module *module, const char *name, const char *val_str, ly_bool clear_dflt, struct lyd_meta **meta)
Create new metadata.
LY_ERR lyd_value_compare(const struct lyd_node_term *node, const char *value, size_t value_len)
Compare the node&#39;s value with the given string value. The string value is first validated according t...
struct lyd_node * lyd_first_sibling(const struct lyd_node *node)
Get the first sibling of the given node.
LY_ERR lyxp_vars_set(struct lyxp_var **vars, const char *name, const char *value)
Set a new XPath variable to vars.
void * original
Definition: tree_data.h:593
YANG identity-stmt.
Definition: tree_schema.h:1478
libyang representation of YANG schema trees.
Special lyd_value structure for ietf-inet-types ipv4-address values.
Definition: tree_data.h:632
libyang generic macros and functions to work with YANG schema or data trees.
Special lyd_value structure for ietf-inet-types ipv6-address-no-zone values.
Definition: tree_data.h:648
Special lyd_value structure for ietf-inet-types ipv4-address-no-zone values.
Definition: tree_data.h:625
size_t orig_len
Definition: tree_data.h:594
LY_ERR lyd_diff_merge_tree(struct lyd_node **diff_first, struct lyd_node *diff_parent, const struct lyd_node *src_sibling, lyd_diff_cb diff_cb, void *cb_data, uint16_t options)
Merge 2 diff trees into each other.
LY_ERR lyd_change_term_bin(struct lyd_node *term, const void *value, size_t value_len)
Change the value of a term (leaf or leaf-list) node to a binary value.
LY_ERR lyd_new_list_bin(struct lyd_node *parent, const struct lys_module *module, const char *name, ly_bool output, struct lyd_node **node,...)
Create a new list node in the data tree.
Data node structure for the inner data tree nodes - containers, lists, RPCs, actions and Notification...
Definition: tree_data.h:779
LY_ERR lyd_new_ext_inner(const struct lysc_ext_instance *ext, const char *name, struct lyd_node **node)
Create a new top-level inner node defined in the given extension instance.
struct lyd_node * child
Definition: tree_data.h:801
void lyd_free_tree(struct lyd_node *node)
Free (and unlink) the specified data (sub)tree.
LY_ERR lyd_insert_before(struct lyd_node *sibling, struct lyd_node *node)
Insert a node before another node, can be used only for user-ordered nodes. If inserting several sibl...
LY_ERR lyd_new_any(struct lyd_node *parent, const struct lys_module *module, const char *name, const void *value, ly_bool use_value, LYD_ANYDATA_VALUETYPE value_type, ly_bool output, struct lyd_node **node)
Create a new any node in the data tree.
struct lyd_meta * lyd_find_meta(const struct lyd_meta *first, const struct lys_module *module, const char *name)
Find a specific metadata.
LY_ERR lyd_compare_single(const struct lyd_node *node1, const struct lyd_node *node2, uint32_t options)
Compare 2 data nodes if they are equivalent.
struct in6_addr addr
Definition: tree_data.h:664
void lyd_free_all(struct lyd_node *node)
Free all the nodes (even parents of the node) in the data tree.
LY_ERR lyd_compare_meta(const struct lyd_meta *meta1, const struct lyd_meta *meta2)
Compare 2 metadata.
struct lysc_ext_instance * annotation
Definition: tree_data.h:689
Special lyd_value structure for ietf-yang-types date-and-time values.
Definition: tree_data.h:671
ly_bool lyd_is_default(const struct lyd_node *node)
Check whether a node value equals to its default one.
LY_ERR ly_time_str2ts(const char *value, struct timespec *ts)
Convert date-and-time from string to timespec.
struct lys_module * module
Definition: tree_schema.h:1448
char * lyd_path(const struct lyd_node *node, LYD_PATH_TYPE pathtype, char *buffer, size_t buflen)
Generate path of the given node in the requested format.
uint16_t nodetype
Definition: tree_schema.h:1667
struct lyd_meta * meta
Definition: tree_data.h:772
Data node structure for the terminal data tree nodes - leaves and leaf-lists.
Definition: tree_data.h:809
struct lyd_node_inner * parent
Definition: tree_data.h:766
LY_ERR lyd_new_list(struct lyd_node *parent, const struct lys_module *module, const char *name, ly_bool output, struct lyd_node **node,...)
Create a new list node in the data tree.
LY_ERR lyd_new_implicit_module(struct lyd_node **tree, const struct lys_module *module, uint32_t implicit_options, struct lyd_node **diff)
Add any missing implicit nodes of one module. Default nodes with a false &quot;when&quot; are not added...
LY_ERR lyd_insert_after(struct lyd_node *sibling, struct lyd_node *node)
Insert a node after another node, can be used only for user-ordered nodes. If inserting several sibli...
struct lysc_node * schema
Definition: tree_data.h:765
LY_ERR lyd_merge_module(struct lyd_node **target, const struct lyd_node *source, const struct lys_module *mod, lyd_merge_cb merge_cb, void *cb_data, uint16_t options)
Merge all the nodes of a module from source data tree into the target data tree. Merge may not be com...
struct lysc_node * ctx_node
Definition: tree_data.h:600
struct ly_opaq_name name
Definition: tree_data.h:716
uint32_t hints
Definition: tree_data.h:718
Metadata structure.
Definition: tree_data.h:686
struct lysc_type_bitenum_item ** items
Definition: tree_data.h:610
LY_ERR lyd_find_sibling_dup_inst_set(const struct lyd_node *siblings, const struct lyd_node *target, struct ly_set **set)
Search the given siblings for all the exact same instances of a specific node instance. Accepts only nodes that are allowed to have several exact same instances. Uses hashes to whatever extent possible.
Special lyd_value structure for ietf-inet-types ipv6-address values.
Definition: tree_data.h:655
LY_ERR lyd_find_target(const struct ly_path *path, const struct lyd_node *tree, struct lyd_node **match)
Find the target node of a compiled path (lyd_value instance-identifier).
LYD_FORMAT
Data input/output formats supported by libyang parser and printer functions.
Definition: tree_data.h:508
YANG data representation.
Definition: tree_data.h:535
LY_ERR lyd_new_implicit_all(struct lyd_node **tree, const struct ly_ctx *ctx, uint32_t implicit_options, struct lyd_node **diff)
Add any missing implicit nodes. Default nodes with a false &quot;when&quot; are not added.
const char * _canonical
Definition: tree_data.h:536
LY_ERR lyd_insert_sibling(struct lyd_node *sibling, struct lyd_node *node, struct lyd_node **first)
Insert a node into siblings.
LY_ERR lyd_new_ext_term(const struct lysc_ext_instance *ext, const char *name, const char *val_str, struct lyd_node **node)
Create a new top-level term node defined in the given extension instance.
LY_ERR lyd_new_attr(struct lyd_node *parent, const char *module_name, const char *name, const char *value, struct lyd_attr **attr)
Create new JSON attribute for an opaque data node. To create an XML attribute, use lyd_new_attr2()...
LY_ERR lyd_find_sibling_first(const struct lyd_node *siblings, const struct lyd_node *target, struct lyd_node **match)
Search in the given siblings (NOT recursively) for the first target instance with the same value...
LY_ERR lyd_find_xpath(const struct lyd_node *ctx_node, const char *xpath, struct ly_set **set)
Search in the given data for instances of nodes matching the provided XPath.
void lyd_free_meta_siblings(struct lyd_meta *meta)
Free the metadata instance with any following instances.
LY_ERR lyd_find_xpath2(const struct lyd_node *ctx_node, const char *xpath, const struct lyxp_var *vars, struct ly_set **set)
Search in the given data for instances of nodes matching the provided XPath.
LY_ERR lyd_find_path(const struct lyd_node *ctx_node, const char *path, ly_bool output, struct lyd_node **match)
Search in given data for a node uniquely identified by a path.
LY_ERR lyd_new_list_canon(struct lyd_node *parent, const struct lys_module *module, const char *name, ly_bool output, struct lyd_node **node,...)
Create a new list node in the data tree.
struct lyd_node * lyd_child_no_keys(const struct lyd_node *node)
Get the child pointer of a generic data node but skip its keys in case it is LYS_LIST.
void lyd_free_attr_single(const struct ly_ctx *ctx, struct lyd_attr *attr)
Free a single attribute.
const char * name
Definition: tree_data.h:702
uint32_t hints
Definition: tree_data.h:595
#define LYS_ACTION
Definition: tree_schema.h:249
LY_ERR lyd_dup_meta_single(const struct lyd_meta *meta, struct lyd_node *parent, struct lyd_meta **dup)
Create a copy of the metadata.
Special lyd_value structure for ietf-inet-types ipv4-prefix values.
Definition: tree_data.h:640
LY_ERR lyd_insert_child(struct lyd_node *parent, struct lyd_node *node)
Insert a child into a parent.
void * val_prefix_data
Definition: tree_data.h:720
LY_ERR lyd_new_term_canon(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *val_str, ly_bool output, struct lyd_node **node)
Create a new term node in the data tree.
LY_ERR ly_time_time2str(time_t time, const char *fractions_s, char **str)
Convert UNIX timestamp and fractions of a second into canonical date-and-time string value...
LY_ERR lyd_new_inner(struct lyd_node *parent, const struct lys_module *module, const char *name, ly_bool output, struct lyd_node **node)
Create a new inner node in the data tree.
uint32_t flags
Definition: tree_data.h:764
Structure to hold a set of (not necessary somehow connected) objects. Usually used for lyd_node...
Definition: set.h:46
void * prefix_data
Definition: tree_data.h:599
LY_ERR lyd_eval_xpath2(const struct lyd_node *ctx_node, const char *xpath, const struct lyxp_var *vars, ly_bool *result)
Evaluate an XPath on data and return the result converted to boolean.
Available YANG schema tree structures representing YANG module.
Definition: tree_schema.h:2342
LY_ERR lyd_find_sibling_val(const struct lyd_node *siblings, const struct lysc_node *schema, const char *key_or_value, size_t val_len, struct lyd_node **match)
Search in the given siblings for the first schema instance. Uses hashes - should be used whenever pos...
struct in6_addr addr
Definition: tree_data.h:656
void lyd_free_siblings(struct lyd_node *node)
Free all the sibling nodes (preceding as well as succeeding).
char * mem
Definition: tree_data.h:842
LY_ERR(* lyd_diff_cb)(const struct lyd_node *diff_node, struct lyd_node *data_node, void *cb_data)
Callback for diff nodes.
Definition: tree_data.h:2117
const char * json
Definition: tree_data.h:841
const char * value
Definition: tree_data.h:717
Special lyd_value structure for ietf-inet-types ipv6-prefix values.
Definition: tree_data.h:663
Generic attribute structure.
Definition: tree_data.h:713
LY_ERR lyd_new_opaq2(struct lyd_node *parent, const struct ly_ctx *ctx, const char *name, const char *value, const char *prefix, const char *module_ns, struct lyd_node **node)
Create a new XML opaque node in the data tree. To create a JSON opaque node, use lyd_new_opaq().
#define LYD_CTX(node)
Macro to get context from a data tree node.
Definition: tree_data.h:502
struct lyd_attr * next
Definition: tree_data.h:715
void lyd_unlink_tree(struct lyd_node *node)
Unlink the specified data subtree.
LY_VALUE_FORMAT format
Definition: tree_data.h:719
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
Definition: tree.h:235
void lyd_unlink_siblings(struct lyd_node *node)
Unlink the specified node with all the following siblings.
#define LYS_NOTIF
Definition: tree_schema.h:250
const char * name
Definition: tree_data.h:690
#define LYD_NODE_TERM
Definition: tree_data.h:724
#define LYS_RPC
Definition: tree_schema.h:248
char * bitmap
Definition: tree_data.h:607
struct lyd_value value
Definition: tree_data.h:691
LY_ERR lyd_new_ext_path(struct lyd_node *parent, const struct lysc_ext_instance *ext, const char *path, const void *value, uint32_t options, struct lyd_node **node)
Create a new node defined in the given extension instance. In case of anyxml/anydata nodes...
LYD_ANYDATA_VALUETYPE value_type
Definition: tree_data.h:872
LYD_ANYDATA_VALUETYPE
List of possible value types stored in lyd_node_any.
Definition: tree_data.h:518
int lyd_lyb_data_length(const char *data)
Learn the length of LYB data.
LY_ERR lyd_change_term_canon(struct lyd_node *term, const char *val_str)
Change the value of a term (leaf or leaf-list) node to a canonical string value.
LY_ERR lyd_eval_xpath(const struct lyd_node *ctx_node, const char *xpath, ly_bool *result)
Evaluate an XPath on data and return the result converted to boolean.
LY_ERR lyd_new_path2(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const void *value, size_t value_len, LYD_ANYDATA_VALUETYPE value_type, uint32_t options, struct lyd_node **new_parent, struct lyd_node **new_node)
Create a new node in the data tree based on a path. All node types can be created.
Data node structure for unparsed (opaque) nodes.
Definition: tree_data.h:949
LY_ERR
libyang&#39;s error codes returned by the libyang functions.
Definition: log.h:245
struct lyd_node_term * lyd_target(const struct ly_path *path, const struct lyd_node *tree)
Deprecated, use lyd_find_target() instead.
LY_ERR lyd_value_validate(const struct ly_ctx *ctx, const struct lysc_node *schema, const char *value, size_t value_len, const struct lyd_node *ctx_node, const struct lysc_type **realtype, const char **canonical)
Check type restrictions applicable to the particular leaf/leaf-list with the given string value...
LY_ERR lyd_new_list2(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *keys, ly_bool output, struct lyd_node **node)
Create a new list node in the data tree.
Data node structure for the anydata data tree nodes - anydata or anyxml.
Definition: tree_data.h:849
Logger manipulation routines and error definitions.
struct lyd_meta * next
Definition: tree_data.h:688
Special lyd_value structure for built-in bits values.
Definition: tree_data.h:606
Special lyd_value structure for built-in union values.
Definition: tree_data.h:590
struct hash_table * children_ht
Definition: tree_data.h:802
struct lyd_node * prev
Definition: tree_data.h:768
LY_VALUE_FORMAT format
Definition: tree_data.h:596
LY_ERR lyd_diff_merge_all(struct lyd_node **diff, const struct lyd_node *src_diff, uint16_t options)
Merge 2 diffs into each other.
LY_ERR lyd_dup_siblings(const struct lyd_node *node, struct lyd_node_inner *parent, uint32_t options, struct lyd_node **dup)
Create a copy of the specified data tree node with any following siblings. Schema references are kept...
LY_ERR ly_time_str2time(const char *value, time_t *time, char **fractions_s)
Convert date-and-time from string to UNIX timestamp and fractions of a second.
LY_ERR lyd_diff_apply_module(struct lyd_node **data, const struct lyd_node *diff, const struct lys_module *mod, lyd_diff_cb diff_cb, void *cb_data)
Apply the whole diff on a data tree but restrict the operation to one module.
LY_ERR lyd_merge_siblings(struct lyd_node **target, const struct lyd_node *source, uint16_t options)
Merge the source data tree with any following siblings into the target data tree. Merge may not be co...
#define LYS_LIST
Definition: tree_schema.h:243
LY_ERR lyd_diff_reverse_all(const struct lyd_node *src_diff, struct lyd_node **diff)
Reverse a diff and make the opposite changes. Meaning change create to delete, delete to create...
const char * lyd_value_get_canonical(const struct ly_ctx *ctx, const struct lyd_value *value)
Get the (canonical) value of a lyd_value.
LY_ERR lyd_change_term(struct lyd_node *term, const char *val_str)
Change the value of a term (leaf or leaf-list) node to a string value.
libyang context handler.
LY_ERR lyd_change_meta(struct lyd_meta *meta, const char *val_str)
Change the value of a metadata instance.
LY_ERR lyd_any_value_str(const struct lyd_node *any, char **value_str)
Get anydata string value.
struct lyd_node * tree
Definition: tree_data.h:838
Special lyd_value structure for built-in binary values.
Definition: tree_data.h:617
struct lyd_value value
Definition: tree_data.h:591
void lyd_free_attr_siblings(const struct ly_ctx *ctx, struct lyd_attr *attr)
Free the attribute with any following attributes.
struct lyd_node * next
Definition: tree_data.h:767
void lyxp_vars_free(struct lyxp_var *vars)
Free the XPath variables.
struct lyd_node * parent
Definition: tree_data.h:687
LY_ERR lyd_diff_siblings(const struct lyd_node *first, const struct lyd_node *second, uint16_t options, struct lyd_node **diff)
Learn the differences between 2 data trees including all the following siblings.