libyang
3.7.5
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
|
Macros | |
#define | LYD_CTX(node) ((node)->schema ? (node)->schema->module->ctx : ((const struct lyd_node_opaq *)(node))->ctx) |
Macro to get context from a data tree node. More... | |
#define | LYD_LIST_FOR_INST(START, SCHEMA, ELEM) |
Macro to iterate via all schema node data instances in data siblings. More... | |
#define | LYD_LIST_FOR_INST_SAFE(START, SCHEMA, NEXT, ELEM) |
Macro to iterate via all schema node data instances in data siblings allowing to modify the list itself. More... | |
#define | LYD_NODE_IS_ALONE(NODE) |
Find out if the node is the only instance, i.e. it has no siblings with the same schema. More... | |
#define | LYD_TREE_DFS_BEGIN(START, ELEM) |
Macro to iterate via all elements in a data tree. This is the opening part to the LYD_TREE_DFS_END - they always have to be used together. More... | |
#define | LYD_TREE_DFS_END(START, ELEM) |
Macro to iterate via all elements in a tree. This is the closing part to the LYD_TREE_DFS_BEGIN - they always have to be used together. More... | |
Enumerations | |
enum | LYD_ANYDATA_VALUETYPE { LYD_ANYDATA_DATATREE, LYD_ANYDATA_STRING, LYD_ANYDATA_XML, LYD_ANYDATA_JSON, LYD_ANYDATA_LYB } |
List of possible value types stored in lyd_node_any. More... | |
enum | LYD_FORMAT { LYD_UNKNOWN = 0, LYD_XML, LYD_JSON, LYD_LYB } |
Data input/output formats supported by libyang parser and printer functions. More... | |
Functions | |
LIBYANG_API_DECL LY_ERR | lyd_parse_data (const struct ly_ctx *ctx, struct lyd_node *parent, struct ly_in *in, LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options, struct lyd_node **tree) |
Parse (and validate) data from the input handler as a YANG data tree. More... | |
LIBYANG_API_DECL LY_ERR | lyd_parse_data_fd (const struct ly_ctx *ctx, int fd, LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options, struct lyd_node **tree) |
Parse (and validate) input data as a YANG data tree. More... | |
LIBYANG_API_DECL LY_ERR | lyd_parse_data_mem (const struct ly_ctx *ctx, const char *data, LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options, struct lyd_node **tree) |
Parse (and validate) input data as a YANG data tree. More... | |
LIBYANG_API_DECL LY_ERR | lyd_parse_data_path (const struct ly_ctx *ctx, const char *path, LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options, struct lyd_node **tree) |
Parse (and validate) input data as a YANG data tree. More... | |
LIBYANG_API_DECL LY_ERR | lyd_parse_ext_data (const struct lysc_ext_instance *ext, struct lyd_node *parent, struct ly_in *in, LYD_FORMAT format, uint32_t parse_options, uint32_t validate_options, struct lyd_node **tree) |
Parse (and validate) data from the input handler as an extension data tree following the schema tree of the given extension instance. More... | |
LIBYANG_API_DECL LY_ERR | lyd_parse_ext_op (const struct lysc_ext_instance *ext, struct lyd_node *parent, struct ly_in *in, LYD_FORMAT format, enum lyd_type data_type, struct lyd_node **tree, struct lyd_node **op) |
Parse extension data into an operation data tree following only the specification from the given extension instance. More... | |
LIBYANG_API_DECL LY_ERR | lyd_parse_op (const struct ly_ctx *ctx, struct lyd_node *parent, struct ly_in *in, LYD_FORMAT format, enum lyd_type data_type, struct lyd_node **tree, struct lyd_node **op) |
Parse YANG data into an operation data tree. Specific parsing flags LYD_PARSE_ONLY, LYD_PARSE_STRICT and no validation flags are used. More... | |
LIBYANG_API_DECL LY_ERR | lyd_validate_all (struct lyd_node **tree, const struct ly_ctx *ctx, uint32_t val_opts, struct lyd_node **diff) |
Fully validate a data tree. More... | |
LIBYANG_API_DECL LY_ERR | lyd_validate_module (struct lyd_node **tree, const struct lys_module *module, uint32_t val_opts, struct lyd_node **diff) |
Fully validate a data tree of a module. More... | |
LIBYANG_API_DECL LY_ERR | lyd_validate_module_final (struct lyd_node *tree, const struct lys_module *module, uint32_t val_opts) |
Finish validation of a module data that have previously been validated with LYD_VALIDATE_NOT_FINAL flag. More... | |
LIBYANG_API_DECL LY_ERR | lyd_validate_op (struct lyd_node *op_tree, const struct lyd_node *dep_tree, enum lyd_type data_type, struct lyd_node **diff) |
Validate an RPC/action request, reply, or notification. Only the operation data tree (input/output/notif) is validate, any parents are ignored. More... | |
Data structures and functions to manipulate and access instance data tree.
#define LYD_CTX | ( | node | ) | ((node)->schema ? (node)->schema->module->ctx : ((const struct lyd_node_opaq *)(node))->ctx) |
Macro to get context from a data tree node.
Definition at line 531 of file tree_data.h.
#define LYD_LIST_FOR_INST | ( | START, | |
SCHEMA, | |||
ELEM | |||
) |
Macro to iterate via all schema node data instances in data siblings.
START | Pointer to the starting sibling. Even if it is not first, all the siblings are searched. |
SCHEMA | Schema node of the searched instances. |
ELEM | Iterator. |
Definition at line 508 of file tree_data.h.
#define LYD_LIST_FOR_INST_SAFE | ( | START, | |
SCHEMA, | |||
NEXT, | |||
ELEM | |||
) |
Macro to iterate via all schema node data instances in data siblings allowing to modify the list itself.
START | Pointer to the starting sibling. Even if it is not first, all the siblings are searched. |
SCHEMA | Schema node of the searched instances. |
NEXT | Temporary storage to allow removing of the current iterator content. |
ELEM | Iterator. |
Definition at line 521 of file tree_data.h.
#define LYD_NODE_IS_ALONE | ( | NODE | ) |
Find out if the node is the only instance, i.e. it has no siblings with the same schema.
[in] | NODE | Pointer to the struct lyd_node. |
NODE
is a single instance (is alone). NODE
is not alone. Definition at line 540 of file tree_data.h.
#define LYD_TREE_DFS_BEGIN | ( | START, | |
ELEM | |||
) |
Macro to iterate via all elements in a data tree. This is the opening part to the LYD_TREE_DFS_END - they always have to be used together.
The function follows deep-first search algorithm:
1 / \ 2 4 / / \ 3 5 6
Use the same parameters for LYD_TREE_DFS_BEGIN and LYD_TREE_DFS_END. While START can be any of the lyd_node* types, ELEM variable must be a pointer to the generic struct lyd_node.
To skip a particular subtree, instead of the continue statement, set LYD_TREE_DFS_continue variable to non-zero value.
Use with opening curly bracket '{' after the macro.
START | Pointer to the starting element processed first. |
ELEM | Iterator intended for use in the block. |
Definition at line 454 of file tree_data.h.
#define LYD_TREE_DFS_END | ( | START, | |
ELEM | |||
) |
Macro to iterate via all elements in a tree. This is the closing part to the LYD_TREE_DFS_BEGIN - they always have to be used together.
Use the same parameters for LYD_TREE_DFS_BEGIN and LYD_TREE_DFS_END. While START can be any of the lyd_node* types, ELEM variable must be a pointer to the generic struct lyd_node.
Use with closing curly bracket '}' after the macro.
START | Pointer to the starting element processed first. |
ELEM | Iterator intended for use in the block. |
Definition at line 474 of file tree_data.h.
List of possible value types stored in lyd_node_any.
Enumerator | |
---|---|
LYD_ANYDATA_DATATREE |
Value is a pointer to lyd_node structure (first sibling). When provided as input parameter, the pointer is directly connected into the anydata node without duplication, caller is supposed to not manipulate with the data after a successful call (including calling lyd_free_all() on the provided data) |
LYD_ANYDATA_STRING |
Value is a generic string without any knowledge about its format (e.g. anyxml value in JSON encoded as string). XML sensitive characters (such as & or >) are automatically escaped when the anydata is printed in XML format. |
LYD_ANYDATA_XML |
Value is a string containing the serialized XML data. |
LYD_ANYDATA_JSON |
Value is a string containing the data modeled by YANG and encoded as I-JSON. |
LYD_ANYDATA_LYB |
Value is a memory chunk with the serialized data tree in LYB format. |
Definition at line 558 of file tree_data.h.
enum LYD_FORMAT |
Data input/output formats supported by libyang parser and printer functions.
Enumerator | |
---|---|
LYD_UNKNOWN |
unknown data format, invalid value |
LYD_XML |
XML instance data format |
LYD_JSON |
JSON instance data format |
LYD_LYB |
LYB instance data format |
Definition at line 548 of file tree_data.h.
LIBYANG_API_DECL LY_ERR lyd_parse_data | ( | const struct ly_ctx * | ctx, |
struct lyd_node * | parent, | ||
struct ly_in * | in, | ||
LYD_FORMAT | format, | ||
uint32_t | parse_options, | ||
uint32_t | validate_options, | ||
struct lyd_node ** | tree | ||
) |
Parse (and validate) data from the input handler as a YANG data tree.
[in] | ctx | Context to connect with the tree being built here. |
[in] | parent | Optional parent to connect the parsed nodes to. If provided, the data are expected to describe a subtree of the YANG model instead of starting at the schema root. |
[in] | in | The input handle to provide the dumped data in the specified format to parse (and validate). |
[in] | format | Format of the input data to be parsed. Can be 0 to try to detect format from the input handler. |
[in] | parse_options | Options for parser, see Data parser options. |
[in] | validate_options | Options for the validation phase, see Data validation options. |
[out] | tree | Full parsed data tree, note that NULL can be a valid tree. If parent is set, the first parsed child. |
When parsing subtrees (i.e., when parent
is non-NULL), validation is only performed on the newly parsed data. This might result in allowing invalid datastore content when the schema contains cross-branch constraints, complicated must
statements, etc. When a full-datastore validation is desirable, parse all subtrees first, and then request validation of the complete datastore content.
LIBYANG_API_DECL LY_ERR lyd_parse_data_fd | ( | const struct ly_ctx * | ctx, |
int | fd, | ||
LYD_FORMAT | format, | ||
uint32_t | parse_options, | ||
uint32_t | validate_options, | ||
struct lyd_node ** | tree | ||
) |
Parse (and validate) input data as a YANG data tree.
Wrapper around lyd_parse_data() hiding work with the input handler and some obscure options.
[in] | ctx | Context to connect with the tree being built here. |
[in] | fd | File descriptor of a regular file (e.g. sockets are not supported) containing the input data in the specified format to parse. |
[in] | format | Format of the input data to be parsed. |
[in] | parse_options | Options for parser, see Data parser options. |
[in] | validate_options | Options for the validation phase, see Data validation options. |
[out] | tree | Full parsed data tree, note that NULL can be a valid tree |
LIBYANG_API_DECL LY_ERR lyd_parse_data_mem | ( | const struct ly_ctx * | ctx, |
const char * | data, | ||
LYD_FORMAT | format, | ||
uint32_t | parse_options, | ||
uint32_t | validate_options, | ||
struct lyd_node ** | tree | ||
) |
Parse (and validate) input data as a YANG data tree.
Wrapper around lyd_parse_data() hiding work with the input handler and some obscure options.
[in] | ctx | Context to connect with the tree being built here. |
[in] | data | The input data in the specified format to parse (and validate). |
[in] | format | Format of the input data to be parsed. |
[in] | parse_options | Options for parser, see Data parser options. |
[in] | validate_options | Options for the validation phase, see Data validation options. |
[out] | tree | Full parsed data tree, note that NULL can be a valid tree |
LIBYANG_API_DECL LY_ERR lyd_parse_data_path | ( | const struct ly_ctx * | ctx, |
const char * | path, | ||
LYD_FORMAT | format, | ||
uint32_t | parse_options, | ||
uint32_t | validate_options, | ||
struct lyd_node ** | tree | ||
) |
Parse (and validate) input data as a YANG data tree.
Wrapper around lyd_parse_data() hiding work with the input handler and some obscure options.
[in] | ctx | Context to connect with the tree being built here. |
[in] | path | Path to the file with the input data in the specified format to parse (and validate). |
[in] | format | Format of the input data to be parsed. Can be 0 to try to detect format from path extension. |
[in] | parse_options | Options for parser, see Data parser options. |
[in] | validate_options | Options for the validation phase, see Data validation options. |
[out] | tree | Full parsed data tree, note that NULL can be a valid tree |
LIBYANG_API_DECL LY_ERR lyd_parse_ext_data | ( | const struct lysc_ext_instance * | ext, |
struct lyd_node * | parent, | ||
struct ly_in * | in, | ||
LYD_FORMAT | format, | ||
uint32_t | parse_options, | ||
uint32_t | validate_options, | ||
struct lyd_node ** | tree | ||
) |
Parse (and validate) data from the input handler as an extension data tree following the schema tree of the given extension instance.
Note that the data being parsed are limited only to the schema tree specified by the given extension, it does not allow to mix them with the standard data from any module.
Directly applicable to data defined as yang-data.
[in] | ext | Extension instance providing the specific schema tree to match with the data being parsed. |
[in] | parent | Optional parent to connect the parsed nodes to. |
[in] | in | The input handle to provide the dumped data in the specified format to parse (and validate). |
[in] | format | Format of the input data to be parsed. Can be 0 to try to detect format from the input handler. |
[in] | parse_options | Options for parser, see Data parser options. |
[in] | validate_options | Options for the validation phase, see Data validation options. |
[out] | tree | Full parsed data tree, note that NULL can be a valid tree. If parent is set, set to NULL. |
LIBYANG_API_DECL LY_ERR lyd_parse_ext_op | ( | const struct lysc_ext_instance * | ext, |
struct lyd_node * | parent, | ||
struct ly_in * | in, | ||
LYD_FORMAT | format, | ||
enum lyd_type | data_type, | ||
struct lyd_node ** | tree, | ||
struct lyd_node ** | op | ||
) |
Parse extension data into an operation data tree following only the specification from the given extension instance.
Directly applicable to data defined as yang-data.
At least one of parent
, tree
, or op
must always be set.
Specific data_type
values have different parameter meaning as follows:
parent
- must be NULL, the whole RPC is expected;format
- must be LYD_XML, NETCONF supports only this format;tree
- must be provided, all the NETCONF-specific XML envelopes will be returned here as a separate opaque data tree, even if the function fails, this may be returned;op
- must be provided, the RPC/action data tree itself will be returned here, pointing to the operation;parent
- must be NULL, the whole notification is expected;format
- must be LYD_XML, NETCONF supports only this format;tree
- must be provided, all the NETCONF-specific XML envelopes will be returned here as a separate opaque data tree, even if the function fails, this may be returned;op
- must be provided, the notification data tree itself will be returned here, pointing to the operation;parent
- must be set, pointing to the invoked RPC operation (RPC or action) node;format
- must be LYD_XML, NETCONF supports only this format;tree
- must be provided, all the NETCONF-specific XML envelopes will be returned here as a separate opaque data tree, even if the function fails, this may be returned;op
- must be NULL, the reply is appended to the RPC; Note that there are 3 kinds of NETCONF replies - ok, error, and data. Only data reply appends any nodes to the RPC.[in] | ext | Extension instance providing the specific schema tree to match with the data being parsed. |
[in] | parent | Optional parent to connect the parsed nodes to. |
[in] | in | Input handle to read the input from. |
[in] | format | Expected format of the data in in . |
[in] | data_type | Expected operation to parse (Data operation type). |
[out] | tree | Optional full parsed data tree. If parent is set, set to NULL. |
[out] | op | Optional pointer to the operation (action/RPC) node. |
data_type
is a NETCONF message and the root XML element is not the expected one. LIBYANG_API_DECL LY_ERR lyd_parse_op | ( | const struct ly_ctx * | ctx, |
struct lyd_node * | parent, | ||
struct ly_in * | in, | ||
LYD_FORMAT | format, | ||
enum lyd_type | data_type, | ||
struct lyd_node ** | tree, | ||
struct lyd_node ** | op | ||
) |
Parse YANG data into an operation data tree. Specific parsing flags LYD_PARSE_ONLY, LYD_PARSE_STRICT and no validation flags are used.
At least one of parent
, tree
, or op
must always be set.
Specific data_type
values have different parameter meaning as follows:
parent
- must be NULL, the whole RPC is expected;format
- must be LYD_XML, NETCONF supports only this format;tree
- must be provided, all the NETCONF-specific XML envelopes will be returned here as a separate opaque data tree, even if the function fails, this may be returned;op
- must be provided, the RPC/action data tree itself will be returned here, pointing to the operation;parent
- must be NULL, the whole notification is expected;format
- must be LYD_XML, NETCONF supports only this format;tree
- must be provided, all the NETCONF-specific XML envelopes will be returned here as a separate opaque data tree, even if the function fails, this may be returned;op
- must be provided, the notification data tree itself will be returned here, pointing to the operation;parent
- must be set, pointing to the invoked RPC operation (RPC or action) node;format
- must be LYD_XML, NETCONF supports only this format;tree
- must be provided, all the NETCONF-specific XML envelopes will be returned here as a separate opaque data tree, even if the function fails, this may be returned;op
- must be NULL, the reply is appended to the RPC; Note that there are 3 kinds of NETCONF replies - ok, error, and data. Only data reply appends any nodes to the RPC.parent
- must be set, pointing to the invoked RPC operation (RPC or action) node;format
- can be both LYD_JSON and LYD_XML;tree
- must be provided, all the RESTCONF-specific JSON objects will be returned here as a separate opaque data tree, even if the function fails, this may be returned;op
- must be NULL, parent
points to the operation;parent
- must be NULL, the whole notification is expected;format
- must be LYD_JSON, XML-formatted notifications are parsed using LYD_TYPE_NOTIF_NETCONF;tree
- must be provided, all the RESTCONF-specific JSON objects will be returned here as a separate opaque data tree, even if the function fails, this may be returned;op
- must be provided, the notification data tree itself will be returned here, pointing to the operation;parent
- must be set, pointing to the invoked RPC operation (RPC or action) node;format
- can be both LYD_JSON and LYD_XML;tree
- must be provided, all the RESTCONF-specific JSON objects will be returned here as a separate opaque data tree, even if the function fails, this may be returned;op
- must be NULL, parent
points to the operation; Note that error reply should be parsed as 'yang-data' extension data.[in] | ctx | libyang context. |
[in] | parent | Optional parent to connect the parsed nodes to. |
[in] | in | Input handle to read the input from. |
[in] | format | Expected format of the data in in . |
[in] | data_type | Expected operation to parse (Data operation type). |
[out] | tree | Optional full parsed data tree. If parent is set, set to NULL. |
[out] | op | Optional pointer to the operation (action/RPC/notification) node. |
data_type
is a NETCONF message and the root XML element is not the expected one. LIBYANG_API_DECL LY_ERR lyd_validate_all | ( | struct lyd_node ** | tree, |
const struct ly_ctx * | ctx, | ||
uint32_t | val_opts, | ||
struct lyd_node ** | diff | ||
) |
Fully validate a data tree.
The data tree is modified in-place. As a result of the validation, some data might be removed from the tree. In that case, the removed items are freed, not just unlinked.
[in,out] | tree | Data tree to recursively validate. May be changed by validation, might become NULL. |
[in] | ctx | libyang context. Can be NULL if tree is set. |
[in] | val_opts | Validation options (Data validation options). |
[out] | diff | Optional diff with any changes made by the validation. |
LIBYANG_API_DECL LY_ERR lyd_validate_module | ( | struct lyd_node ** | tree, |
const struct lys_module * | module, | ||
uint32_t | val_opts, | ||
struct lyd_node ** | diff | ||
) |
Fully validate a data tree of a module.
The data tree is modified in-place. As a result of the validation, some data might be removed from the tree. In that case, the removed items are freed, not just unlinked.
If several modules need to be validated, the flag LYD_VALIDATE_NOT_FINAL should be used first for validation of each module and then lyd_validate_module_final() should be called also for each module. Otherwise, false-positive validation errors for foreign dependencies may occur.
[in,out] | tree | Data tree to recursively validate. May be changed by validation, might become NULL. |
[in] | module | Module whose data (and schema restrictions) to validate. |
[in] | val_opts | Validation options (Data validation options). |
[out] | diff | Optional diff with any changes made by the validation. |
LIBYANG_API_DECL LY_ERR lyd_validate_module_final | ( | struct lyd_node * | tree, |
const struct lys_module * | module, | ||
uint32_t | val_opts | ||
) |
Finish validation of a module data that have previously been validated with LYD_VALIDATE_NOT_FINAL flag.
This final validation will not add or remove any nodes.
[in] | tree | Data tree to recursively validate. |
[in] | module | Module whose data (and schema restrictions) to validate. |
[in] | val_opts | Validation options (Data validation options). |
LIBYANG_API_DECL LY_ERR lyd_validate_op | ( | struct lyd_node * | op_tree, |
const struct lyd_node * | dep_tree, | ||
enum lyd_type | data_type, | ||
struct lyd_node ** | diff | ||
) |
Validate an RPC/action request, reply, or notification. Only the operation data tree (input/output/notif) is validate, any parents are ignored.
[in,out] | op_tree | Operation tree with any parents. It can point to the operation itself or any of its parents, only the operation subtree is actually validated. |
[in] | dep_tree | Tree to be used for validating references from the operation subtree. |
[in] | data_type | Operation type to validate (only YANG operations are accepted, Data operation type). |
[out] | diff | Optional diff with any changes made by the validation. |