15 #ifndef LY_TREE_SCHEMA_H_
16 #define LY_TREE_SCHEMA_H_
22 #include <sys/types.h>
40 #define LY_TREE_FOR(START, ELEM) \
41 for ((ELEM) = (START); \
43 (ELEM) = (ELEM)->next)
58 #define LY_TREE_FOR_SAFE(START, NEXT, ELEM) \
59 for ((ELEM) = (START); \
60 (ELEM) ? (NEXT = (ELEM)->next, 1) : 0; \
90 #define LY_TREE_DFS_BEGIN(START, NEXT, ELEM) \
91 for ((ELEM) = (NEXT) = (START); \
115 #define TYPES_COMPATIBLE(type1, type2) typeid(*(type1)) == typeid(type2)
116 #elif defined(__GNUC__) || defined(__clang__)
117 #define TYPES_COMPATIBLE(type1, type2) __builtin_types_compatible_p(__typeof__(*(type1)), type2)
119 #define TYPES_COMPATIBLE(type1, type2) _Generic(*(type1), type2: 1, default: 0)
122 #define LY_TREE_DFS_END(START, NEXT, ELEM) \
124 if (TYPES_COMPATIBLE(ELEM, struct lyd_node)) { \
126 if (((struct lyd_node *)(ELEM))->schema->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_ANYDATA)) { \
129 (NEXT) = (ELEM)->child; \
131 } else if (TYPES_COMPATIBLE(ELEM, struct lys_node)) { \
133 if (((struct lys_node *)(ELEM))->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_ANYDATA)) { \
136 (NEXT) = (ELEM)->child; \
139 (NEXT) = (ELEM)->child; \
144 if ((ELEM) == (START)) { \
149 (NEXT) = (ELEM)->next; \
153 if (TYPES_COMPATIBLE(ELEM, struct lys_node) \
154 && (((struct lys_node *)(ELEM)->parent)->nodetype == LYS_AUGMENT)) { \
155 (ELEM) = (ELEM)->parent->prev; \
157 (ELEM) = (ELEM)->parent; \
160 if (TYPES_COMPATIBLE(ELEM, struct lys_node)) { \
162 if (lys_parent((struct lys_node *)(ELEM)) == lys_parent((struct lys_node *)(START))) { \
166 } else if ((ELEM)->parent == (START)->parent) { \
170 (NEXT) = (ELEM)->next; \
180 #define LY_ARRAY_MAX(var) (sizeof(var) == 8 ? ULLONG_MAX : ((1ULL << (sizeof(var) * 8)) - 1))
182 #define LY_REV_SIZE 11
211 #define LYS_OUTOPT_TREE_RFC 0x01
212 #define LYS_OUTOPT_TREE_GROUPING 0x02
213 #define LYS_OUTOPT_TREE_USES 0x04
214 #define LYS_OUTOPT_TREE_NO_LEAFREF 0x08
229 typedef enum lys_nodetype {
251 #define LYS_NO_RPC_NOTIF_NODE 0x807F
253 #define LYS_ANY 0xFFFF
404 #define LYEXT_OPT_INHERIT 0x01
410 #define LYEXT_OPT_YANG 0x02
411 #define LYEXT_OPT_CONTENT 0x04
413 #define LYEXT_OPT_VALID 0x08
414 #define LYEXT_OPT_VALID_SUBTREE 0x10
418 #define LYEXT_OPT_PLUGIN1 0x0100
419 #define LYEXT_OPT_PLUGIN2 0x0200
420 #define LYEXT_OPT_PLUGIN3 0x0400
421 #define LYEXT_OPT_PLUGIN4 0x0800
422 #define LYEXT_OPT_PLUGIN5 0x1000
423 #define LYEXT_OPT_PLUGIN6 0x2000
424 #define LYEXT_OPT_PLUGIN7 0x4000
425 #define LYEXT_OPT_PLUGIN8 0x8000
435 struct lyext_substmt {
807 #define LY_DATA_TYPE_COUNT 20
812 struct lys_type_info_binary {
937 #ifdef LY_ENABLED_CACHE
938 void **patterns_pcre;
1062 #define LYS_IFF_NOT 0x00
1063 #define LYS_IFF_AND 0x01
1064 #define LYS_IFF_OR 0x02
1065 #define LYS_IFF_F 0x03
1135 #define LYS_CONFIG_W 0x01
1136 #define LYS_CONFIG_R 0x02
1137 #define LYS_CONFIG_SET 0x04
1138 #define LYS_CONFIG_MASK 0x03
1139 #define LYS_STATUS_CURR 0x08
1140 #define LYS_STATUS_DEPRC 0x10
1141 #define LYS_STATUS_OBSLT 0x20
1142 #define LYS_STATUS_MASK 0x38
1143 #define LYS_RFN_MAXSET 0x08
1144 #define LYS_RFN_MINSET 0x10
1145 #define LYS_MAND_TRUE 0x40
1147 #define LYS_MAND_FALSE 0x80
1149 #define LYS_INCL_STATUS 0x80
1151 #define LYS_MAND_MASK 0xc0
1152 #define LYS_USERORDERED 0x100
1154 #define LYS_FENABLED 0x100
1155 #define LYS_UNIQUE 0x100
1156 #define LYS_AUTOASSIGNED 0x01
1158 #define LYS_USESGRP 0x01
1159 #define LYS_IMPLICIT 0x40
1160 #define LYS_XPCONF_DEP 0x200
1163 #define LYS_XPSTATE_DEP 0x400
1166 #define LYS_LEAFREF_DEP 0x800
1169 #define LYS_DFLTJSON 0x1000
1173 #define LYS_NOTAPPLIED 0x01
1174 #define LYS_YINELEM 0x01
1175 #define LYS_VALID_EXT 0x2000
1176 #define LYS_VALID_EXT_SUBTREE 0x4000
1183 #ifdef LY_ENABLED_CACHE
1188 #define LYS_NODE_HASH_COUNT 4
1241 #ifdef LY_ENABLED_CACHE
1242 uint8_t hash[LYS_NODE_HASH_COUNT];
1283 #ifdef LY_ENABLED_CACHE
1284 uint8_t hash[LYS_NODE_HASH_COUNT];
1372 #ifdef LY_ENABLED_CACHE
1373 uint8_t hash[LYS_NODE_HASH_COUNT];
1426 #ifdef LY_ENABLED_CACHE
1427 uint8_t hash[LYS_NODE_HASH_COUNT];
1481 #ifdef LY_ENABLED_CACHE
1482 uint8_t hash[LYS_NODE_HASH_COUNT];
1538 #ifdef LY_ENABLED_CACHE
1539 uint8_t hash[LYS_NODE_HASH_COUNT];
1756 #ifdef LY_ENABLED_CACHE
1757 uint8_t hash[LYS_NODE_HASH_COUNT];
1802 #ifdef LY_ENABLED_CACHE
1803 uint8_t hash[LYS_NODE_HASH_COUNT];
2278 #define LYS_GETNEXT_WITHCHOICE 0x01
2279 #define LYS_GETNEXT_WITHCASE 0x02
2280 #define LYS_GETNEXT_WITHGROUPING 0x04
2281 #define LYS_GETNEXT_WITHINOUT 0x08
2283 #define LYS_GETNEXT_WITHUSES 0x10
2284 #define LYS_GETNEXT_INTOUSES 0x20
2286 #define LYS_GETNEXT_INTONPCONT 0x40
2287 #define LYS_GETNEXT_PARENTUSES 0x80
2289 #define LYS_GETNEXT_NOSTATECHECK 0x100
2299 const struct lys_type *lys_getnext_union_type(const struct lys_type *last, const struct lys_type *type);
2344 const char *expr,
int options);
2346 #define LYXP_MUST 0x01
2347 #define LYXP_WHEN 0x02
2356 struct ly_set *lys_node_xpath_atomize(const struct lys_node *node, int options);
2358 #define LYXP_RECURSIVE 0x01
2359 #define LYXP_NO_LOCAL 0x02
2372 char *lys_path(const struct lys_node *node, int options);
2374 #define LYS_PATH_FIRST_PREFIX 0x01
2384 char *lys_data_path(const struct lys_node *node);
2532 int line_length,
int options);
2547 int line_length,
int options);
2562 int line_length,
int options);
2577 int line_length,
int options);
2592 int lys_print_clb(ssize_t (*writeclb)(
void *arg,
const void *buf,
size_t count),
void *arg,
2593 const struct lys_module *module,
LYS_OUTFORMAT format,
const char *target_node,
int line_length,
int options);
struct lys_deviation * deviation
int ly_register_types(struct lytype_plugin_list *plugin, const char *log_name)
Directly register a YANG type by pointer.
struct lys_module * module
Common structure representing single YANG data statement describing.
struct lys_node * lys_is_disabled(const struct lys_node *node, int recursive)
Check if the schema node is disabled in the schema tree, i.e. there is any disabled if-feature statem...
struct ly_set * backlinks
int lys_print_file(FILE *f, const struct lys_module *module, LYS_OUTFORMAT format, const char *target_node, int line_length, int options)
Print schema tree in the specified format into a file stream.
LY_STMT_CARD
Possible cardinalities of the YANG statements.
Schema leaf node structure.
Schema grouping node structure.
struct lys_type_bit * bit
int lys_iffeature_value(const struct lys_iffeature *iff)
Learn how the if-feature statement currently evaluates.
Submodule schema node structure that can be included into a YANG module.
Schema choice node structure.
struct lys_type_info_num num
struct lys_unique * unique
struct lys_restr * patterns
struct lys_module * lys_main_module(const struct lys_module *module)
Return main module of the module.
struct lys_ext * extensions
YANG uses's refine substatement structure, see RFC 6020 sec. 7.12.2
YANG import structure used to reference other schemas (modules).
Container for list modifications in lys_refine_mod.
Container for information about string types (LY_TYPE_STRING), used in lys_type_info.
int lys_print_clb(ssize_t(*writeclb)(void *arg, const void *buf, size_t count), void *arg, const struct lys_module *module, LYS_OUTFORMAT format, const char *target_node, int line_length, int options)
Print schema tree in the specified format using a provided callback.
struct ly_set * lys_find_path(const struct lys_module *cur_module, const struct lys_node *cur_node, const char *path)
Search for schema nodes matching the provided path.
YANG typedef structure providing information from the schema.
struct lys_restr * length
lyxp_node_type
Types of context nodes, LYXP_NODE_ROOT_CONFIG used only in when or must conditions.
int lys_search_localfile(const char *const *searchpaths, int cwd, const char *name, const char *revision, char **localfile, LYS_INFORMAT *format)
Search for the schema file in the specified searchpaths.
Single enumeration value specification for lys_type_info_enums.
Union for holding type-specific information in lys_type.
int lys_features_disable(const struct lys_module *module, const char *feature)
Disable specified feature in the module. If it causes some dependant features to be disabled...
Container for information about leafref types (LY_TYPE_LEAFREF), used in lys_type_info.
Compiled if-feature expression structure.
struct lys_node_leaf ** keys
Schema leaf-list node structure.
YANG augment structure (covering both possibilities - uses's substatement as well as (sub)module's su...
LYS_OUTFORMAT
Schema output formats accepted by libyang printer functions.
void ly_load_plugins(void)
Load the available YANG extension and type plugins from the plugin directory (LIBDIR/libyang/).
struct lys_node * orig_node
struct lys_type_enum * enm
Container for information about enumeration types (LY_TYPE_ENUM), used in lys_type_info.
Container for information about integer types, used in lys_type_info.
int ly_register_exts(struct lyext_plugin_list *plugin, const char *log_name)
Directly register a YANG extension by pointer.
Union to hold target modification in lys_refine.
Schema anydata (and anyxml) node structure.
Container for information about decimal64 types (LY_TYPE_DEC64), used in lys_type_info.
int lys_set_implemented(const struct lys_module *module)
Mark imported module as "implemented".
struct lys_node * lys_getnext(const struct lys_node *last, const struct lys_node *parent, const struct lys_module *module, int options)
Get next schema tree (sibling) node element that can be instantiated in a data tree. Returned node can be from an augment.
struct lys_ext_instance ** ext
uint8_t has_union_leafref
int lys_features_enable(const struct lys_module *module, const char *feature)
Enable specified feature in the module. In case its if-feature evaluates to false, return an error.
struct lys_type_info_lref lref
struct lys_module * belongsto
struct lys_module * module
struct lyext_plugin * plugin
struct lys_iffeature * iffeature
Container for information about identity types (LY_TYPE_IDENT), used in lys_type_info.
YANG when restriction, see RFC 6020 sec. 7.19.5
const void * lys_ext_instance_substmt(const struct lys_ext_instance *ext)
Get address of the substatement structure to which the extension instance refers. ...
int lys_print_fd(int fd, const struct lys_module *module, LYS_OUTFORMAT format, const char *target_node, int line_length, int options)
Print schema tree in the specified format into a file descriptor.
Container for information about bits types (LY_TYPE_BINARY), used in lys_type_info.
struct lyext_substmt * substmt
lys_deviate_type
Possible deviation modifications, see RFC 6020 sec. 7.18.3.2
LYS_INFORMAT
Schema input formats accepted by libyang parser functions.
Schema case node structure.
struct lys_submodule * submodule
int lys_features_state(const struct lys_module *module, const char *feature)
Get the current status of the specified feature in the module. Even if the feature is enabled but som...
struct lys_node_augment * augment
int lys_set_enabled(const struct lys_module *module)
Enable previously disabled module.
Schema list node structure.
struct lys_revision * rev
int lys_features_disable_force(const struct lys_module *module, const char *feature)
Disable specified feature in the module disregarding dependant features.
Container for information about instance-identifier types (LY_TYPE_INST), used in lys_type_info...
struct lys_feature * features
Main schema node structure representing YANG module.
struct lys_module * lys_node_module(const struct lys_node *node)
Return main module of the schema tree node.
Complex extension instance structure.
int lys_print_mem(char **strp, const struct lys_module *module, LYS_OUTFORMAT format, const char *target_node, int line_length, int options)
Print schema tree in the specified format into a memory block. It is up to caller to free the returne...
struct lys_module * lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format)
Load a schema into the specified context.
struct lys_deviate * deviate
int ly_clean_plugins(void)
Unload all the YANG extension and type plugins.
RPC input and output node structure.
LY_DATA_TYPE _PACKED base
LY_DATA_TYPE
YANG built-in types.
struct lys_node_leaf * target
struct lys_node_grp * grp
struct lys_module * lys_implemented_module(const struct lys_module *mod)
Find the implemented revision of the given module in the context.
YANG type structure providing information from the schema.
LYS_VERSION
supported YANG schema version values
YANG list's unique statement structure, see RFC 6020 sec. 7.8.3
struct lys_refine * refine
void * lys_ext_complex_get_substmt(LY_STMT stmt, struct lys_ext_instance_complex *ext, struct lyext_substmt **info)
get pointer to the place where the specified extension's substatement is supposed to be stored in the...
Structure to hold information about identity, see RFC 6020 sec. 7.16
struct ly_set * depfeatures
Description of the extension instance substatement.
char * lys_data_path_pattern(const struct lys_node *node, const char *placeholder)
Build the data path pattern of a schema node.
YANG deviate statement structure, see RFC 6020 sec. 7.18.3.2
const char *const * ly_get_loaded_plugins(void)
Get list of all the loaded plugins, both extension and user type ones.
const char ** lys_features_list(const struct lys_module *module, uint8_t **states)
Get list of all the defined features in the module and its submodules.
Schema uses node structure.
int lys_set_disabled(const struct lys_module *module)
Disable module in its context to avoid its further usage (it will be hidden for module getters)...
struct lys_type_info_union uni
Schema notification node structure.
void * lys_set_private(const struct lys_node *node, void *priv)
Set a schema private pointer to a user pointer.
int lys_print_path(const char *path, const struct lys_module *module, LYS_OUTFORMAT format, const char *target_node, int line_length, int options)
Print schema tree in the specified format into a file.
LY_STMT
List of YANG statements.
YANG validity restriction (must, length, etc.) structure providing information from the schema...
struct lys_module * lys_parse_path(struct ly_ctx *ctx, const char *path, LYS_INFORMAT format)
Load a schema into the specified context from a file.
enum lys_deviate_type LYS_DEVIATE_TYPE
Possible deviation modifications, see RFC 6020 sec. 7.18.3.2
LYEXT_TYPE
Extension types.
Schema rpc/action node structure.
Generic extension instance structure.
Container for information about union types (LY_TYPE_UNION), used in lys_type_info.
YANG extension definition.
YANG revision statement for (sub)modules.
struct lys_type_info_str str
YANG include structure used to reference submodules.
struct lys_node_list * lys_is_key(const struct lys_node_leaf *node, uint8_t *index)
Check if the schema leaf node is used as a key for a list.
YANG feature definition structure.
struct lys_feature ** features
enum lys_nodetype LYS_NODE
YANG schema node types.
Single bit value specification for lys_type_info_bits.
int lys_ext_instance_presence(struct lys_ext *def, struct lys_ext_instance **ext, uint8_t ext_size)
Get the position of the extension instance in the extensions list.
struct lys_module * lys_parse_fd(struct ly_ctx *ctx, int fd, LYS_INFORMAT format)
Read a schema from file descriptor into the specified context.
struct lys_ext_instance ** ext
Schema container node structure.
YANG deviation statement structure, see RFC 6020 sec. 7.18.3
struct lys_node * lys_parent(const struct lys_node *node)
Return parent node in the schema tree.
struct ly_set * lys_xpath_atomize(const struct lys_node *ctx_node, enum lyxp_node_type ctx_node_type, const char *expr, int options)
Get all the partial XPath nodes (atoms) that are required for expr to be evaluated.
int lys_features_enable_force(const struct lys_module *module, const char *feature)
Enable specified feature in the module disregarding its if-features.