15 #ifndef LY_TREE_SCHEMA_H_ 16 #define LY_TREE_SCHEMA_H_ 19 #include <machine/endian.h> 20 #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) 21 #include <sys/endian.h> 30 #include <sys/types.h> 48 #define LY_TREE_FOR(START, ELEM) \ 49 for ((ELEM) = (START); \ 51 (ELEM) = (ELEM)->next) 66 #define LY_TREE_FOR_SAFE(START, NEXT, ELEM) \ 67 for ((ELEM) = (START); \ 68 (ELEM) ? (NEXT = (ELEM)->next, 1) : 0; \ 98 #define LY_TREE_DFS_BEGIN(START, NEXT, ELEM) \ 99 for ((ELEM) = (NEXT) = (START); \ 123 #define TYPES_COMPATIBLE(type1, type2) typeid(*(type1)) == typeid(type2) 124 #elif defined(__GNUC__) || defined(__clang__) 125 #define TYPES_COMPATIBLE(type1, type2) __builtin_types_compatible_p(__typeof__(*(type1)), type2) 127 #define TYPES_COMPATIBLE(type1, type2) _Generic(*(type1), type2: 1, default: 0) 130 #define LY_TREE_DFS_END(START, NEXT, ELEM) \ 132 if (TYPES_COMPATIBLE(ELEM, struct lyd_node)) { \ 134 if (((struct lyd_node *)(ELEM))->schema->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_ANYDATA)) { \ 137 (NEXT) = (ELEM)->child; \ 139 } else if (TYPES_COMPATIBLE(ELEM, struct lys_node)) { \ 141 if (((struct lys_node *)(ELEM))->nodetype & (LYS_LEAF | LYS_LEAFLIST | LYS_ANYDATA)) { \ 144 (NEXT) = (ELEM)->child; \ 147 (NEXT) = (ELEM)->child; \ 152 if ((ELEM) == (START)) { \ 157 (NEXT) = (ELEM)->next; \ 161 if (TYPES_COMPATIBLE(ELEM, struct lys_node) \ 162 && (((struct lys_node *)(ELEM)->parent)->nodetype == LYS_AUGMENT)) { \ 163 (ELEM) = (ELEM)->parent->prev; \ 165 (ELEM) = (ELEM)->parent; \ 168 if (TYPES_COMPATIBLE(ELEM, struct lys_node)) { \ 170 if (lys_parent((struct lys_node *)(ELEM)) == lys_parent((struct lys_node *)(START))) { \ 174 } else if ((ELEM)->parent == (START)->parent) { \ 178 (NEXT) = (ELEM)->next; \ 188 #define LY_ARRAY_MAX(var) (sizeof(var) == 8 ? ULLONG_MAX : ((1ULL << (sizeof(var) * 8)) - 1)) 190 #define LY_REV_SIZE 11 219 #define LYS_OUTOPT_TREE_RFC 0x01 220 #define LYS_OUTOPT_TREE_GROUPING 0x02 221 #define LYS_OUTOPT_TREE_USES 0x04 222 #define LYS_OUTOPT_TREE_NO_LEAFREF 0x08 237 typedef enum lys_nodetype { 259 #define LYS_NO_RPC_NOTIF_NODE 0x807F 261 #define LYS_ANY 0xFFFF 412 #define LYEXT_OPT_INHERIT 0x01 418 #define LYEXT_OPT_YANG 0x02 419 #define LYEXT_OPT_CONTENT 0x04 421 #define LYEXT_OPT_VALID 0x08 422 #define LYEXT_OPT_PLUGIN1 0x0100 423 #define LYEXT_OPT_PLUGIN2 0x0200 424 #define LYEXT_OPT_PLUGIN3 0x0400 425 #define LYEXT_OPT_PLUGIN4 0x0800 426 #define LYEXT_OPT_PLUGIN5 0x1000 427 #define LYEXT_OPT_PLUGIN6 0x2000 428 #define LYEXT_OPT_PLUGIN7 0x4000 429 #define LYEXT_OPT_PLUGIN8 0x8000 439 struct lyext_substmt { 811 #define LY_DATA_TYPE_COUNT 20 816 struct lys_type_info_binary { 941 #ifdef LY_ENABLED_CACHE 942 void **patterns_pcre;
1066 #define LYS_IFF_NOT 0x00 1067 #define LYS_IFF_AND 0x01 1068 #define LYS_IFF_OR 0x02 1069 #define LYS_IFF_F 0x03 1139 #define LYS_CONFIG_W 0x01 1140 #define LYS_CONFIG_R 0x02 1141 #define LYS_CONFIG_SET 0x04 1142 #define LYS_CONFIG_MASK 0x03 1143 #define LYS_STATUS_CURR 0x08 1144 #define LYS_STATUS_DEPRC 0x10 1145 #define LYS_STATUS_OBSLT 0x20 1146 #define LYS_STATUS_MASK 0x38 1147 #define LYS_RFN_MAXSET 0x08 1148 #define LYS_RFN_MINSET 0x10 1149 #define LYS_MAND_TRUE 0x40 1151 #define LYS_MAND_FALSE 0x80 1153 #define LYS_INCL_STATUS 0x80 1155 #define LYS_MAND_MASK 0xc0 1156 #define LYS_USERORDERED 0x100 1158 #define LYS_FENABLED 0x100 1159 #define LYS_UNIQUE 0x100 1160 #define LYS_AUTOASSIGNED 0x01 1162 #define LYS_USESGRP 0x01 1163 #define LYS_IMPLICIT 0x40 1164 #define LYS_XPCONF_DEP 0x200 1167 #define LYS_XPSTATE_DEP 0x400 1170 #define LYS_LEAFREF_DEP 0x800 1173 #define LYS_DFLTJSON 0x1000 1177 #define LYS_NOTAPPLIED 0x01 1178 #define LYS_YINELEM 0x01 1179 #define LYS_VALID_EXT 0x2000 1185 #ifdef LY_ENABLED_CACHE 1190 #define LYS_NODE_HASH_COUNT 4 1243 #ifdef LY_ENABLED_CACHE 1244 uint8_t hash[LYS_NODE_HASH_COUNT];
1285 #ifdef LY_ENABLED_CACHE 1286 uint8_t hash[LYS_NODE_HASH_COUNT];
1376 #ifdef LY_ENABLED_CACHE 1377 uint8_t hash[LYS_NODE_HASH_COUNT];
1430 #ifdef LY_ENABLED_CACHE 1431 uint8_t hash[LYS_NODE_HASH_COUNT];
1485 #ifdef LY_ENABLED_CACHE 1486 uint8_t hash[LYS_NODE_HASH_COUNT];
1542 #ifdef LY_ENABLED_CACHE 1543 uint8_t hash[LYS_NODE_HASH_COUNT];
1760 #ifdef LY_ENABLED_CACHE 1761 uint8_t hash[LYS_NODE_HASH_COUNT];
1806 #ifdef LY_ENABLED_CACHE 1807 uint8_t hash[LYS_NODE_HASH_COUNT];
2250 #define LYS_GETNEXT_WITHCHOICE 0x01 2251 #define LYS_GETNEXT_WITHCASE 0x02 2252 #define LYS_GETNEXT_WITHGROUPING 0x04 2253 #define LYS_GETNEXT_WITHINOUT 0x08 2255 #define LYS_GETNEXT_WITHUSES 0x10 2256 #define LYS_GETNEXT_INTOUSES 0x20 2258 #define LYS_GETNEXT_INTONPCONT 0x40 2259 #define LYS_GETNEXT_PARENTUSES 0x80 2261 #define LYS_GETNEXT_NOSTATECHECK 0x100 2271 const struct lys_type *lys_getnext_union_type(const struct lys_type *last, const struct lys_type *type); 2314 const char *expr,
int options);
2316 #define LYXP_MUST 0x01 2317 #define LYXP_WHEN 0x02 2326 struct ly_set *lys_node_xpath_atomize(const struct lys_node *node, int options); 2328 #define LYXP_RECURSIVE 0x01 2329 #define LYXP_NO_LOCAL 0x02 2342 char *lys_path(const struct lys_node *node, int options); 2344 #define LYS_PATH_FIRST_PREFIX 0x01 2354 char *lys_data_path(const struct lys_node *node); 2487 int line_length,
int options);
2502 int line_length,
int options);
2517 int line_length,
int options);
2532 int line_length,
int options);
2547 int lys_print_clb(ssize_t (*writeclb)(
void *arg,
const void *buf,
size_t count),
void *arg,
2548 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.
const 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_module * module
Common structure representing single YANG data statement describing.
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.
const 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....
Schema grouping node structure.
struct lys_type_bit * bit
struct lys_type_info_bits bits
struct lys_type_info_inst inst
Submodule schema node structure that can be included into a YANG module.
Schema choice node structure.
struct lys_type_info_num num
const 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 lys_unique * unique
struct lys_restr * patterns
struct lys_refine_mod_list list
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.
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_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.
Structure to hold a set of (not necessary somehow connected) lyd_node or lys_node objects....
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.
const 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.
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.
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
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.
const 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.
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_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_type_info_dec64 dec64
struct lys_type_info_binary binary
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.
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.
struct lys_type_info_enums enums
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.
const 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.
#define _PACKED
Compiler flag for packed data types.
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.
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_type_info_ident ident
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.