libyang  1.0.101
YANG data modeling language library
Context

Structures and functions to manipulate with the libyang "containers". The context concept allows callers to work in environments with different sets of YANG schemas. More detailed information can be found at Context page. More...

Collaboration diagram for Context:

Modules

 Context options
 

Data Structures

struct  ly_ctx
 libyang context handler. More...
 

Macros

#define LY_MODCLB_NOT_IMPLEMENTED   0x01
 

Typedefs

typedef const struct lys_module *(* ly_module_data_clb) (struct ly_ctx *ctx, const char *name, const char *ns, int options, void *user_data)
 Callback for retrieving missing modules in the context, for which some data was found. More...
 

Functions

struct ly_ctxly_ctx_new (const char *search_dir, int options)
 Create libyang context. More...
 
struct ly_ctxly_ctx_new_ylpath (const char *search_dir, const char *path, LYD_FORMAT format, int options)
 Create libyang context according to the content of the given yang-library data. More...
 
struct ly_ctxly_ctx_new_ylmem (const char *search_dir, const char *data, LYD_FORMAT format, int options)
 Create libyang context according to the content of the given yang-library data. More...
 
unsigned int ly_ctx_internal_modules_count (struct ly_ctx *ctx)
 Number of internal modules, which are in the context and cannot be removed nor disabled. More...
 
int ly_ctx_set_searchdir (struct ly_ctx *ctx, const char *search_dir)
 Add the search path into libyang context. More...
 
void ly_ctx_unset_searchdirs (struct ly_ctx *ctx, int index)
 Clean the search path(s) from the libyang context. More...
 
const char *const * ly_ctx_get_searchdirs (const struct ly_ctx *ctx)
 Get the NULL-terminated list of the search paths in libyang context. More...
 
int ly_ctx_get_options (struct ly_ctx *ctx)
 Get the currently set context's options. More...
 
void ly_ctx_set_disable_searchdirs (struct ly_ctx *ctx)
 Make context to stop searching for schemas (imported, included or requested via ly_ctx_load_module()) in searchdirs set via ly_ctx_set_searchdir() functions. Searchdirs are still stored in the context, so by unsetting the option by ly_ctx_unset_disable_searchdirs() searching in all previously searchdirs is restored. More...
 
void ly_ctx_unset_disable_searchdirs (struct ly_ctx *ctx)
 Reverse function to ly_ctx_set_disable_searchdirs(). More...
 
void ly_ctx_set_disable_searchdir_cwd (struct ly_ctx *ctx)
 Make context to stop implicitly searching for schemas (imported, included or requested via ly_ctx_load_module()) in current working directory. This flag can be unset by ly_ctx_unset_disable_searchdir_cwd(). More...
 
void ly_ctx_unset_disable_searchdir_cwd (struct ly_ctx *ctx)
 Reverse function to ly_ctx_set_disable_searchdir_cwd(). More...
 
void ly_ctx_set_prefer_searchdirs (struct ly_ctx *ctx)
 Prefer context's searchdirs before the user callback (ly_module_imp_clb) provided via ly_ctx_set_module_imp_clb()). More...
 
void ly_ctx_unset_prefer_searchdirs (struct ly_ctx *ctx)
 Reverse function to ly_ctx_set_prefer_searchdirs(). More...
 
void ly_ctx_set_allimplemented (struct ly_ctx *ctx)
 Make context to set all the imported modules to be implemented. By default, if the imported module is not used in leafref's path, augment or deviation, it is imported and its data tree is not taken into account. More...
 
void ly_ctx_unset_allimplemented (struct ly_ctx *ctx)
 Reverse function to ly_ctx_set_allimplemented(). More...
 
void ly_ctx_set_trusted (struct ly_ctx *ctx)
 Change the schema parser behavior when parsing new schemas forcing it to skip some of the schema validation checks to improve performance. Note that parsing invalid schemas this way may lead to an undefined behavior later, e.g. when working with data trees. More...
 
void ly_ctx_unset_trusted (struct ly_ctx *ctx)
 Reverse function to ly_ctx_set_trusted(). More...
 
uint16_t ly_ctx_get_module_set_id (const struct ly_ctx *ctx)
 Get current ID of the modules set. The value is available also as module-set-id in ly_ctx_info() result. More...
 
struct lyd_nodely_ctx_info (struct ly_ctx *ctx)
 Get data of an internal ietf-yang-library module. More...
 
const struct lys_modulely_ctx_get_module_iter (const struct ly_ctx *ctx, uint32_t *idx)
 Iterate over all (enabled) modules in a context. More...
 
const struct lys_modulely_ctx_get_disabled_module_iter (const struct ly_ctx *ctx, uint32_t *idx)
 Iterate over the disabled modules in a context. More...
 
const struct lys_modulely_ctx_get_module (const struct ly_ctx *ctx, const char *name, const char *revision, int implemented)
 Get pointer to the schema tree of the module of the specified name. More...
 
const struct lys_modulely_ctx_get_module_older (const struct ly_ctx *ctx, const struct lys_module *module)
 Get pointer to the older schema tree to the specified one in the provided context. More...
 
const struct lys_modulely_ctx_load_module (struct ly_ctx *ctx, const char *name, const char *revision)
 Try to find the model in the searchpath of ctx and load it into it. If custom missing module callback is set, it is used instead. More...
 
void ly_ctx_set_module_imp_clb (struct ly_ctx *ctx, ly_module_imp_clb clb, void *user_data)
 Set missing include or import module callback. It is meant to be used when the models are not locally available (such as when downloading modules from a NETCONF server), it should not be required in other cases. More...
 
ly_module_imp_clb ly_ctx_get_module_imp_clb (const struct ly_ctx *ctx, void **user_data)
 Get the custom callback for missing import/include module retrieval. More...
 
void ly_ctx_set_module_data_clb (struct ly_ctx *ctx, ly_module_data_clb clb, void *user_data)
 Set the missing data module callback. It will be called when some data is parsed or searched for and their module is not found in the context or is not implemented. More...
 
ly_module_data_clb ly_ctx_get_module_data_clb (const struct ly_ctx *ctx, void **user_data)
 Get the missing data module calback. More...
 
void ly_ctx_set_priv_dup_clb (struct ly_ctx *ctx, void *(*priv_dup_clb)(const void *priv))
 
const struct lys_modulely_ctx_get_module_by_ns (const struct ly_ctx *ctx, const char *ns, const char *revision, int implemented)
 Get pointer to the schema tree of the module of the specified namespace. More...
 
const struct lys_submodulely_ctx_get_submodule (const struct ly_ctx *ctx, const char *module, const char *revision, const char *submodule, const char *sub_revision)
 Get submodule of a main module. More...
 
const struct lys_submodulely_ctx_get_submodule2 (const struct lys_module *main_module, const char *submodule)
 Get submodule of a main module. More...
 
const struct lys_nodely_ctx_get_node (const struct ly_ctx *ctx, const struct lys_node *start, const char *data_path, int output)
 Get schema node according to the given data path (JSON format, see XPath Addressing). More...
 
struct ly_setly_ctx_find_path (struct ly_ctx *ctx, const char *path)
 Get schema node according to the given schema path (see XPath Addressing). More...
 
int ly_ctx_remove_module (const struct lys_module *module, void(*private_destructor)(const struct lys_node *node, void *priv))
 Remove the specified module from its context. More...
 
void ly_ctx_clean (struct ly_ctx *ctx, void(*private_destructor)(const struct lys_node *node, void *priv))
 Remove all the modules from the context except the internal modules. Also the addition data in dictionary are kept. More...
 
void ly_ctx_destroy (struct ly_ctx *ctx, void(*private_destructor)(const struct lys_node *node, void *priv))
 Free all internal structures of the specified context. More...
 
char * ly_path_xml2json (struct ly_ctx *ctx, const char *xml_path, struct lyxml_elem *xml)
 Transform a data path in XML format (node prefixes are XML namespace prefixes of module namespaces) to JSON format (node prefixes are module names directly). More...
 
char * ly_path_data2schema (struct ly_ctx *ctx, const char *data_path)
 Transform a data path into schema path (see XPath Addressing). More...
 

Variables

const typedef char *(* ly_module_imp_clb )(const char *mod_name, const char *mod_rev, const char *submod_name, const char *sub_rev, void *user_data, LYS_INFORMAT *format, void(**free_module_data)(void *model_data, void *user_data))
 Callback for retrieving missing included or imported models in a custom way. More...
 

Detailed Description

Structures and functions to manipulate with the libyang "containers". The context concept allows callers to work in environments with different sets of YANG schemas. More detailed information can be found at Context page.


Data Structure Documentation

◆ ly_ctx

struct ly_ctx

libyang context handler.

Macro Definition Documentation

◆ LY_MODCLB_NOT_IMPLEMENTED

#define LY_MODCLB_NOT_IMPLEMENTED   0x01

Definition at line 1508 of file libyang.h.

Typedef Documentation

◆ ly_module_data_clb

typedef const struct lys_module*(* ly_module_data_clb) (struct ly_ctx *ctx, const char *name, const char *ns, int options, void *user_data)

Callback for retrieving missing modules in the context, for which some data was found.

Either name or ns is ALWAYS set, but both can also be set.

Parameters
[in,out]ctxContext with the missing module.
[in]nameMissing module name.
[in]nsMissing module namespace.
[in]optionsBitmask of LY_MODCLB_* values or 0.
[in]user_dataUser-supplied callback data.
Returns
Newly added or modified module, NULL on failure.

Definition at line 1504 of file libyang.h.

Function Documentation

◆ ly_ctx_new()

struct ly_ctx* ly_ctx_new ( const char *  search_dir,
int  options 
)

Create libyang context.

Context is used to hold all information about schemas. Usually, the application is supposed to work with a single context in which libyang is holding all schemas (and other internal information) according to which the data trees will be processed and validated. So, the schema trees are tightly connected with the specific context and they are held by the context internally

  • caller does not need to keep pointers to the schemas returned by lys_parse(), context knows about them. The data trees created with lyd_parse() are still connected with the specific context, but they are not internally held by the context. The data tree just points and lean on some data held by the context (schema tree, string dictionary, etc.). Therefore, in case of data trees, caller is supposed to keep pointers returned by the lyd_parse() and manage the data tree on its own. This also affects the number of instances of both tree types. While you can have only one instance of specific schema connected with a single context, number of data tree instances is not connected.
Parameters
[in]search_dirDirectory where libyang will search for the imported or included modules and submodules. If no such directory is available, NULL is accepted.
[in]optionsContext options, see Context options.
Returns
Pointer to the created libyang context, NULL in case of error.

◆ ly_ctx_new_ylpath()

struct ly_ctx* ly_ctx_new_ylpath ( const char *  search_dir,
const char *  path,
LYD_FORMAT  format,
int  options 
)

Create libyang context according to the content of the given yang-library data.

This function loads the yang-library data from the file at the given path. If you need to pass the data as string, use ly_ctx_new_ylmem(). Both functions extend functionality of ly_ctx_new() by loading modules specified in the ietf-yang-library form into the context being created.

The preferred tree model revision is 2018-01-17. However, only the first module-set is processed and loaded into the context. If there are no matching nodes from this tree, the legacy tree (originally from model revision 2016-04-09) is processed.

Note, that the modules are loaded the same way as in case of ly_ctx_load_module(), so the schema paths in the yang-library data are ignored and the modules are loaded from the context's search locations. On the other hand, YANG features of the modules are set as specified in the yang-library data.

To get yang library data from a libyang context, use ly_ctx_info().

Parameters
[in]search_dirDirectory where libyang will search for the imported or included modules and submodules. If no such directory is available, NULL is accepted.
[in]pathPath to the file containing yang-library data in the specified format.
[in]formatFormat of the data in the provided file.
[in]optionsContext options, see Context options.
Returns
Pointer to the created libyang context, NULL in case of error.

◆ ly_ctx_new_ylmem()

struct ly_ctx* ly_ctx_new_ylmem ( const char *  search_dir,
const char *  data,
LYD_FORMAT  format,
int  options 
)

Create libyang context according to the content of the given yang-library data.

This function loads the yang-library data from the given string. If you need to pass the data as path to a file holding the data, use ly_ctx_new_ylpath(). Both functions extend functionality of ly_ctx_new() by loading modules specified in the ietf-yang-library form into the context being created.

The preferred tree model revision is 2018-01-17. However, only the first module-set is processed and loaded into the context. If there are no matching nodes from this tree, the legacy tree (originally from model revision 2016-04-09) is processed.

Note, that the modules are loaded the same way as in case of ly_ctx_load_module(), so the schema paths in the yang-library data are ignored and the modules are loaded from the context's search locations. On the other hand, YANG features of the modules are set as specified in the yang-library data.

To get yang library data from a libyang context, use ly_ctx_info().

Parameters
[in]search_dirDirectory where libyang will search for the imported or included modules and submodules. If no such directory is available, NULL is accepted.
[in]dataString containing yang-library data in the specified format.
[in]formatFormat of the data in the provided file.
[in]optionsContext options, see Context options.
Returns
Pointer to the created libyang context, NULL in case of error.

◆ ly_ctx_internal_modules_count()

unsigned int ly_ctx_internal_modules_count ( struct ly_ctx ctx)

Number of internal modules, which are in the context and cannot be removed nor disabled.

Parameters
[in]ctxContext to investigate.
Returns
Number of internal modules, 0 in case of invalid parameter.

◆ ly_ctx_set_searchdir()

int ly_ctx_set_searchdir ( struct ly_ctx ctx,
const char *  search_dir 
)

Add the search path into libyang context.

To reset search paths set in the context, use ly_ctx_unset_searchdirs() and then set search paths again.

Parameters
[in]ctxContext to be modified.
[in]search_dirNew search path to add to the current paths previously set in ctx.
Returns
EXIT_SUCCESS, EXIT_FAILURE.

◆ ly_ctx_unset_searchdirs()

void ly_ctx_unset_searchdirs ( struct ly_ctx ctx,
int  index 
)

Clean the search path(s) from the libyang context.

Parameters
[in]ctxContext to be modified.
[in]indexIndex of the search path to be removed, use negative value to remove them all. Correct index value can be checked via ly_ctx_get_searchdirs().

◆ ly_ctx_get_searchdirs()

const char* const * ly_ctx_get_searchdirs ( const struct ly_ctx ctx)

Get the NULL-terminated list of the search paths in libyang context.

Parameters
[in]ctxContext to query.
Returns
NULL-terminated list (array) of the search paths, NULL if no searchpath was set.

◆ ly_ctx_get_options()

int ly_ctx_get_options ( struct ly_ctx ctx)

Get the currently set context's options.

Parameters
[in]ctxContext to query.
Returns
Combination of all the currently set context's options, see Context options.

◆ ly_ctx_set_disable_searchdirs()

void ly_ctx_set_disable_searchdirs ( struct ly_ctx ctx)

Make context to stop searching for schemas (imported, included or requested via ly_ctx_load_module()) in searchdirs set via ly_ctx_set_searchdir() functions. Searchdirs are still stored in the context, so by unsetting the option by ly_ctx_unset_disable_searchdirs() searching in all previously searchdirs is restored.

The same effect is achieved by using LY_CTX_DISABLE_SEARCHDIRS option when creating new context or parsing a specific schema.

Parameters
[in]ctxContext to be modified.

◆ ly_ctx_unset_disable_searchdirs()

void ly_ctx_unset_disable_searchdirs ( struct ly_ctx ctx)

Reverse function to ly_ctx_set_disable_searchdirs().

Parameters
[in]ctxContext to be modified.

◆ ly_ctx_set_disable_searchdir_cwd()

void ly_ctx_set_disable_searchdir_cwd ( struct ly_ctx ctx)

Make context to stop implicitly searching for schemas (imported, included or requested via ly_ctx_load_module()) in current working directory. This flag can be unset by ly_ctx_unset_disable_searchdir_cwd().

The same effect is achieved by using LY_CTX_DISABLE_SEARCHDIR_CWD option when creating new context or parsing a specific schema.

Parameters
[in]ctxContext to be modified.

◆ ly_ctx_unset_disable_searchdir_cwd()

void ly_ctx_unset_disable_searchdir_cwd ( struct ly_ctx ctx)

Reverse function to ly_ctx_set_disable_searchdir_cwd().

Parameters
[in]ctxContext to be modified.

◆ ly_ctx_set_prefer_searchdirs()

void ly_ctx_set_prefer_searchdirs ( struct ly_ctx ctx)

Prefer context's searchdirs before the user callback (ly_module_imp_clb) provided via ly_ctx_set_module_imp_clb()).

The same effect is achieved by using LY_CTX_PREFER_SEARCHDIRS option when creating new context or parsing a specific schema.

Parameters
[in]ctxContext to be modified.

◆ ly_ctx_unset_prefer_searchdirs()

void ly_ctx_unset_prefer_searchdirs ( struct ly_ctx ctx)

Reverse function to ly_ctx_set_prefer_searchdirs().

Parameters
[in]ctxContext to be modified.

◆ ly_ctx_set_allimplemented()

void ly_ctx_set_allimplemented ( struct ly_ctx ctx)

Make context to set all the imported modules to be implemented. By default, if the imported module is not used in leafref's path, augment or deviation, it is imported and its data tree is not taken into account.

The same effect is achieved by using LY_CTX_ALLIMPLEMENTED option when creating new context or parsing a specific schema.

Note, that function does not make the currently loaded modules, it just change the schema parser behavior for the future parsing. This flag can be unset by ly_ctx_unset_allimplemented().

Parameters
[in]ctxContext to be modified.

◆ ly_ctx_unset_allimplemented()

void ly_ctx_unset_allimplemented ( struct ly_ctx ctx)

Reverse function to ly_ctx_set_allimplemented().

Parameters
[in]ctxContext to be modified.

◆ ly_ctx_set_trusted()

void ly_ctx_set_trusted ( struct ly_ctx ctx)

Change the schema parser behavior when parsing new schemas forcing it to skip some of the schema validation checks to improve performance. Note that parsing invalid schemas this way may lead to an undefined behavior later, e.g. when working with data trees.

The same effect is achieved by using LY_CTX_TRUSTED option when creating new context or parsing a specific schema.

This flag can be unset by ly_ctx_unset_trusted().

Parameters
[in]ctxContext to be modified.

◆ ly_ctx_unset_trusted()

void ly_ctx_unset_trusted ( struct ly_ctx ctx)

Reverse function to ly_ctx_set_trusted().

Parameters
[in]ctxContext to be modified.

◆ ly_ctx_get_module_set_id()

uint16_t ly_ctx_get_module_set_id ( const struct ly_ctx ctx)

Get current ID of the modules set. The value is available also as module-set-id in ly_ctx_info() result.

Parameters
[in]ctxContext to be examined.
Returns
Numeric identifier of the current context's modules set.

◆ ly_ctx_info()

struct lyd_node* ly_ctx_info ( struct ly_ctx ctx)

Get data of an internal ietf-yang-library module.

Parameters
[in]ctxContext with the modules.
Returns
Root data node corresponding to the model, NULL on error. Caller is responsible for freeing the returned data tree using lyd_free().

◆ ly_ctx_get_module_iter()

const struct lys_module* ly_ctx_get_module_iter ( const struct ly_ctx ctx,
uint32_t *  idx 
)

Iterate over all (enabled) modules in a context.

Parameters
[in]ctxContext with the modules.
[in,out]idxIndex of the next module to be returned. Value of 0 starts from the beginning.
Returns
Next context module, NULL if the last was already returned.

◆ ly_ctx_get_disabled_module_iter()

const struct lys_module* ly_ctx_get_disabled_module_iter ( const struct ly_ctx ctx,
uint32_t *  idx 
)

Iterate over the disabled modules in a context.

Parameters
[in]ctxContext with the modules.
[in,out]idxIndex of the next module to be returned. Value of 0 starts from the beginning.
Returns
Next context module, NULL if the last was already returned.

◆ ly_ctx_get_module()

const struct lys_module* ly_ctx_get_module ( const struct ly_ctx ctx,
const char *  name,
const char *  revision,
int  implemented 
)

Get pointer to the schema tree of the module of the specified name.

Parameters
[in]ctxContext to work in.
[in]nameName of the YANG module to get.
[in]revisionOptional revision date of the YANG module to get. If not specified, the schema in the newest/implemented revision (see implemented parameter) is returned if any.
[in]implementedIn case the revision is not specified, require the implemented module instead of the newest revision of the module.
Returns
Pointer to the data model structure, NULL if no schema following the name and revision requirements is present in the context.

◆ ly_ctx_get_module_older()

const struct lys_module* ly_ctx_get_module_older ( const struct ly_ctx ctx,
const struct lys_module module 
)

Get pointer to the older schema tree to the specified one in the provided context.

The module is not necessarily from the provided ctx. If there are multiple schemas older than the provided one, the newest of them is returned.

The function can be used in combination with ly_ctx_get_module() to get all revisions of a module in a context:

for (mod = ly_ctx_get_module(ctx, name, NULL); mod; mod = ly_ctx_get_module_older(ctx, mod)) {
...
}
Parameters
[in]ctxContext to work in.
[in]moduleYANG module to compare with
Returns
Pointer to the data model structure, NULL if no older schema is present in the context.

◆ ly_ctx_load_module()

const struct lys_module* ly_ctx_load_module ( struct ly_ctx ctx,
const char *  name,
const char *  revision 
)

Try to find the model in the searchpath of ctx and load it into it. If custom missing module callback is set, it is used instead.

If there is a possibility that the requested module is already in the context, you should call the ly_ctx_get_module() first to avoid a lot of work performed by ly_ctx_load_module().

Parameters
[in]ctxContext to add to.
[in]nameName of the module to load.
[in]revisionOptional revision date of the module. If not specified, it is assumed that there is only one model revision in the searchpath (the first matching file is parsed).
Returns
Pointer to the data model structure, NULL if not found or some error occurred.

◆ ly_ctx_set_module_imp_clb()

void ly_ctx_set_module_imp_clb ( struct ly_ctx ctx,
ly_module_imp_clb  clb,
void *  user_data 
)

Set missing include or import module callback. It is meant to be used when the models are not locally available (such as when downloading modules from a NETCONF server), it should not be required in other cases.

Parameters
[in]ctxContext that will use this callback.
[in]clbCallback responsible for returning the missing model.
[in]user_dataArbitrary data that will always be passed to the callback clb.

◆ ly_ctx_get_module_imp_clb()

ly_module_imp_clb ly_ctx_get_module_imp_clb ( const struct ly_ctx ctx,
void **  user_data 
)

Get the custom callback for missing import/include module retrieval.

Parameters
[in]ctxContext to read from.
[in]user_dataOptional pointer for getting the user-supplied callback data.
Returns
Callback or NULL if not set.

◆ ly_ctx_set_module_data_clb()

void ly_ctx_set_module_data_clb ( struct ly_ctx ctx,
ly_module_data_clb  clb,
void *  user_data 
)

Set the missing data module callback. It will be called when some data is parsed or searched for and their module is not found in the context or is not implemented.

Parameters
[in]ctxContext that will use this callback.
[in]clbCallback responsible for returning the missing model.
[in]user_dataArbitrary data that will always be passed to the callback clb.

◆ ly_ctx_get_module_data_clb()

ly_module_data_clb ly_ctx_get_module_data_clb ( const struct ly_ctx ctx,
void **  user_data 
)

Get the missing data module calback.

Parameters
[in]ctxContext to read from.
[in]user_dataOptional pointer for getting the user-supplied callback data.
Returns
Callback or NULL if not set.

◆ ly_ctx_set_priv_dup_clb()

void ly_ctx_set_priv_dup_clb ( struct ly_ctx ctx,
void *(*)(const void *priv)  priv_dup_clb 
)

◆ ly_ctx_get_module_by_ns()

const struct lys_module* ly_ctx_get_module_by_ns ( const struct ly_ctx ctx,
const char *  ns,
const char *  revision,
int  implemented 
)

Get pointer to the schema tree of the module of the specified namespace.

Parameters
[in]ctxContext to work in.
[in]nsNamespace of the YANG module to get.
[in]revisionOptional revision date of the YANG module to get. If not specified, the schema in the newest/implemented revision (see implemented parameter) is returned if any.
[in]implementedIn case the revision is not specified, require the implemented module instead of the newest revision of the module.
Returns
Pointer to the data model structure, NULL if no schema following the namespace and revision requirements is present in the context.

◆ ly_ctx_get_submodule()

const struct lys_submodule* ly_ctx_get_submodule ( const struct ly_ctx ctx,
const char *  module,
const char *  revision,
const char *  submodule,
const char *  sub_revision 
)

Get submodule of a main module.

If you already have the pointer to the submodule's main module, use ly_ctx_get_submodule2() instead.

Parameters
[in]ctxContext to work in.
[in]moduleName of the main (belongs-to) module. If NULL, all module submodules are searched.
[in]revisionOptional revision date of module. If NULL, all revisions of module are searched. If set, module must also be set.
[in]submoduleName of the submodule to get.
[in]sub_revisionOptional revision date of submodule. If NULL, the newest revision of submodule is returned.
Returns
Pointer to the data model structure.

◆ ly_ctx_get_submodule2()

const struct lys_submodule* ly_ctx_get_submodule2 ( const struct lys_module main_module,
const char *  submodule 
)

Get submodule of a main module.

If you have only the name (and optionally revision) of the submodule's main module, use ly_ctx_get_submodule() instead.

Parameters
[in]main_moduleMain module (belongs to) of the searched submodule.
[in]submoduleName of the submodule to get.
Returns
Pointer to the data model structure.

◆ ly_ctx_get_node()

const struct lys_node* ly_ctx_get_node ( const struct ly_ctx ctx,
const struct lys_node start,
const char *  data_path,
int  output 
)

Get schema node according to the given data path (JSON format, see XPath Addressing).

This function is meant as a utility function to ease getting a specific schema node directly from context having data_path a const immutable string. Generally, it is better to use lyd_find_path(), lys_find_path(), or ly_ctx_find_path(). Also, it is possible to transform data paths into schema paths using ly_path_data2schema().

Parameters
[in]ctxContext to work in. Must be set if start is NULL.
[in]startStarting node for a relative data node identifier, in which case it is mandatory and ctx can be NULL.
[in]data_pathJSON data path of the node to get.
[in]outputSearch operation output instead input.
Returns
Resolved schema node or NULL.

◆ ly_ctx_find_path()

struct ly_set* ly_ctx_find_path ( struct ly_ctx ctx,
const char *  path 
)

Get schema node according to the given schema path (see XPath Addressing).

Note that the given path must be absolute and fully prefixed (which is the default output of lys_path() function). To get node specified by a relative path, use lys_find_path() instead.

Parameters
[in]ctxContext to work in.
[in]pathSchema path of the node to find.
Returns
Set of found schema nodes. If no nodes are matching path the returned set is empty. In case of an error, NULL is returned.

◆ ly_ctx_remove_module()

int ly_ctx_remove_module ( const struct lys_module module,
void(*)(const struct lys_node *node, void *priv)  private_destructor 
)

Remove the specified module from its context.

Beside the selected module, also all other modules depending on all the modules being removed will be removed as well.

libyang internal modules (those present when the context is created) cannot be removed.

Parameters
[in]moduleModule to be removed.
[in]private_destructorOptional destructor function for private objects assigned to the nodes via lys_set_private(). If NULL, the private objects are not freed by libyang.
Returns
EXIT_SUCCESS or EXIT_FAILURE (in case of invalid parameter).

◆ ly_ctx_clean()

void ly_ctx_clean ( struct ly_ctx ctx,
void(*)(const struct lys_node *node, void *priv)  private_destructor 
)

Remove all the modules from the context except the internal modules. Also the addition data in dictionary are kept.

Parameters
[in]ctxContext to work in.
[in]private_destructorOptional destructor function for private objects assigned to the nodes via lys_set_private(). If NULL, the private objects are not freed by libyang.

◆ ly_ctx_destroy()

void ly_ctx_destroy ( struct ly_ctx ctx,
void(*)(const struct lys_node *node, void *priv)  private_destructor 
)

Free all internal structures of the specified context.

The function should be used before terminating the application to destroy and free all structures internally used by libyang. If the caller uses multiple contexts, the function should be called for each used context.

All instance data are supposed to be freed before destroying the context. Data models are destroyed automatically as part of ly_ctx_destroy() call.

Parameters
[in]ctxlibyang context to destroy
[in]private_destructorOptional destructor function for private objects assigned to the nodes via lys_set_private(). If NULL, the private objects are not freed by libyang. Remember the differences between the structures derived from lys_node and always check lys_node::nodetype.

◆ ly_path_xml2json()

char* ly_path_xml2json ( struct ly_ctx ctx,
const char *  xml_path,
struct lyxml_elem xml 
)

Transform a data path in XML format (node prefixes are XML namespace prefixes of module namespaces) to JSON format (node prefixes are module names directly).

Parameters
[in]ctxContext to work in.
[in]xml_pathPath in XML format to transform.
[in]xmlXML tree to be used for XML namespace prefix resolution.
Returns
Transformed JSON data path, needs to be freed. NULL on error.

◆ ly_path_data2schema()

char* ly_path_data2schema ( struct ly_ctx ctx,
const char *  data_path 
)

Transform a data path into schema path (see XPath Addressing).

Some XPath tokens such as "*" or "//" should not be used because they cannot be properly transformed into schema path. If used, any following nodes will not be transformed and simply copied, so use at your own risk! It causes no problems if the path ends with the aforementioned tokens.

Parameters
[in]ctxContext to work in.
[in]data_pathData path to be transformed.
Returns
Created schema path, NULL on error.

Variable Documentation

◆ ly_module_imp_clb

const typedef char*(* ly_module_imp_clb) (const char *mod_name, const char *mod_rev, const char *submod_name, const char *sub_rev, void *user_data, LYS_INFORMAT *format, void(**free_module_data)(void *model_data, void *user_data))

Callback for retrieving missing included or imported models in a custom way.

Parameters
[in]mod_nameMissing module name.
[in]mod_revOptional missing module revision.
[in]submod_nameOptional missing submodule name.
[in]submod_revOptional missing submodule revision.
[in]user_dataUser-supplied callback data.
[out]formatFormat of the returned module data.
[out]free_module_dataCallback for freeing the returned module data. If not set, the data will be left untouched.
Returns
Requested module data, NULL if the module is supposed to be loaded using standard mechanisms (searched for in the filesystem), NULL and ly_errno set if the callback failed resulting in the module failing to load. If an
  • free_module_data callback is provided, it will be used to free the allegedly const data which were returned by this callback.

Definition at line 1469 of file libyang.h.

ly_ctx_get_module_older
const struct lys_module * ly_ctx_get_module_older(const struct ly_ctx *ctx, const struct lys_module *module)
Get pointer to the older schema tree to the specified one in the provided context.
lyxml_elem::name
const char * name
Definition: xml.h:102
ly_ctx_get_module
const struct lys_module * ly_ctx_get_module(const struct ly_ctx *ctx, const char *name, const char *revision, int implemented)
Get pointer to the schema tree of the module of the specified name.