libyang 4.7.3
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
Loading...
Searching...
No Matches
tree_data.h
Go to the documentation of this file.
1
15
16#ifndef LY_TREE_DATA_H_
17#define LY_TREE_DATA_H_
18
19/* socket/ip includes in ly_config.h */
20
21#include <stddef.h>
22#include <stdint.h>
23#include <time.h>
24
25#include "log.h"
26#include "ly_config.h"
27#include "tree.h"
28#include "tree_schema.h"
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34struct ly_ctx;
35struct ly_path;
36struct ly_set;
37struct lyd_node;
38struct lyd_node_opaq;
39struct lyd_node_term;
40struct timespec;
41struct lyxp_var;
42struct rb_node;
43
208
338
391
403
411
412/* *INDENT-OFF* */
413
439#define LYD_TREE_DFS_BEGIN(START, ELEM) \
440 { ly_bool LYD_TREE_DFS_continue = 0; struct lyd_node *LYD_TREE_DFS_next; \
441 for ((ELEM) = (LYD_TREE_DFS_next) = (struct lyd_node *)(START); \
442 (ELEM); \
443 (ELEM) = (LYD_TREE_DFS_next), LYD_TREE_DFS_continue = 0)
444
458
459#define LYD_TREE_DFS_END(START, ELEM) \
460 /* select element for the next run - children first */ \
461 if (LYD_TREE_DFS_continue) { \
462 (LYD_TREE_DFS_next) = NULL; \
463 } else { \
464 (LYD_TREE_DFS_next) = lyd_child(ELEM); \
465 }\
466 if (!(LYD_TREE_DFS_next)) { \
467 /* no children */ \
468 if ((ELEM) == (struct lyd_node *)(START)) { \
469 /* we are done, (START) has no children */ \
470 break; \
471 } \
472 /* try siblings */ \
473 (LYD_TREE_DFS_next) = (ELEM)->next; \
474 } \
475 while (!(LYD_TREE_DFS_next)) { \
476 /* parent is already processed, go to its sibling */ \
477 (ELEM) = (struct lyd_node *)(ELEM)->parent; \
478 /* no siblings, go back through parents */ \
479 if ((ELEM)->parent == (START)->parent) { \
480 /* we are done, no next element to process */ \
481 break; \
482 } \
483 (LYD_TREE_DFS_next) = (ELEM)->next; \
484 } }
485
493#define LYD_LIST_FOR_INST(START, SCHEMA, ELEM) \
494 for (lyd_find_sibling_val(START, SCHEMA, NULL, 0, &(ELEM)); \
495 (ELEM) && ((ELEM)->schema == (SCHEMA)); \
496 (ELEM) = (ELEM)->next)
497
506#define LYD_LIST_FOR_INST_SAFE(START, SCHEMA, NEXT, ELEM) \
507 for ((NEXT) = (ELEM) = NULL, lyd_find_sibling_val(START, SCHEMA, NULL, 0, &(ELEM)); \
508 (ELEM) && ((ELEM)->schema == (SCHEMA)) ? ((NEXT) = (ELEM)->next, 1) : 0; \
509 (ELEM) = (NEXT))
510
511/* *INDENT-ON* */
512
516#define LYD_CTX(node) ((node)->schema ? (node)->schema->module->ctx : ((const struct lyd_node_opaq *)(node))->ctx)
517
525#define LYD_NODE_IS_ALONE(NODE) \
526 (((NODE)->prev == NODE) || \
527 (((NODE)->prev->schema != (NODE)->schema) && (!(NODE)->next || ((NODE)->schema != (NODE)->next->schema))))
528
539
554
556
560struct lyd_value {
561 const char *_canonical;
564 const struct lysc_type *realtype;
571
572 union {
573 int8_t boolean;
574 int64_t dec64;
575 int8_t int8;
576 int16_t int16;
577 int32_t int32;
578 int64_t int64;
579 uint8_t uint8;
580 uint16_t uint16;
581 uint32_t uint32;
582 uint64_t uint64;
584 struct lysc_ident *ident;
585 struct ly_path *target;
587 struct lyd_value_union *subvalue;
588
589 void *dyn_mem;
590 uint8_t fixed_mem[LYD_VALUE_FIXED_MEM_SIZE];
591 };
592
593};
594
603#define LYD_VALUE_GET(value, type_val) \
604 ((sizeof *(type_val) > LYD_VALUE_FIXED_MEM_SIZE) \
605 ? ((type_val) = (((value)->dyn_mem))) \
606 : ((type_val) = ((void *)((value)->fixed_mem))))
607
628
639
644 void *data;
645 uint32_t size;
646};
647
652 struct in_addr addr;
653};
654
659 struct in_addr addr;
660 const char *zone;
661};
662
667 struct in_addr addr;
668 uint8_t prefix;
669};
670
675 struct in6_addr addr;
676};
677
682 struct in6_addr addr;
683 const char *zone;
684};
685
690 struct in6_addr addr;
691 uint8_t prefix;
692};
693
702
710
715 time_t time;
716};
717
726
731 uint32_t seconds;
733};
734
739 struct lyxp_expr *exp;
740 const struct ly_ctx *ctx;
743};
744
749 struct rb_node *rbt;
750};
751
760 const char *name;
761 const char *prefix;
762
763 union {
764 const char *module_ns;
765 const char *module_name;
766 };
767};
768
781
782#define LYD_NODE_INNER (LYS_CONTAINER|LYS_LIST|LYS_RPC|LYS_ACTION|LYS_NOTIF)
783#define LYD_NODE_TERM (LYS_LEAF|LYS_LEAFLIST)
784#define LYD_NODE_ANY (LYS_ANYDATA)
785
810
811#define LYD_DEFAULT 0x01
812#define LYD_WHEN_TRUE 0x02
813#define LYD_NEW 0x04
814#define LYD_EXT 0x08
815
817
821struct lyd_node {
822 uint32_t hash;
826 uint32_t flags;
827 const struct lysc_node *schema;
829 struct lyd_node *next;
830 struct lyd_node *prev;
834 struct lyd_meta *meta;
835 void *priv;
836};
837
842 union {
843 struct lyd_node node;
844
845 struct {
846 uint32_t hash;
851 uint32_t flags;
852 const struct lysc_node *schema;
853 struct lyd_node_inner *parent;
854 struct lyd_node *next;
855 struct lyd_node *prev;
859 struct lyd_meta *meta;
860 void *priv;
861 };
862 };
863
864 struct lyd_node *child;
866
867#define LYD_HT_MIN_ITEMS 4
868};
869
874 union {
875 struct lyd_node node;
876
877 struct {
878 uint32_t hash;
883 uint32_t flags;
884 const struct lysc_node *schema;
885 struct lyd_node_inner *parent;
886 struct lyd_node *next;
887 struct lyd_node *prev;
891 struct lyd_meta *meta;
892 void *priv;
893 };
894 };
895
897};
898
903 struct lyd_node *tree;
904 const char *str;
905 const char *xml;
906 const char *json;
907};
908
914 union {
915 struct lyd_node node;
916
917 struct {
918 uint32_t hash;
923 uint32_t flags;
924 const struct lysc_node *schema;
925 struct lyd_node_inner *parent;
926 struct lyd_node *next;
927 struct lyd_node *prev;
931 struct lyd_meta *meta;
932 void *priv;
933 };
934 };
935
938};
939
946#define LYD_NAME(node) ((node)->schema ? (node)->schema->name : ((struct lyd_node_opaq *)node)->name.name)
947
957#define LYD_VALHINT_STRING 0x0001
958#define LYD_VALHINT_DECNUM 0x0002
959#define LYD_VALHINT_OCTNUM 0x0004
960#define LYD_VALHINT_HEXNUM 0x0008
961#define LYD_VALHINT_NUM64 0x0010
962#define LYD_VALHINT_BOOLEAN 0x0020
963#define LYD_VALHINT_EMPTY 0x0040
964#define LYD_VALHINT_STRING_DATATYPES 0x0080
968
978#define LYD_NODEHINT_LIST 0x0080
979#define LYD_NODEHINT_LEAFLIST 0x0100
980#define LYD_NODEHINT_CONTAINER 0x0200
984
995#define LYD_HINT_DATA 0x03F3
999#define LYD_HINT_SCHEMA 0x03FF
1006
1011 union {
1012 struct lyd_node node;
1013
1014 struct {
1015 uint32_t hash;
1016 uint32_t flags;
1017 const struct lysc_node *schema;
1018 struct lyd_node_inner *parent;
1019 struct lyd_node *next;
1020 struct lyd_node *prev;
1024 struct lyd_meta *meta;
1025 void *priv;
1026 };
1027 };
1028
1029 struct lyd_node *child;
1030
1032 const char *value;
1033 uint32_t hints;
1036
1037 struct lyd_attr *attr;
1038 const struct ly_ctx *ctx;
1039};
1040
1056
1064static inline struct lyd_node *
1065lyd_parent(const struct lyd_node *node)
1066{
1067 return (node && node->parent) ? &node->parent->node : NULL;
1068}
1069
1080static inline struct lyd_node *
1081lyd_child(const struct lyd_node *node)
1082{
1083 if (!node) {
1084 return NULL;
1085 }
1086
1087 if (!node->schema) {
1088 /* opaq node */
1089 return ((const struct lyd_node_opaq *)node)->child;
1090 }
1091
1093 return ((const struct lyd_node_inner *)node)->child;
1094 }
1095
1096 return NULL;
1097}
1098
1109LIBYANG_API_DECL struct lyd_node *lyd_child_no_keys(const struct lyd_node *node);
1110
1120LIBYANG_API_DECL const struct lys_module *lyd_owner_module(const struct lyd_node *node);
1121
1128LIBYANG_API_DECL const struct lys_module *lyd_node_module(const struct lyd_node *node);
1129
1136LIBYANG_API_DECL ly_bool lyd_is_default(const struct lyd_node *node);
1137
1145LIBYANG_API_DECL uint32_t lyd_list_pos(const struct lyd_node *instance);
1146
1153LIBYANG_API_DECL struct lyd_node *lyd_first_sibling(const struct lyd_node *node);
1154
1164LIBYANG_API_DECL LY_ERR lyd_parse_opaq_error(const struct lyd_node *node);
1165
1175LIBYANG_API_DECL const char *lyd_value_get_canonical(const struct ly_ctx *ctx, const struct lyd_value *value);
1176
1183static inline const char *
1184lyd_get_value(const struct lyd_node *node)
1185{
1186 if (!node) {
1187 return NULL;
1188 }
1189
1190 if (!node->schema) {
1191 return ((const struct lyd_node_opaq *)node)->value;
1192 } else if (node->schema->nodetype & LYD_NODE_TERM) {
1193 const struct lyd_value *value = &((const struct lyd_node_term *)node)->value;
1194
1196 }
1197
1198 return NULL;
1199}
1200
1208LIBYANG_API_DECL LY_ERR lyd_any_value_str(const struct lyd_node *any, char **value_str);
1209
1218LIBYANG_API_DECL LY_ERR lyd_any_copy_value(struct lyd_node *trg, const union lyd_any_value *value,
1219 LYD_ANYDATA_VALUETYPE value_type);
1220
1227LIBYANG_API_DECL const struct lysc_node *lyd_node_schema(const struct lyd_node *node);
1228
1236LIBYANG_API_DECL ly_bool lyd_meta_is_internal(const struct lyd_meta *meta);
1237
1253LIBYANG_API_DECL LY_ERR lyd_new_inner(struct lyd_node *parent, const struct lys_module *module, const char *name,
1254 ly_bool output, struct lyd_node **node);
1255
1269LIBYANG_API_DECL LY_ERR lyd_new_ext_inner(const struct lysc_ext_instance *ext, const char *name, struct lyd_node **node);
1270
1291
1292#define LYD_NEW_VAL_OUTPUT 0x01
1294#define LYD_NEW_VAL_STORE_ONLY 0x02
1295#define LYD_NEW_VAL_BIN 0x04
1297#define LYD_NEW_VAL_CANON 0x08
1300#define LYD_NEW_META_CLEAR_DFLT 0x10
1301#define LYD_NEW_PATH_UPDATE 0x20
1305#define LYD_NEW_PATH_OPAQ 0x40
1309#define LYD_NEW_PATH_WITH_OPAQ 0x80
1310#define LYD_NEW_ANY_USE_VALUE 0x100
1311
1313
1327LIBYANG_API_DECL LY_ERR lyd_new_list(struct lyd_node *parent, const struct lys_module *module, const char *name,
1328 uint32_t options, struct lyd_node **node, ...);
1329
1345LIBYANG_API_DECL LY_ERR lyd_new_ext_list(const struct lysc_ext_instance *ext, const char *name, uint32_t options,
1346 struct lyd_node **node, ...);
1347
1361LIBYANG_API_DECL LY_ERR lyd_new_list2(struct lyd_node *parent, const struct lys_module *module, const char *name,
1362 const char *keys, uint32_t options, struct lyd_node **node);
1363
1377LIBYANG_API_DECL LY_ERR lyd_new_list3(struct lyd_node *parent, const struct lys_module *module, const char *name,
1378 const void **key_values, uint32_t *value_sizes_bits, uint32_t options, struct lyd_node **node);
1379
1394LIBYANG_API_DECL LY_ERR lyd_new_term(struct lyd_node *parent, const struct lys_module *module, const char *name,
1395 const char *value, uint32_t options, struct lyd_node **node);
1396
1409LIBYANG_API_DECL LY_ERR lyd_new_term_bin(struct lyd_node *parent, const struct lys_module *module, const char *name,
1410 const void *value, uint32_t value_size_bits, uint32_t options, struct lyd_node **node);
1411
1426LIBYANG_API_DECL LY_ERR lyd_new_ext_term(const struct lysc_ext_instance *ext, const char *name, const void *value,
1427 uint32_t value_size_bits, uint32_t options, struct lyd_node **node);
1428
1443LIBYANG_API_DECL LY_ERR lyd_new_any(struct lyd_node *parent, const struct lys_module *module, const char *name,
1444 const void *value, LYD_ANYDATA_VALUETYPE value_type, uint32_t options, struct lyd_node **node);
1445
1460LIBYANG_API_DECL LY_ERR lyd_new_ext_any(const struct lysc_ext_instance *ext, const char *name, const void *value,
1461 LYD_ANYDATA_VALUETYPE value_type, uint32_t options, struct lyd_node **node);
1462
1477LIBYANG_API_DECL LY_ERR lyd_new_meta(const struct ly_ctx *ctx, struct lyd_node *parent, const struct lys_module *module,
1478 const char *name, const char *val_str, uint32_t options, struct lyd_meta **meta);
1479
1492LIBYANG_API_DECL LY_ERR lyd_new_meta2(const struct ly_ctx *ctx, struct lyd_node *parent, uint32_t options,
1493 const struct lyd_attr *attr, struct lyd_meta **meta);
1494
1507LIBYANG_API_DECL LY_ERR lyd_new_opaq(struct lyd_node *parent, const struct ly_ctx *ctx, const char *name, const char *value,
1508 const char *prefix, const char *module_name, struct lyd_node **node);
1509
1522LIBYANG_API_DECL LY_ERR lyd_new_opaq2(struct lyd_node *parent, const struct ly_ctx *ctx, const char *name, const char *value,
1523 const char *prefix, const char *module_ns, struct lyd_node **node);
1524
1538LIBYANG_API_DECL LY_ERR lyd_new_attr(struct lyd_node *parent, const char *module_name, const char *name, const char *value,
1539 struct lyd_attr **attr);
1540
1553LIBYANG_API_DECL LY_ERR lyd_new_attr2(struct lyd_node *parent, const char *module_ns, const char *name, const char *value,
1554 struct lyd_attr **attr);
1555
1584LIBYANG_API_DECL LY_ERR lyd_new_path(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const char *value,
1585 uint32_t options, struct lyd_node **node);
1586
1611LIBYANG_API_DECL LY_ERR lyd_new_path2(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const void *value,
1612 uint32_t value_size_bits, LYD_ANYDATA_VALUETYPE value_type, uint32_t options, struct lyd_node **new_parent,
1613 struct lyd_node **new_node);
1614
1637LIBYANG_API_DECL LY_ERR lyd_new_ext_path(struct lyd_node *parent, const struct lysc_ext_instance *ext, const char *path,
1638 const char *value, uint32_t options, struct lyd_node **node);
1639
1652
1653#define LYD_IMPLICIT_NO_STATE 0x01
1654#define LYD_IMPLICIT_NO_CONFIG 0x02
1655#define LYD_IMPLICIT_OUTPUT 0x04
1656#define LYD_IMPLICIT_NO_DEFAULTS 0x08
1658
1660
1669LIBYANG_API_DECL LY_ERR lyd_new_implicit_tree(struct lyd_node *tree, uint32_t implicit_options, struct lyd_node **diff);
1670
1682LIBYANG_API_DECL LY_ERR lyd_new_implicit_all(struct lyd_node **tree, const struct ly_ctx *ctx, uint32_t implicit_options,
1683 struct lyd_node **diff);
1684
1696LIBYANG_API_DECL LY_ERR lyd_new_implicit_module(struct lyd_node **tree, const struct lys_module *module,
1697 uint32_t implicit_options, struct lyd_node **diff);
1698
1712LIBYANG_API_DECL LY_ERR lyd_change_term(struct lyd_node *term, const char *val_str);
1713
1728LIBYANG_API_DECL LY_ERR lyd_change_term_bin(struct lyd_node *term, const void *value, uint32_t value_size_bits);
1729
1744LIBYANG_API_DECL LY_ERR lyd_change_term_canon(struct lyd_node *term, const char *val_str);
1745
1755LIBYANG_API_DECL LY_ERR lyd_change_meta(struct lyd_meta *meta, const char *val_str);
1756
1768LIBYANG_API_DECL LY_ERR lyd_insert_child(struct lyd_node *parent, struct lyd_node *node);
1769
1782LIBYANG_API_DECL LY_ERR lyd_insert_sibling(struct lyd_node *sibling, struct lyd_node *node, struct lyd_node **first);
1783
1795LIBYANG_API_DECL LY_ERR lyd_insert_before(struct lyd_node *sibling, struct lyd_node *node);
1796
1808LIBYANG_API_DECL LY_ERR lyd_insert_after(struct lyd_node *sibling, struct lyd_node *node);
1809
1817LIBYANG_API_DECL LY_ERR lyd_unlink_siblings(struct lyd_node *node);
1818
1826LIBYANG_API_DECL LY_ERR lyd_unlink_tree(struct lyd_node *node);
1827
1833LIBYANG_API_DECL void lyd_free_all(struct lyd_node *node);
1834
1840LIBYANG_API_DECL void lyd_free_siblings(struct lyd_node *node);
1841
1847LIBYANG_API_DECL void lyd_free_tree(struct lyd_node *node);
1848
1854LIBYANG_API_DECL void lyd_free_meta_single(struct lyd_meta *meta);
1855
1861LIBYANG_API_DECL void lyd_free_meta_siblings(struct lyd_meta *meta);
1862
1869LIBYANG_API_DECL void lyd_free_attr_single(const struct ly_ctx *ctx, struct lyd_attr *attr);
1870
1877LIBYANG_API_DECL void lyd_free_attr_siblings(const struct ly_ctx *ctx, struct lyd_attr *attr);
1878
1896LIBYANG_API_DECL LY_ERR lyd_value_validate(const struct lysc_node *schema, const char *value, uint32_t value_len,
1897 const struct lyd_node *ctx_node, const struct lysc_type **realtype, const char **canonical);
1898
1916LIBYANG_API_DECL LY_ERR lyd_value_validate_dflt(const struct lysc_node *schema, const char *value,
1917 struct lysc_prefix *prefixes, const struct lyd_node *ctx_node, const struct lysc_type **realtype,
1918 const char **canonical);
1919
1932LIBYANG_API_DECL LY_ERR lyd_value_compare(const struct lyd_node_term *node, const char *value, uint32_t value_len);
1933
1940#define LYD_COMPARE_FULL_RECURSION 0x01 /* Lists and containers are the same only in case all they children
1941 (subtree, so direct as well as indirect children) are the same. By default,
1942 containers are the same in case of the same schema node and lists are the same
1943 in case of equal keys (keyless lists do the full recursion comparison all the time). */
1944#define LYD_COMPARE_DEFAULTS 0x02 /* By default, implicit and explicit default nodes are considered to be equal. This flag
1945 changes this behavior and implicit (automatically created default node) and explicit
1946 (explicitly created node with the default value) default nodes are considered different. */
1947#define LYD_COMPARE_OPAQ 0x04 /* Opaque nodes can normally be never equal to data nodes. Using this flag even
1948 opaque nodes members are compared to data node schema and value and can result
1949 in a match. */
1951
1963LIBYANG_API_DECL LY_ERR lyd_compare_single(const struct lyd_node *node1, const struct lyd_node *node2, uint32_t options);
1964
1976LIBYANG_API_DECL LY_ERR lyd_compare_siblings(const struct lyd_node *node1, const struct lyd_node *node2, uint32_t options);
1977
1988LIBYANG_API_DECL LY_ERR lyd_compare_meta(const struct lyd_meta *meta1, const struct lyd_meta *meta2);
1989
2002#define LYD_DUP_RECURSIVE 0x01
2004#define LYD_DUP_NO_META 0x02
2006#define LYD_DUP_WITH_PARENTS 0x04
2008#define LYD_DUP_WITH_FLAGS 0x08
2010#define LYD_DUP_NO_EXT 0x10
2011#define LYD_DUP_WITH_PRIV 0x20
2013#define LYD_DUP_NO_LYDS 0x40
2017
2019
2031LIBYANG_API_DECL LY_ERR lyd_dup_single(const struct lyd_node *node, struct lyd_node_inner *parent, uint32_t options,
2032 struct lyd_node **dup);
2033
2047LIBYANG_API_DECL LY_ERR lyd_dup_single_to_ctx(const struct lyd_node *node, const struct ly_ctx *trg_ctx,
2048 struct lyd_node_inner *parent, uint32_t options, struct lyd_node **dup);
2049
2061LIBYANG_API_DECL LY_ERR lyd_dup_siblings(const struct lyd_node *node, struct lyd_node_inner *parent, uint32_t options,
2062 struct lyd_node **dup);
2063
2078LIBYANG_API_DECL LY_ERR lyd_dup_siblings_to_ctx(const struct lyd_node *node, const struct ly_ctx *trg_ctx,
2079 struct lyd_node_inner *parent, uint32_t options, struct lyd_node **dup);
2080
2089LIBYANG_API_DECL LY_ERR lyd_dup_meta_single(const struct lyd_meta *meta, struct lyd_node *parent, struct lyd_meta **dup);
2090
2104
2105#define LYD_MERGE_DESTRUCT 0x01
2106#define LYD_MERGE_DEFAULTS 0x02
2107#define LYD_MERGE_WITH_FLAGS 0x04
2108
2110
2131LIBYANG_API_DECL LY_ERR lyd_merge_tree(struct lyd_node **target, const struct lyd_node *source, uint16_t options);
2132
2154LIBYANG_API_DECL LY_ERR lyd_merge_siblings(struct lyd_node **target, const struct lyd_node *source, uint16_t options);
2155
2165typedef LY_ERR (*lyd_merge_cb)(struct lyd_node *trg_node, const struct lyd_node *src_node, void *cb_data);
2166
2182LIBYANG_API_DECL LY_ERR lyd_merge_module(struct lyd_node **target, const struct lyd_node *source, const struct lys_module *mod,
2183 lyd_merge_cb merge_cb, void *cb_data, uint16_t options);
2184
2198
2199#define LYD_DIFF_DEFAULTS 0x01
2202#define LYD_DIFF_META 0x02
2205
2207
2233LIBYANG_API_DECL LY_ERR lyd_diff_tree(const struct lyd_node *first, const struct lyd_node *second, uint16_t options,
2234 struct lyd_node **diff);
2235
2248LIBYANG_API_DECL LY_ERR lyd_diff_siblings(const struct lyd_node *first, const struct lyd_node *second, uint16_t options,
2249 struct lyd_node **diff);
2250
2259typedef LY_ERR (*lyd_diff_cb)(const struct lyd_node *diff_node, struct lyd_node *data_node, void *cb_data);
2260
2277LIBYANG_API_DECL LY_ERR lyd_diff_apply_module(struct lyd_node **data, const struct lyd_node *diff,
2278 const struct lys_module *mod, lyd_diff_cb diff_cb, void *cb_data);
2279
2290LIBYANG_API_DECL LY_ERR lyd_diff_apply_all(struct lyd_node **data, const struct lyd_node *diff);
2291
2302
2303#define LYD_DIFF_MERGE_DEFAULTS 0x01
2304
2306
2331LIBYANG_API_DECL LY_ERR lyd_diff_merge_module(struct lyd_node **diff, const struct lyd_node *src_diff,
2332 const struct lys_module *mod, lyd_diff_cb diff_cb, void *cb_data, uint16_t options);
2333
2350LIBYANG_API_DECL LY_ERR lyd_diff_merge_tree(struct lyd_node **diff_first, struct lyd_node *diff_parent,
2351 const struct lyd_node *src_sibling, lyd_diff_cb diff_cb, void *cb_data, uint16_t options);
2352
2364LIBYANG_API_DECL LY_ERR lyd_diff_merge_all(struct lyd_node **diff, const struct lyd_node *src_diff, uint16_t options);
2365
2373 * @return LY_ERR on error.
2375LIBYANG_API_DECL LY_ERR lyd_diff_reverse_all(const struct lyd_node *src_diff, struct lyd_node **diff);
2379
2380typedef enum {
2381 LYD_PATH_STD,
2386
2402LIBYANG_API_DECL char *lyd_path(const struct lyd_node *node, LYD_PATH_TYPE pathtype, char *buffer, size_t buflen);
2403
2413LIBYANG_API_DECL struct lyd_meta *lyd_find_meta(const struct lyd_meta *first, const struct lys_module *module,
2414 const char *name);
2415
2427LIBYANG_API_DECL LY_ERR lyd_find_sibling_first(const struct lyd_node *siblings, const struct lyd_node *target,
2428 struct lyd_node **match);
2429
2454LIBYANG_API_DECL LY_ERR lyd_find_sibling_val(const struct lyd_node *siblings, const struct lysc_node *schema,
2455 const char *key_or_value, uint32_t val_len, struct lyd_node **match);
2456
2468LIBYANG_API_DECL LY_ERR lyd_find_sibling_dup_inst_set(const struct lyd_node *siblings, const struct lyd_node *target,
2469 struct ly_set **set);
2470
2481LIBYANG_API_DECL LY_ERR lyd_find_sibling_opaq_next(const struct lyd_node *first, const char *name, struct lyd_node **match);
2482
2494LIBYANG_API_DECL LY_ERR lyxp_vars_set(struct lyxp_var **vars, const char *name, const char *value);
2495
2501LIBYANG_API_DECL void lyxp_vars_free(struct lyxp_var *vars);
2502
2520LIBYANG_API_DECL LY_ERR lyd_find_xpath(const struct lyd_node *ctx_node, const char *xpath, struct ly_set **set);
2521
2535LIBYANG_API_DECL LY_ERR lyd_find_xpath2(const struct lyd_node *ctx_node, const char *xpath, const struct lyxp_var *vars,
2536 struct ly_set **set);
2537
2555LIBYANG_API_DECL LY_ERR lyd_find_xpath3(const struct lyd_node *ctx_node, const struct lyd_node *tree, const char *xpath,
2556 LY_VALUE_FORMAT format, void *prefix_data, const struct lyxp_var *vars, struct ly_set **set);
2557
2569LIBYANG_API_DECL LY_ERR lyd_eval_xpath(const struct lyd_node *ctx_node, const char *xpath, ly_bool *result);
2570
2583LIBYANG_API_DECL LY_ERR lyd_eval_xpath2(const struct lyd_node *ctx_node, const char *xpath,
2584 const struct lyxp_var *vars, ly_bool *result);
2585
2601LIBYANG_API_DECL LY_ERR lyd_eval_xpath3(const struct lyd_node *ctx_node, const struct lys_module *cur_mod,
2602 const char *xpath, LY_VALUE_FORMAT format, void *prefix_data, const struct lyxp_var *vars, ly_bool *result);
2606
2607typedef enum {
2613
2636LIBYANG_API_DECL LY_ERR lyd_eval_xpath4(const struct lyd_node *ctx_node, const struct lyd_node *tree,
2637 const struct lys_module *cur_mod, const char *xpath, LY_VALUE_FORMAT format, void *prefix_data,
2638 const struct lyxp_var *vars, LY_XPATH_TYPE *ret_type, struct ly_set **node_set, char **string,
2639 long double *number, ly_bool *boolean);
2640
2650LIBYANG_API_DEF LY_ERR lyd_trim_xpath(struct lyd_node **tree, const char *xpath, const struct lyxp_var *vars);
2651
2669LIBYANG_API_DECL LY_ERR lyd_find_path(const struct lyd_node *ctx_node, const char *path, ly_bool output,
2670 struct lyd_node **match);
2671
2682LIBYANG_API_DECL LY_ERR lyd_find_target(const struct ly_path *path, const struct lyd_node *tree, struct lyd_node **match);
2683
2689LIBYANG_API_DECL int ly_time_tz_offset(void);
2697LIBYANG_API_DECL int ly_time_tz_offset_at(time_t time);
2698
2707LIBYANG_API_DECL LY_ERR ly_time_str2time(const char *value, time_t *time, char **fractions_s);
2708
2717LIBYANG_API_DECL LY_ERR ly_time_time2str(time_t time, const char *fractions_s, char **str);
2718
2726LIBYANG_API_DECL LY_ERR ly_time_str2ts(const char *value, struct timespec *ts);
2727
2735LIBYANG_API_DECL LY_ERR ly_time_ts2str(const struct timespec *ts, char **str);
2736
2747LIBYANG_API_DECL LY_ERR lyd_leafref_get_links(const struct lyd_node_term *node, const struct lyd_leafref_links_rec **record);
2748
2758LIBYANG_API_DECL LY_ERR lyd_leafref_link_node_tree(const struct lyd_node *tree);
2759
2773LIBYANG_API_DECL LY_ERR ly_pattern_match(const struct ly_ctx *ctx, const char *pattern, const char *string,
2774 uint32_t str_len, void **pat_comp);
2775
2785LIBYANG_API_DECL LY_ERR ly_pattern_compile(const struct ly_ctx *ctx, const char *pattern, void **pat_comp);
2786
2792LIBYANG_API_DECL void ly_pattern_free(void *pat_comp);
2793
2794#ifdef __cplusplus
2795}
2796#endif
2797
2798#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:543
LYD_FORMAT
Data input/output formats supported by libyang parser and printer functions.
Definition tree_data.h:533
#define LYD_CTX(node)
Macro to get context from a data tree node.
Definition tree_data.h:516
@ LYD_ANYDATA_DATATREE
Definition tree_data.h:544
@ LYD_ANYDATA_JSON
Definition tree_data.h:552
@ LYD_ANYDATA_XML
Definition tree_data.h:551
@ LYD_ANYDATA_STRING
Definition tree_data.h:548
@ LYD_LYB
Definition tree_data.h:537
@ LYD_XML
Definition tree_data.h:535
@ LYD_UNKNOWN
Definition tree_data.h:534
@ LYD_JSON
Definition tree_data.h:536
LY_ERR
libyang's error codes returned by the libyang functions.
Definition log.h:251
Structure to hold a set of (not necessary somehow connected) objects. Usually used for lyd_node,...
Definition set.h:47
YANG extension compiled instance.
#define LYS_NOTIF
#define LYS_RPC
#define LYS_CONTAINER
#define LYS_ACTION
#define LYS_LIST
uint16_t nodetype
struct lys_module * module
struct lysc_node * parent
const char * name
Available YANG schema tree structures representing YANG module.
YANG identity-stmt.
Compiled YANG data node.
Compiled prefix data pair mapping of prefixes to modules. In case the format is LY_VALUE_SCHEMA_RESOL...
LY_VALUE_FORMAT
All kinds of supported value formats and prefix mappings to modules.
Definition tree.h:234
Logger manipulation routines and error definitions.
uint8_t ly_bool
Type to indicate boolean value.
Definition log.h:35
const char * name
Definition metadata.h:40
struct lyd_value value
Definition metadata.h:41
Metadata structure.
Definition metadata.h:36
libyang hash table.
libyang generic macros and functions to work with YANG schema or data trees.
LIBYANG_API_DECL void lyxp_vars_free(struct lyxp_var *vars)
Free the XPath variables.
LY_VALUE_FORMAT format
Definition tree_data.h:778
const struct lysc_ext_instance * top_ext
Definition tree_data.h:626
struct lyd_node * next
Definition tree_data.h:829
LIBYANG_API_DECL void lyd_free_all(struct lyd_node *node)
Free all the nodes (even parents of the node) in the data tree.
LIBYANG_API_DECL 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.
void * val_prefix_data
Definition tree_data.h:1035
LIBYANG_API_DECL 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...
LIBYANG_API_DECL void lyd_free_meta_siblings(struct lyd_meta *meta)
Free the metadata instance with any following instances.
LIBYANG_API_DECL 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.
const char * prefix
Definition tree_data.h:761
struct rb_node * rbt
Definition tree_data.h:749
LIBYANG_API_DECL LY_ERR ly_time_ts2str(const struct timespec *ts, char **str)
Convert timespec into date-and-time string value.
struct in_addr addr
Definition tree_data.h:659
LIBYANG_API_DECL 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.
LIBYANG_API_DECL 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,...
LIBYANG_API_DECL const char * lyd_value_get_canonical(const struct ly_ctx *ctx, const struct lyd_value *value)
Get the (canonical) value of a lyd_value.
LIBYANG_API_DECL 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.
const char * str
Definition tree_data.h:904
LIBYANG_API_DECL 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_PATH_TYPE
Types of the different data paths.
Definition tree_data.h:2373
@ LYD_PATH_STD_NO_LAST_PRED
Definition tree_data.h:2376
@ LYD_PATH_STD
Definition tree_data.h:2374
LIBYANG_API_DECL 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.
struct lyd_value value
Definition tree_data.h:896
LIBYANG_API_DECL LY_ERR lyd_new_term_bin(struct lyd_node *parent, const struct lys_module *module, const char *name, const void *value, uint32_t value_size_bits, uint32_t options, struct lyd_node **node)
Create a new term node in the data tree based on binary value.
LIBYANG_API_DECL int ly_time_tz_offset(void)
Get current timezone (including DST setting) UTC (GMT) time offset in seconds.
LIBYANG_API_DECL 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.
const struct lysc_type * realtype
Definition tree_data.h:564
LIBYANG_API_DECL LY_ERR lyd_change_meta(struct lyd_meta *meta, const char *val_str)
Change the value of a metadata instance.
struct lyd_node * tree
Definition tree_data.h:903
LIBYANG_API_DECL LY_ERR ly_time_str2ts(const char *value, struct timespec *ts)
Convert date-and-time from string to timespec.
uint32_t hints
Definition tree_data.h:777
LIBYANG_API_DECL 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().
LIBYANG_API_DECL 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.
LYD_ANYDATA_VALUETYPE value_type
Definition tree_data.h:937
ly_bool unknown_tz
Definition tree_data.h:708
LIBYANG_API_DECL 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().
LIBYANG_API_DECL LY_ERR lyd_insert_child(struct lyd_node *parent, struct lyd_node *node)
Insert a child into a parent.
LIBYANG_API_DECL struct lyd_node * lyd_first_sibling(const struct lyd_node *node)
Get the first sibling of the given node.
const struct lyd_node_term ** leafref_nodes
Definition tree_data.h:1046
struct lyd_attr * attr
Definition tree_data.h:1037
LIBYANG_API_DECL LY_ERR lyd_new_list(struct lyd_node *parent, const struct lys_module *module, const char *name, uint32_t options, struct lyd_node **node,...)
Create a new list node in the data tree.
LIBYANG_API_DECL 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.
LIBYANG_API_DECL LY_ERR lyd_value_validate(const struct lysc_node *schema, const char *value, uint32_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.
LIBYANG_API_DECL LY_ERR lyd_value_validate_dflt(const struct lysc_node *schema, const char *value, struct lysc_prefix *prefixes, 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_diff_cb)(const struct lyd_node *diff_node, struct lyd_node *data_node, void *cb_data)
Callback for diff nodes.
Definition tree_data.h:2252
LIBYANG_API_DECL const struct lys_module * lyd_node_module(const struct lyd_node *node)
Get the module of a node. Useful mainly for opaque nodes.
LIBYANG_API_DECL LY_ERR lyd_dup_siblings_to_ctx(const struct lyd_node *node, const struct ly_ctx *trg_ctx, 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 assi...
struct lyd_node * child
Definition tree_data.h:1029
LIBYANG_API_DECL LY_ERR lyd_compare_meta(const struct lyd_meta *meta1, const struct lyd_meta *meta2)
Compare 2 metadata.
const char * json
Definition tree_data.h:906
LIBYANG_API_DECL void lyd_free_tree(struct lyd_node *node)
Free (and unlink) the specified data (sub)tree.
LIBYANG_API_DECL 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, uint32_t options, struct lyd_meta **meta)
Create a new metadata.
LIBYANG_API_DECL 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.
LIBYANG_API_DECL 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.
LIBYANG_API_DECL 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....
struct ly_path * target
LIBYANG_API_DECL LY_ERR lyd_eval_xpath4(const struct lyd_node *ctx_node, const struct lyd_node *tree, const struct lys_module *cur_mod, const char *xpath, LY_VALUE_FORMAT format, void *prefix_data, const struct lyxp_var *vars, LY_XPATH_TYPE *ret_type, struct ly_set **node_set, char **string, long double *number, ly_bool *boolean)
Evaluate an XPath on data and return the result or convert it first to an expected result type.
LIBYANG_API_DECL LY_ERR lyd_leafref_link_node_tree(const struct lyd_node *tree)
Traverse through data tree including root node siblings and adds leafrefs links to the given nodes.
LIBYANG_API_DECL LY_ERR lyd_dup_single_to_ctx(const struct lyd_node *node, const struct ly_ctx *trg_ctx, struct lyd_node_inner *parent, uint32_t options, struct lyd_node **dup)
Create a copy of the specified data tree node. Schema references are assigned from trg_ctx.
struct lysc_type_bitenum_item ** items
Definition tree_data.h:636
const struct ly_ctx * ctx
Definition tree_data.h:1038
char * fractions_s
Definition tree_data.h:723
LIBYANG_API_DECL 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...
LIBYANG_API_DECL 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....
LIBYANG_API_DECL 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.
LIBYANG_API_DECL LY_ERR lyd_new_ext_path(struct lyd_node *parent, const struct lysc_ext_instance *ext, const char *path, const char *value, uint32_t options, struct lyd_node **node)
Create a new node defined in the given extension instance. In case of anyxml/anydata nodes,...
uint8_t fixed_mem[LYD_VALUE_FIXED_MEM_SIZE]
LIBYANG_API_DECL const struct lysc_node * lyd_node_schema(const struct lyd_node *node)
Get schema node of a data node. Useful especially for opaque nodes.
LIBYANG_API_DECL LY_ERR lyd_new_term(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *value, uint32_t options, struct lyd_node **node)
Create a new term node in the data tree.
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:2158
struct lyd_meta * meta
Definition tree_data.h:834
LIBYANG_API_DECL 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 lyd_node_term ** target_nodes
Definition tree_data.h:1052
uint32_t flags
Definition tree_data.h:826
struct lysc_ident * ident
LIBYANG_API_DECL ly_bool lyd_meta_is_internal(const struct lyd_meta *meta)
Check whether metadata are not an instance of internal metadata.
LIBYANG_API_DECL void ly_pattern_free(void *pat_comp)
Free a compiled XML Schema regex pattern.
LIBYANG_API_DECL LY_ERR lyd_new_any(struct lyd_node *parent, const struct lys_module *module, const char *name, const void *value, LYD_ANYDATA_VALUETYPE value_type, uint32_t options, struct lyd_node **node)
Create a new any node in the data tree.
LY_XPATH_TYPE
XPath result type.
Definition tree_data.h:2600
@ LY_XPATH_NODE_SET
Definition tree_data.h:2601
@ LY_XPATH_NUMBER
Definition tree_data.h:2603
@ LY_XPATH_STRING
Definition tree_data.h:2602
@ LY_XPATH_BOOLEAN
Definition tree_data.h:2604
const struct lysc_node * schema
Definition tree_data.h:827
uint32_t seconds
Definition tree_data.h:722
struct in6_addr addr
Definition tree_data.h:682
LIBYANG_API_DECL 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.
LIBYANG_API_DECL LY_ERR lyd_unlink_siblings(struct lyd_node *node)
Unlink the specified node with all the following siblings.
LIBYANG_API_DECL void lyd_free_siblings(struct lyd_node *node)
Free all the sibling nodes (preceding as well as succeeding).
struct lyxp_expr * exp
Definition tree_data.h:739
LIBYANG_API_DECL 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.
const char * value
Definition tree_data.h:1032
LIBYANG_API_DECL LY_ERR lyxp_vars_set(struct lyxp_var **vars, const char *name, const char *value)
Set a new XPath variable to vars.
LIBYANG_API_DECL 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.
LIBYANG_API_DECL 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...
LIBYANG_API_DECL LY_ERR lyd_new_list3(struct lyd_node *parent, const struct lys_module *module, const char *name, const void **key_values, uint32_t *value_sizes_bits, uint32_t options, struct lyd_node **node)
Create a new list node in the data tree.
LIBYANG_API_DECL LY_ERR lyd_new_meta2(const struct ly_ctx *ctx, struct lyd_node *parent, uint32_t options, const struct lyd_attr *attr, struct lyd_meta **meta)
Create new metadata from an opaque node attribute if possible.
LIBYANG_API_DECL 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.
LIBYANG_API_DECL LY_ERR lyd_leafref_get_links(const struct lyd_node_term *node, const struct lyd_leafref_links_rec **record)
Gets the leafref links record for given node.
const char * name
Definition tree_data.h:760
LIBYANG_API_DECL int ly_time_tz_offset_at(time_t time)
Get UTC (GMT) timezone offset in seconds at a specific timestamp (including DST setting).
LIBYANG_API_DECL LY_ERR lyd_new_path2(struct lyd_node *parent, const struct ly_ctx *ctx, const char *path, const void *value, uint32_t value_size_bits, 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.
void * prefix_data
Definition tree_data.h:624
LIBYANG_API_DECL 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.
LIBYANG_API_DECL LY_ERR lyd_new_ext_list(const struct lysc_ext_instance *ext, const char *name, uint32_t options, struct lyd_node **node,...)
Create a new top-level list node defined in the given extension instance.
LIBYANG_API_DECL 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.
LIBYANG_API_DEF LY_ERR lyd_trim_xpath(struct lyd_node **tree, const char *xpath, const struct lyxp_var *vars)
Evaluate an XPath on data and free all the nodes except the subtrees selected by the expression.
const struct lyd_node_term * node
Definition tree_data.h:1045
#define LYD_NODE_TERM
Definition tree_data.h:783
uint32_t hints
Definition tree_data.h:1033
LIBYANG_API_DECL 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.
LIBYANG_API_DECL 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...
LIBYANG_API_DECL 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...
LIBYANG_API_DECL 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,...
LIBYANG_API_DECL LY_ERR lyd_find_xpath3(const struct lyd_node *ctx_node, const struct lyd_node *tree, const char *xpath, LY_VALUE_FORMAT format, void *prefix_data, const struct lyxp_var *vars, struct ly_set **set)
Search in the given data for instances of nodes matching the provided XPath.
struct ly_opaq_name name
Definition tree_data.h:775
LIBYANG_API_DECL 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.
LIBYANG_API_DECL LY_ERR lyd_change_term_bin(struct lyd_node *term, const void *value, uint32_t value_size_bits)
Change the value of a term (leaf or leaf-list) node to a binary value.
LIBYANG_API_DECL struct lyd_meta * lyd_find_meta(const struct lyd_meta *first, const struct lys_module *module, const char *name)
Find a specific metadata.
LIBYANG_API_DECL 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...
LIBYANG_API_DECL 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.
LIBYANG_API_DECL 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().
uint32_t hash
Definition tree_data.h:822
void * val_prefix_data
Definition tree_data.h:779
struct in_addr addr
Definition tree_data.h:667
struct lyd_node * prev
Definition tree_data.h:830
ly_bool unknown_tz
Definition tree_data.h:724
LIBYANG_API_DECL 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.
LIBYANG_API_DECL LY_ERR lyd_new_list2(struct lyd_node *parent, const struct lys_module *module, const char *name, const char *keys, uint32_t options, struct lyd_node **node)
Create a new list node in the data tree.
LIBYANG_API_DECL 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....
struct lyd_node * child
Definition tree_data.h:864
const char * xml
Definition tree_data.h:905
LIBYANG_API_DECL void lyd_free_attr_siblings(const struct ly_ctx *ctx, struct lyd_attr *attr)
Free the attribute with any following attributes.
LIBYANG_API_DECL LY_ERR lyd_parse_opaq_error(const struct lyd_node *node)
Check node parsed into an opaque node for the reason (error) why it could not be parsed as data node.
LY_VALUE_FORMAT format
Definition tree_data.h:742
void * priv
Definition tree_data.h:835
LIBYANG_API_DECL ly_bool lyd_is_default(const struct lyd_node *node)
Check whether a node value equals to its default one.
LIBYANG_API_DECL 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.
LIBYANG_API_DECL 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.
struct lyd_value_union * subvalue
uint32_t orig_size_bits
Definition tree_data.h:619
struct ly_ht * children_ht
Definition tree_data.h:865
LY_VALUE_FORMAT format
Definition tree_data.h:1034
LIBYANG_API_DECL void lyd_free_attr_single(const struct ly_ctx *ctx, struct lyd_attr *attr)
Free a single attribute.
struct lysc_type_bitenum_item * enum_item
LIBYANG_API_DECL 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.
const char * value
Definition tree_data.h:776
LIBYANG_API_DECL LY_ERR lyd_find_sibling_val(const struct lyd_node *siblings, const struct lysc_node *schema, const char *key_or_value, uint32_t val_len, struct lyd_node **match)
Search in the given siblings for the first schema instance. Uses hashes - should be used whenever pos...
LIBYANG_API_DECL LY_ERR lyd_value_compare(const struct lyd_node_term *node, const char *value, uint32_t value_len)
Compare the node's value with the given string value. The string value is first validated according t...
LIBYANG_API_DECL 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.
const struct ly_ctx * ctx
Definition tree_data.h:740
LIBYANG_API_DECL LY_ERR lyd_new_ext_term(const struct lysc_ext_instance *ext, const char *name, const void *value, uint32_t value_size_bits, uint32_t options, struct lyd_node **node)
Create a new top-level term node defined in the given extension instance.
LIBYANG_API_DECL LY_ERR lyd_unlink_tree(struct lyd_node *node)
Unlink the specified data subtree.
union lyd_any_value value
Definition tree_data.h:936
struct lyd_attr * next
Definition tree_data.h:774
LIBYANG_API_DECL LY_ERR lyd_diff_apply_all(struct lyd_node **data, const struct lyd_node *diff)
Apply the whole diff tree on a data tree.
LIBYANG_API_DECL LY_ERR lyd_new_ext_any(const struct lysc_ext_instance *ext, const char *name, const void *value, LYD_ANYDATA_VALUETYPE value_type, uint32_t options, struct lyd_node **node)
Create a new top-level any node defined in the given extension instance.
uint32_t hints
Definition tree_data.h:620
LIBYANG_API_DECL 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.
struct in6_addr addr
Definition tree_data.h:690
struct lyd_value value
Definition tree_data.h:616
const char * _canonical
Definition tree_data.h:561
struct lyd_node_opaq * parent
Definition tree_data.h:773
LY_VALUE_FORMAT format
Definition tree_data.h:621
LIBYANG_API_DECL 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...
LIBYANG_API_DECL LY_ERR ly_pattern_match(const struct ly_ctx *ctx, const char *pattern, const char *string, uint32_t str_len, void **pat_comp)
Check a string matches an XML Schema regex used in YANG.
struct lyd_node_inner * parent
Definition tree_data.h:828
struct ly_opaq_name name
Definition tree_data.h:1031
LIBYANG_API_DECL LY_ERR ly_pattern_compile(const struct ly_ctx *ctx, const char *pattern, void **pat_comp)
Compile an XML Schema regex pattern prior to matching.
LIBYANG_API_DECL void lyd_free_meta_single(struct lyd_meta *meta)
Free a single metadata instance.
LIBYANG_API_DECL 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.
LIBYANG_API_DECL LY_ERR lyd_eval_xpath3(const struct lyd_node *ctx_node, const struct lys_module *cur_mod, const char *xpath, LY_VALUE_FORMAT format, void *prefix_data, const struct lyxp_var *vars, ly_bool *result)
Evaluate an XPath on data and return the result converted to boolean.
LIBYANG_API_DECL LY_ERR lyd_insert_sibling(struct lyd_node *sibling, struct lyd_node *node, struct lyd_node **first)
Insert a node into siblings.
const struct lysc_node * ctx_node
Definition tree_data.h:625
LIBYANG_API_DECL LY_ERR lyd_any_value_str(const struct lyd_node *any, char **value_str)
Get anydata string value.
LIBYANG_API_DECL 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().
Generic prefix and namespace mapping, meaning depends on the format.
Definition tree_data.h:759
Generic attribute structure.
Definition tree_data.h:772
Generic structure for a data node.
Definition tree_data.h:821
Data node structure for the anydata data tree nodes - anydata or anyxml.
Definition tree_data.h:913
Data node structure for the inner data tree nodes - containers, lists, RPCs, actions and Notification...
Definition tree_data.h:841
Data node structure for unparsed (opaque) nodes.
Definition tree_data.h:1010
Data node structure for the terminal data tree nodes - leaves and leaf-lists.
Definition tree_data.h:873
YANG data representation.
Definition tree_data.h:560
Special lyd_value structure for built-in binary values.
Definition tree_data.h:643
Special lyd_value structure for built-in bits values.
Definition tree_data.h:632
Special lyd_value structure for ietf-yang-types date values.
Definition tree_data.h:706
Special lyd_value structure for ietf-yang-types date-and-time values.
Definition tree_data.h:697
Special lyd_value structure for ietf-yang-types date-no-zone values.
Definition tree_data.h:714
Special lyd_value structure for ietf-inet-types ipv4-address values.
Definition tree_data.h:658
Special lyd_value structure for ietf-inet-types ipv4-address-no-zone values.
Definition tree_data.h:651
Special lyd_value structure for ietf-inet-types ipv4-prefix values.
Definition tree_data.h:666
Special lyd_value structure for ietf-inet-types ipv6-address values.
Definition tree_data.h:681
Special lyd_value structure for ietf-inet-types ipv6-address-no-zone values.
Definition tree_data.h:674
Special lyd_value structure for ietf-inet-types ipv6-prefix values.
Definition tree_data.h:689
Special lyd_value structure for lyds tree value.
Definition tree_data.h:748
Special lyd_value structure for ietf-yang-types time values.
Definition tree_data.h:721
Special lyd_value structure for ietf-yang-types time-no-zone values.
Definition tree_data.h:730
Special lyd_value structure for built-in union values.
Definition tree_data.h:615
Special lyd_value structure for ietf-yang-types xpath1.0 values.
Definition tree_data.h:738
union for anydata/anyxml value representation.
Definition tree_data.h:902
libyang representation of YANG schema trees.