libyang  2.0.7
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
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 
394 /* *INDENT-OFF* */
395 
421 #define LYD_TREE_DFS_BEGIN(START, ELEM) \
422  { ly_bool LYD_TREE_DFS_continue = 0; struct lyd_node *LYD_TREE_DFS_next; \
423  for ((ELEM) = (LYD_TREE_DFS_next) = (struct lyd_node *)(START); \
424  (ELEM); \
425  (ELEM) = (LYD_TREE_DFS_next), LYD_TREE_DFS_continue = 0)
426 
441 #define LYD_TREE_DFS_END(START, ELEM) \
442  /* select element for the next run - children first */ \
443  if (LYD_TREE_DFS_continue) { \
444  (LYD_TREE_DFS_next) = NULL; \
445  } else { \
446  (LYD_TREE_DFS_next) = lyd_child(ELEM); \
447  }\
448  if (!(LYD_TREE_DFS_next)) { \
449  /* no children */ \
450  if ((ELEM) == (struct lyd_node *)(START)) { \
451  /* we are done, (START) has no children */ \
452  break; \
453  } \
454  /* try siblings */ \
455  (LYD_TREE_DFS_next) = (ELEM)->next; \
456  } \
457  while (!(LYD_TREE_DFS_next)) { \
458  /* parent is already processed, go to its sibling */ \
459  (ELEM) = (struct lyd_node *)(ELEM)->parent; \
460  /* no siblings, go back through parents */ \
461  if ((ELEM)->parent == (START)->parent) { \
462  /* we are done, no next element to process */ \
463  break; \
464  } \
465  (LYD_TREE_DFS_next) = (ELEM)->next; \
466  } }
467 
475 #define LYD_LIST_FOR_INST(START, SCHEMA, ELEM) \
476  for (lyd_find_sibling_val(START, SCHEMA, NULL, 0, &(ELEM)); \
477  (ELEM) && ((ELEM)->schema == (SCHEMA)); \
478  (ELEM) = (ELEM)->next)
479 
488 #define LYD_LIST_FOR_INST_SAFE(START, SCHEMA, NEXT, ELEM) \
489  for (lyd_find_sibling_val(START, SCHEMA, NULL, 0, &(ELEM)); \
490  (ELEM) && ((ELEM)->schema == (SCHEMA)) ? ((NEXT) = (ELEM)->next, 1) : 0; \
491  (ELEM) = (NEXT))
492 
493 /* *INDENT-ON* */
494 
498 #define LYD_CTX(node) ((node)->schema ? (node)->schema->module->ctx : ((struct lyd_node_opaq *)(node))->ctx)
499 
504 typedef enum {
508  LYD_LYB
510 
514 typedef enum {
525 
531 struct lyd_value {
532  const char *_canonical;
535  const struct lysc_type *realtype;
543  union {
544  int8_t boolean;
545  int64_t dec64;
546  int8_t int8;
547  int16_t int16;
548  int32_t int32;
549  int64_t int64;
550  uint8_t uint8;
551  uint16_t uint16;
552  uint32_t uint32;
553  uint64_t uint64;
554  struct lysc_type_bitenum_item *enum_item;
555  struct lysc_ident *ident;
556  struct ly_path *target;
557  struct lyd_value_union *subvalue;
559  void *dyn_mem;
560  uint8_t fixed_mem[LYD_VALUE_FIXED_MEM_SIZE];
561  };
563 };
564 
573 #define LYD_VALUE_GET(value, type_val) \
574  ((sizeof *(type_val) > LYD_VALUE_FIXED_MEM_SIZE) \
575  ? ((type_val) = (((value)->dyn_mem))) \
576  : ((type_val) = ((void *)((value)->fixed_mem))))
577 
586  struct lyd_value value;
588  void *original;
589  size_t orig_len;
590  uint32_t hints;
594  void *prefix_data;
595  const struct lysc_node *ctx_node;
596 };
597 
602  char *bitmap;
607 };
608 
613  void *data;
614  size_t size;
615 };
616 
621  struct in_addr addr;
622 };
623 
628  struct in_addr addr;
629  const char *zone;
630 };
631 
636  struct in_addr addr;
637  uint8_t prefix;
638 };
639 
644  struct in6_addr addr;
645 };
646 
651  struct in6_addr addr;
652  const char *zone;
653 };
654 
659  struct in6_addr addr;
660  uint8_t prefix;
661 };
662 
667  time_t time;
668  char *fractions_s;
669 };
670 
681 struct lyd_meta {
682  struct lyd_node *parent;
683  struct lyd_meta *next;
685  const char *name;
686  struct lyd_value value;
687 };
688 
696 struct ly_opaq_name {
697  const char *name;
698  const char *prefix;
699  union {
700  const char *module_ns;
701  const char *module_name;
702  };
703 };
704 
708 struct lyd_attr {
710  struct lyd_attr *next;
711  struct ly_opaq_name name;
712  const char *value;
713  uint32_t hints;
716 };
717 
718 #define LYD_NODE_INNER (LYS_CONTAINER|LYS_LIST|LYS_RPC|LYS_ACTION|LYS_NOTIF)
719 #define LYD_NODE_TERM (LYS_LEAF|LYS_LEAFLIST)
720 #define LYD_NODE_ANY (LYS_ANYDATA)
745 #define LYD_DEFAULT 0x01
746 #define LYD_WHEN_TRUE 0x02
747 #define LYD_NEW 0x04
754 struct lyd_node {
755  uint32_t hash;
759  uint32_t flags;
760  const struct lysc_node *schema;
762  struct lyd_node *next;
763  struct lyd_node *prev;
767  struct lyd_meta *meta;
768  void *priv;
769 };
770 
775  union {
776  struct lyd_node node;
777  struct {
778  uint32_t hash;
783  uint32_t flags;
784  const struct lysc_node *schema;
785  struct lyd_node_inner *parent;
786  struct lyd_node *next;
787  struct lyd_node *prev;
791  struct lyd_meta *meta;
792  void *priv;
793  };
794  };
796  struct lyd_node *child;
797  struct hash_table *children_ht;
798 #define LYD_HT_MIN_ITEMS 4
799 };
800 
805  union {
806  struct lyd_node node;
807  struct {
808  uint32_t hash;
813  uint32_t flags;
814  const struct lysc_node *schema;
815  struct lyd_node_inner *parent;
816  struct lyd_node *next;
817  struct lyd_node *prev;
821  struct lyd_meta *meta;
822  void *priv;
823  };
824  };
826  struct lyd_value value;
827 };
828 
833  struct lyd_node *tree;
834  const char *str;
835  const char *xml;
836  const char *json;
837  char *mem;
838 };
839 
844 struct lyd_node_any {
845  union {
846  struct lyd_node node;
847  struct {
848  uint32_t hash;
853  uint32_t flags;
854  const struct lysc_node *schema;
855  struct lyd_node_inner *parent;
856  struct lyd_node *next;
857  struct lyd_node *prev;
861  struct lyd_meta *meta;
862  void *priv;
863  };
864  };
866  union lyd_any_value value;
868 };
869 
876 #define LYD_NAME(node) ((node)->schema ? (node)->schema->name : ((struct lyd_node_opaq *)node)->name.name)
877 
887 #define LYD_VALHINT_STRING 0x0001
888 #define LYD_VALHINT_DECNUM 0x0002
889 #define LYD_VALHINT_OCTNUM 0x0004
890 #define LYD_VALHINT_HEXNUM 0x0008
891 #define LYD_VALHINT_NUM64 0x0010
892 #define LYD_VALHINT_BOOLEAN 0x0020
893 #define LYD_VALHINT_EMPTY 0x0040
907 #define LYD_NODEHINT_LIST 0x0080
908 #define LYD_NODEHINT_LEAFLIST 0x0100
923 #define LYD_HINT_DATA 0x01F3
927 #define LYD_HINT_SCHEMA 0x01FF
939  union {
940  struct lyd_node node;
941  struct {
942  uint32_t hash;
943  uint32_t flags;
944  const struct lysc_node *schema;
945  struct lyd_node_inner *parent;
946  struct lyd_node *next;
947  struct lyd_node *prev;
951  struct lyd_meta *meta;
952  void *priv;
953  };
954  };
956  struct lyd_node *child;
958  struct ly_opaq_name name;
959  const char *value;
960  uint32_t hints;
964  struct lyd_attr *attr;
965  const struct ly_ctx *ctx;
966 };
967 
975 static inline struct lyd_node *
976 lyd_parent(const struct lyd_node *node)
977 {
978  if (!node) {
979  return NULL;
980  }
981 
982  return &node->parent->node;
983 }
984 
995 static inline struct lyd_node *
996 lyd_child(const struct lyd_node *node)
997 {
998  if (!node) {
999  return NULL;
1000  }
1001 
1002  if (!node->schema) {
1003  /* opaq node */
1004  return ((struct lyd_node_opaq *)node)->child;
1005  }
1006 
1007  switch (node->schema->nodetype) {
1008  case LYS_CONTAINER:
1009  case LYS_LIST:
1010  case LYS_RPC:
1011  case LYS_ACTION:
1012  case LYS_NOTIF:
1013  return ((struct lyd_node_inner *)node)->child;
1014  default:
1015  return NULL;
1016  }
1017 }
1018 
1029 struct lyd_node *lyd_child_no_keys(const struct lyd_node *node);
1030 
1040 const struct lys_module *lyd_owner_module(const struct lyd_node *node);
1041 
1048 ly_bool lyd_is_default(const struct lyd_node *node);
1049 
1057 uint32_t lyd_list_pos(const struct lyd_node *instance);
1058 
1065 struct lyd_node *lyd_first_sibling(const struct lyd_node *node);
1066 
1074 int lyd_lyb_data_length(const char *data);
1075 
1085 const char *lyd_value_get_canonical(const struct ly_ctx *ctx, const struct lyd_value *value);
1086 
1093 static inline const char *
1094 lyd_get_value(const struct lyd_node *node)
1095 {
1096  if (!node) {
1097  return NULL;
1098  }
1099 
1100  if (!node->schema) {
1101  return ((struct lyd_node_opaq *)node)->value;
1102  } else if (node->schema->nodetype & LYD_NODE_TERM) {
1103  const struct lyd_value *value = &((struct lyd_node_term *)node)->value;
1105  }
1106 
1107  return NULL;
1108 }
1109 
1116 static inline const char *
1117 lyd_get_meta_value(const struct lyd_meta *meta)
1118 {
1119  if (meta) {
1120  const struct lyd_value *value = &meta->value;
1121  return value->_canonical ? value->_canonical : lyd_value_get_canonical(meta->annotation->module->ctx, value);
1122  }
1123 
1124  return NULL;
1125 }
1126 
1134 LY_ERR lyd_any_value_str(const struct lyd_node *any, char **value_str);
1135 
1144 LY_ERR lyd_any_copy_value(struct lyd_node *trg, const union lyd_any_value *value, LYD_ANYDATA_VALUETYPE value_type);
1145 
1161 LY_ERR lyd_new_inner(struct lyd_node *parent, const struct lys_module *module, const char *name, ly_bool output,
1162  struct lyd_node **node);
1163 
1177 LY_ERR lyd_new_ext_inner(const struct lysc_ext_instance *ext, const char *name, struct lyd_node **node);
1178 
1193 LY_ERR lyd_new_list(struct lyd_node *parent, const struct lys_module *module, const char *name, ly_bool output,
1194  struct lyd_node **node, ...);
1195 
1210 LY_ERR lyd_new_ext_list(const struct lysc_ext_instance *ext, const char *name, struct lyd_node **node, ...);
1211 
1226 LY_ERR lyd_new_list2(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *keys,
1227  ly_bool output, struct lyd_node **node);
1228 
1243 LY_ERR lyd_new_term(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *val_str,
1244  ly_bool output, struct lyd_node **node);
1245 
1259 LY_ERR lyd_new_term_bin(struct lyd_node *parent, const struct lys_module *module, const char *name, const void *value,
1260  size_t value_len, ly_bool output, struct lyd_node **node);
1261 
1274 LY_ERR lyd_new_term_canon(struct lyd_node *parent, const struct lys_module *module, const char *name,
1275  const char *val_str, ly_bool output, struct lyd_node **node);
1276 
1290 LY_ERR lyd_new_ext_term(const struct lysc_ext_instance *ext, const char *name, const char *val_str, struct lyd_node **node);
1291 
1308 LY_ERR lyd_new_any(struct lyd_node *parent, const struct lys_module *module, const char *name, const void *value,
1309  ly_bool use_value, LYD_ANYDATA_VALUETYPE value_type, ly_bool output, struct lyd_node **node);
1310 
1325 LY_ERR lyd_new_ext_any(const struct lysc_ext_instance *ext, const char *name, const void *value, ly_bool use_value,
1326  LYD_ANYDATA_VALUETYPE value_type, struct lyd_node **node);
1327 
1342 LY_ERR lyd_new_meta(const struct ly_ctx *ctx, struct lyd_node *parent, const struct lys_module *module, const char *name,
1343  const char *val_str, ly_bool clear_dflt, struct lyd_meta **meta);
1344 
1357 LY_ERR lyd_new_meta2(const struct ly_ctx *ctx, struct lyd_node *parent, ly_bool clear_dflt, const struct lyd_attr *attr,
1358  struct lyd_meta **meta);
1359 
1372 LY_ERR lyd_new_opaq(struct lyd_node *parent, const struct ly_ctx *ctx, const char *name, const char *value,
1373  const char *prefix, const char *module_name, struct lyd_node **node);
1374 
1387 LY_ERR lyd_new_opaq2(struct lyd_node *parent, const struct ly_ctx *ctx, const char *name, const char *value,
1388  const char *prefix, const char *module_ns, struct lyd_node **node);
1389 
1400 LY_ERR lyd_new_attr(struct lyd_node *parent, const char *module_name, const char *name, const char *value,
1401  struct lyd_attr **attr);
1402 
1413 LY_ERR lyd_new_attr2(struct lyd_node *parent, const char *module_ns, const char *name, const char *value,
1414  struct lyd_attr **attr);
1415 
1429 #define LYD_NEW_PATH_UPDATE 0x01
1433 #define LYD_NEW_PATH_OUTPUT 0x02
1435 #define LYD_NEW_PATH_OPAQ 0x04
1438 #define LYD_NEW_PATH_BIN_VALUE 0x08
1440 #define LYD_NEW_PATH_CANON_VALUE 0x10
1470 LY_ERR lyd_new_path(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const char *value,
1471  uint32_t options, struct lyd_node **node);
1472 
1493 LY_ERR lyd_new_path2(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const void *value,
1494  size_t value_len, LYD_ANYDATA_VALUETYPE value_type, uint32_t options, struct lyd_node **new_parent,
1495  struct lyd_node **new_node);
1496 
1515 LY_ERR lyd_new_ext_path(struct lyd_node *parent, const struct lysc_ext_instance *ext, const char *path, const void *value,
1516  uint32_t options, struct lyd_node **node);
1517 
1531 #define LYD_IMPLICIT_NO_STATE 0x01
1532 #define LYD_IMPLICIT_NO_CONFIG 0x02
1533 #define LYD_IMPLICIT_OUTPUT 0x04
1534 #define LYD_IMPLICIT_NO_DEFAULTS 0x08
1547 LY_ERR lyd_new_implicit_tree(struct lyd_node *tree, uint32_t implicit_options, struct lyd_node **diff);
1548 
1560 LY_ERR lyd_new_implicit_all(struct lyd_node **tree, const struct ly_ctx *ctx, uint32_t implicit_options, struct lyd_node **diff);
1561 
1573 LY_ERR lyd_new_implicit_module(struct lyd_node **tree, const struct lys_module *module, uint32_t implicit_options,
1574  struct lyd_node **diff);
1575 
1589 LY_ERR lyd_change_term(struct lyd_node *term, const char *val_str);
1590 
1605 LY_ERR lyd_change_term_bin(struct lyd_node *term, const void *value, size_t value_len);
1606 
1621 LY_ERR lyd_change_term_canon(struct lyd_node *term, const char *val_str);
1622 
1632 LY_ERR lyd_change_meta(struct lyd_meta *meta, const char *val_str);
1633 
1645 LY_ERR lyd_insert_child(struct lyd_node *parent, struct lyd_node *node);
1646 
1659 LY_ERR lyd_insert_sibling(struct lyd_node *sibling, struct lyd_node *node, struct lyd_node **first);
1660 
1672 LY_ERR lyd_insert_before(struct lyd_node *sibling, struct lyd_node *node);
1673 
1685 LY_ERR lyd_insert_after(struct lyd_node *sibling, struct lyd_node *node);
1686 
1692 void lyd_unlink_tree(struct lyd_node *node);
1693 
1699 void lyd_free_all(struct lyd_node *node);
1700 
1706 void lyd_free_siblings(struct lyd_node *node);
1707 
1713 void lyd_free_tree(struct lyd_node *node);
1714 
1720 void lyd_free_meta_single(struct lyd_meta *meta);
1721 
1728 
1735 void lyd_free_attr_single(const struct ly_ctx *ctx, struct lyd_attr *attr);
1736 
1743 void lyd_free_attr_siblings(const struct ly_ctx *ctx, struct lyd_attr *attr);
1744 
1763 LY_ERR lyd_value_validate(const struct ly_ctx *ctx, const struct lysc_node *schema, const char *value, size_t value_len,
1764  const struct lyd_node *ctx_node, const struct lysc_type **realtype, const char **canonical);
1765 
1778 LY_ERR lyd_value_compare(const struct lyd_node_term *node, const char *value, size_t value_len);
1779 
1786 #define LYD_COMPARE_FULL_RECURSION 0x01 /* lists and containers are the same only in case all they children
1787  (subtree, so direct as well as indirect children) are the same. By default,
1788  containers are the same in case of the same schema node and lists are the same
1789  in case of equal keys (keyless lists do the full recursion comparison all the time). */
1790 #define LYD_COMPARE_DEFAULTS 0x02 /* By default, implicit and explicit default nodes are considered to be equal. This flag
1791  changes this behavior and implicit (automatically created default node) and explicit
1792  (explicitly created node with the default value) default nodes are considered different. */
1804 LY_ERR lyd_compare_single(const struct lyd_node *node1, const struct lyd_node *node2, uint32_t options);
1805 
1815 LY_ERR lyd_compare_siblings(const struct lyd_node *node1, const struct lyd_node *node2, uint32_t options);
1816 
1825 LY_ERR lyd_compare_meta(const struct lyd_meta *meta1, const struct lyd_meta *meta2);
1826 
1839 #define LYD_DUP_RECURSIVE 0x01
1841 #define LYD_DUP_NO_META 0x02
1842 #define LYD_DUP_WITH_PARENTS 0x04
1844 #define LYD_DUP_WITH_FLAGS 0x08
1861 LY_ERR lyd_dup_single(const struct lyd_node *node, struct lyd_node_inner *parent, uint32_t options, struct lyd_node **dup);
1862 
1875 LY_ERR lyd_dup_siblings(const struct lyd_node *node, struct lyd_node_inner *parent, uint32_t options, struct lyd_node **dup);
1876 
1885 LY_ERR lyd_dup_meta_single(const struct lyd_meta *meta, struct lyd_node *parent, struct lyd_meta **dup);
1886 
1900 #define LYD_MERGE_DESTRUCT 0x01
1901 #define LYD_MERGE_DEFAULTS 0x02
1925 LY_ERR lyd_merge_tree(struct lyd_node **target, const struct lyd_node *source, uint16_t options);
1926 
1948 LY_ERR lyd_merge_siblings(struct lyd_node **target, const struct lyd_node *source, uint16_t options);
1949 
1959 typedef LY_ERR (*lyd_merge_cb)(struct lyd_node *trg_node, const struct lyd_node *src_node, void *cb_data);
1960 
1976 LY_ERR lyd_merge_module(struct lyd_node **target, const struct lyd_node *source, const struct lys_module *mod,
1977  lyd_merge_cb merge_cb, void *cb_data, uint16_t options);
1978 
1990 #define LYD_DIFF_DEFAULTS 0x01
2021 LY_ERR lyd_diff_tree(const struct lyd_node *first, const struct lyd_node *second, uint16_t options, struct lyd_node **diff);
2022 
2035 LY_ERR lyd_diff_siblings(const struct lyd_node *first, const struct lyd_node *second, uint16_t options, struct lyd_node **diff);
2036 
2045 typedef LY_ERR (*lyd_diff_cb)(const struct lyd_node *diff_node, struct lyd_node *data_node, void *cb_data);
2046 
2063 LY_ERR lyd_diff_apply_module(struct lyd_node **data, const struct lyd_node *diff, const struct lys_module *mod,
2064  lyd_diff_cb diff_cb, void *cb_data);
2065 
2076 LY_ERR lyd_diff_apply_all(struct lyd_node **data, const struct lyd_node *diff);
2077 
2089 #define LYD_DIFF_MERGE_DEFAULTS 0x01
2117 LY_ERR lyd_diff_merge_module(struct lyd_node **diff, const struct lyd_node *src_diff, const struct lys_module *mod,
2118  lyd_diff_cb diff_cb, void *cb_data, uint16_t options);
2119 
2136 LY_ERR lyd_diff_merge_tree(struct lyd_node **diff_first, struct lyd_node *diff_parent, const struct lyd_node *src_sibling,
2137  lyd_diff_cb diff_cb, void *cb_data, uint16_t options);
2138 
2150 LY_ERR lyd_diff_merge_all(struct lyd_node **diff, const struct lyd_node *src_diff, uint16_t options);
2151 
2161 LY_ERR lyd_diff_reverse_all(const struct lyd_node *src_diff, struct lyd_node **diff);
2162 
2171 const struct lyd_node_term *lyd_target(const struct ly_path *path, const struct lyd_node *tree);
2172 
2176 typedef enum {
2177  LYD_PATH_STD,
2181 } LYD_PATH_TYPE;
2182 
2194 char *lyd_path(const struct lyd_node *node, LYD_PATH_TYPE pathtype, char *buffer, size_t buflen);
2195 
2205 struct lyd_meta *lyd_find_meta(const struct lyd_meta *first, const struct lys_module *module, const char *name);
2206 
2218 LY_ERR lyd_find_sibling_first(const struct lyd_node *siblings, const struct lyd_node *target, struct lyd_node **match);
2219 
2244 LY_ERR lyd_find_sibling_val(const struct lyd_node *siblings, const struct lysc_node *schema, const char *key_or_value,
2245  size_t val_len, struct lyd_node **match);
2246 
2258 LY_ERR lyd_find_sibling_dup_inst_set(const struct lyd_node *siblings, const struct lyd_node *target, struct ly_set **set);
2259 
2270 LY_ERR lyd_find_sibling_opaq_next(const struct lyd_node *first, const char *name, struct lyd_node **match);
2271 
2287 LY_ERR lyd_find_xpath(const struct lyd_node *ctx_node, const char *xpath, struct ly_set **set);
2288 
2304 LY_ERR lyd_find_path(const struct lyd_node *ctx_node, const char *path, ly_bool output, struct lyd_node **match);
2305 
2314 LY_ERR ly_time_str2time(const char *value, time_t *time, char **fractions_s);
2315 
2324 LY_ERR ly_time_time2str(time_t time, const char *fractions_s, char **str);
2325 
2333 LY_ERR ly_time_str2ts(const char *value, struct timespec *ts);
2334 
2342 LY_ERR ly_time_ts2str(const struct timespec *ts, char **str);
2343 
2344 #ifdef __cplusplus
2345 }
2346 #endif
2347 
2348 #endif /* LY_TREE_DATA_H_ */
libyang context handler.
LYD_ANYDATA_VALUETYPE
List of possible value types stored in lyd_node_any.
Definition: tree_data.h:514
LYD_FORMAT
Data input/output formats supported by libyang parser and printer functions.
Definition: tree_data.h:504
#define LYD_CTX(node)
Macro to get context from a data tree node.
Definition: tree_data.h:498
@ LYD_ANYDATA_DATATREE
Definition: tree_data.h:515
@ LYD_ANYDATA_JSON
Definition: tree_data.h:522
@ LYD_ANYDATA_XML
Definition: tree_data.h:521
@ LYD_ANYDATA_LYB
Definition: tree_data.h:523
@ LYD_ANYDATA_STRING
Definition: tree_data.h:518
@ LYD_LYB
Definition: tree_data.h:508
@ LYD_XML
Definition: tree_data.h:506
@ LYD_UNKNOWN
Definition: tree_data.h:505
@ LYD_JSON
Definition: tree_data.h:507
LY_ERR
libyang's error codes returned by the libyang functions.
Definition: log.h:242
Structure to hold a set of (not necessary somehow connected) objects. Usually used for lyd_node,...
Definition: set.h:47
#define LYS_NOTIF
Definition: tree_schema.h:248
#define LYS_RPC
Definition: tree_schema.h:246
#define LYS_CONTAINER
Definition: tree_schema.h:237
#define LYS_ACTION
Definition: tree_schema.h:247
#define LYS_LIST
Definition: tree_schema.h:241
uint16_t nodetype
Definition: tree_schema.h:1645
struct lys_module * module
Definition: tree_schema.h:1428
struct ly_ctx * ctx
Definition: tree_schema.h:2296
Available YANG schema tree structures representing YANG module.
Definition: tree_schema.h:2295
YANG extension instance.
Definition: tree_schema.h:1425
YANG identity-stmt.
Definition: tree_schema.h:1458
Compiled YANG data node.
Definition: tree_schema.h:1644
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
Definition: tree.h:235
Logger manipulation routines and error definitions.
uint8_t ly_bool
Type to indicate boolean value.
Definition: log.h:25
libyang generic macros and functions to work with YANG schema or data trees.
LY_VALUE_FORMAT format
Definition: tree_data.h:714
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().
struct lyd_node * next
Definition: tree_data.h:762
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,...
LY_ERR lyd_any_value_str(const struct lyd_node *any, char **value_str)
Get anydata string value.
struct lyd_node * lyd_first_sibling(const struct lyd_node *node)
Get the first sibling of the given node.
LY_ERR ly_time_ts2str(const struct timespec *ts, char **str)
Convert timespec into date-and-time string value.
void * val_prefix_data
Definition: tree_data.h:962
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.
struct lyd_meta * next
Definition: tree_data.h:683
const char * prefix
Definition: tree_data.h:698
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.
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 in_addr addr
Definition: tree_data.h:628
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...
const char * str
Definition: tree_data.h:834
LYD_PATH_TYPE
Types of the different data paths.
Definition: tree_data.h:2171
@ LYD_PATH_STD_NO_LAST_PRED
Definition: tree_data.h:2174
@ LYD_PATH_STD
Definition: tree_data.h:2172
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.
struct lyd_value value
Definition: tree_data.h:826
const struct lysc_type * realtype
Definition: tree_data.h:535
char * mem
Definition: tree_data.h:837
struct lyd_node * tree
Definition: tree_data.h:833
uint32_t hints
Definition: tree_data.h:713
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 "when" are not added.
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.
LYD_ANYDATA_VALUETYPE value_type
Definition: tree_data.h:867
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...
LY_ERR lyd_new_implicit_tree(struct lyd_node *tree, uint32_t implicit_options, struct lyd_node **diff)
Add any missing implicit nodes into a data subtree. Default nodes with a false "when" are not added.
struct lyd_attr * attr
Definition: tree_data.h:964
void lyd_unlink_tree(struct lyd_node *node)
Unlink the specified data subtree.
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.
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_diff_tree(const struct lyd_node *first, const struct lyd_node *second, uint16_t options, struct lyd_node **diff)
Learn the differences between 2 data trees.
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:2040
struct lyd_node * child
Definition: tree_data.h:956
const char * json
Definition: tree_data.h:836
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_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.
struct lysc_type_bitenum_item ** items
Definition: tree_data.h:605
const struct ly_ctx * ctx
Definition: tree_data.h:965
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.
void lyd_free_meta_siblings(struct lyd_meta *meta)
Free the metadata instance with any following instances.
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.
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.
void * original
Definition: tree_data.h:588
LY_ERR lyd_compare_meta(const struct lyd_meta *meta1, const struct lyd_meta *meta2)
Compare 2 metadata.
int lyd_lyb_data_length(const char *data)
Learn the length of LYB data.
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.
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_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:1954
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.
struct lyd_meta * meta
Definition: tree_data.h:767
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...
const char * name
Definition: tree_data.h:685
uint32_t flags
Definition: tree_data.h:759
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_diff_merge_module(struct lyd_node **diff, const struct lyd_node *src_diff, const struct lys_module *mod, lyd_diff_cb diff_cb, void *cb_data, uint16_t options)
Merge 2 diffs into each other but restrict the operation to one module.
const 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....
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.
struct lyd_value value
Definition: tree_data.h:686
const struct lysc_node * schema
Definition: tree_data.h:760
struct in6_addr addr
Definition: tree_data.h:651
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...
const char * value
Definition: tree_data.h:959
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...
void lyd_free_siblings(struct lyd_node *node)
Free all the sibling nodes (preceding as well as succeeding).
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 lyd_free_all(struct lyd_node *node)
Free all the nodes (even parents of the node) in the data tree.
ly_bool lyd_is_default(const struct lyd_node *node)
Check whether a node value equals to its default one.
void lyd_free_attr_siblings(const struct ly_ctx *ctx, struct lyd_attr *attr)
Free the attribute with any following attributes.
const struct lyd_node_term * lyd_target(const struct ly_path *path, const struct lyd_node *tree)
Find the target in data of a compiled instance-identifier path (the target member in lyd_value).
LY_ERR lyd_change_meta(struct lyd_meta *meta, const char *val_str)
Change the value of a metadata instance.
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.
const char * name
Definition: tree_data.h:697
LY_ERR lyd_dup_single(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. Schema references are kept the same.
void * prefix_data
Definition: tree_data.h:594
struct lysc_ext_instance * annotation
Definition: tree_data.h:684
const char * zone
Definition: tree_data.h:652
#define LYD_NODE_TERM
Definition: tree_data.h:719
uint32_t hints
Definition: tree_data.h:960
void lyd_free_attr_single(const struct ly_ctx *ctx, struct lyd_attr *attr)
Free a single attribute.
LY_ERR ly_time_str2ts(const char *value, struct timespec *ts)
Convert date-and-time from string to timespec.
struct hash_table * children_ht
Definition: tree_data.h:797
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.
struct ly_opaq_name name
Definition: tree_data.h:711
LY_ERR lyd_diff_apply_all(struct lyd_node **data, const struct lyd_node *diff)
Apply the whole diff tree on a data tree.
const char * zone
Definition: tree_data.h:629
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_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.
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_compare_single(const struct lyd_node *node1, const struct lyd_node *node2, uint32_t options)
Compare 2 data nodes if they are equivalent.
uint32_t hash
Definition: tree_data.h:755
void * val_prefix_data
Definition: tree_data.h:715
struct in_addr addr
Definition: tree_data.h:636
struct lyd_node * prev
Definition: tree_data.h:763
void lyd_free_tree(struct lyd_node *node)
Free (and unlink) the specified data (sub)tree.
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 lyd_node * child
Definition: tree_data.h:796
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_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.
const char * xml
Definition: tree_data.h:835
LY_ERR lyd_value_compare(const struct lyd_node_term *node, const char *value, size_t value_len)
Compare the node's value with the given string value. The string value is first validated according t...
void * priv
Definition: tree_data.h:768
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.
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 "when" are not added.
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.
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().
char * bitmap
Definition: tree_data.h:602
LY_VALUE_FORMAT format
Definition: tree_data.h:961
void lyd_free_meta_single(struct lyd_meta *meta)
Free a single metadata instance.
const char * value
Definition: tree_data.h:712
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_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_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,...
union lyd_any_value value
Definition: tree_data.h:866
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....
struct lyd_attr * next
Definition: tree_data.h:710
LY_ERR lyd_insert_child(struct lyd_node *parent, struct lyd_node *node)
Insert a child into a parent.
uint32_t hints
Definition: tree_data.h:590
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().
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_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...
struct in6_addr addr
Definition: tree_data.h:659
size_t orig_len
Definition: tree_data.h:589
struct lyd_value value
Definition: tree_data.h:586
LY_ERR lyd_merge_tree(struct lyd_node **target, const struct lyd_node *source, uint16_t options)
Merge the source data subtree into the target data tree. Merge may not be complete until validation i...
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.
const char * _canonical
Definition: tree_data.h:532
struct lyd_node_opaq * parent
Definition: tree_data.h:709
LY_VALUE_FORMAT format
Definition: tree_data.h:591
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.
struct lyd_node_inner * parent
Definition: tree_data.h:761
struct ly_opaq_name name
Definition: tree_data.h:958
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_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.
LY_ERR lyd_new_path(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const char *value, uint32_t options, struct lyd_node **node)
Create a new node in the data tree based on a path. If creating anyxml/anydata nodes,...
LY_ERR lyd_insert_sibling(struct lyd_node *sibling, struct lyd_node *node, struct lyd_node **first)
Insert a node into siblings.
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.
struct lyd_node * parent
Definition: tree_data.h:682
const struct lysc_node * ctx_node
Definition: tree_data.h:595
Generic prefix and namespace mapping, meaning depends on the format.
Definition: tree_data.h:696
Generic attribute structure.
Definition: tree_data.h:708
Metadata structure.
Definition: tree_data.h:681
Generic structure for a data node.
Definition: tree_data.h:754
Data node structure for the anydata data tree nodes - anydata or anyxml.
Definition: tree_data.h:844
Data node structure for the inner data tree nodes - containers, lists, RPCs, actions and Notification...
Definition: tree_data.h:774
Data node structure for unparsed (opaque) nodes.
Definition: tree_data.h:938
Data node structure for the terminal data tree nodes - leaves and leaf-lists.
Definition: tree_data.h:804
YANG data representation.
Definition: tree_data.h:531
Special lyd_value structure for built-in binary values.
Definition: tree_data.h:612
Special lyd_value structure for built-in bits values.
Definition: tree_data.h:601
Special lyd_value structure for ietf-yang-types date-and-time values.
Definition: tree_data.h:666
Special lyd_value structure for ietf-inet-types ipv4-address values.
Definition: tree_data.h:627
Special lyd_value structure for ietf-inet-types ipv4-address-no-zone values.
Definition: tree_data.h:620
Special lyd_value structure for ietf-inet-types ipv4-prefix values.
Definition: tree_data.h:635
Special lyd_value structure for ietf-inet-types ipv6-address values.
Definition: tree_data.h:650
Special lyd_value structure for ietf-inet-types ipv6-address-no-zone values.
Definition: tree_data.h:643
Special lyd_value structure for ietf-inet-types ipv6-prefix values.
Definition: tree_data.h:658
Special lyd_value structure for built-in union values.
Definition: tree_data.h:585
union for anydata/anyxml value representation.
Definition: tree_data.h:832
libyang representation of YANG schema trees.