libyang  2.1.80
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
context.h
Go to the documentation of this file.
1 
16 #ifndef LY_CONTEXT_H_
17 #define LY_CONTEXT_H_
18 
19 #include <stdint.h>
20 
21 #include "log.h"
22 #include "parser_schema.h"
23 #include "tree_data.h"
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28 
29 struct lys_module;
30 
151 struct ly_ctx;
152 
162 #define LY_CTX_ALL_IMPLEMENTED 0x01
163 #define LY_CTX_REF_IMPLEMENTED 0x02
169 #define LY_CTX_NO_YANGLIBRARY 0x04
175 #define LY_CTX_DISABLE_SEARCHDIRS 0x08
179 #define LY_CTX_DISABLE_SEARCHDIR_CWD 0x10
182 #define LY_CTX_PREFER_SEARCHDIRS 0x20
183 #define LY_CTX_SET_PRIV_PARSED 0x40
191 #define LY_CTX_EXPLICIT_COMPILE 0x80
197 #define LY_CTX_ENABLE_IMP_FEATURES 0x0100
225 LIBYANG_API_DECL LY_ERR ly_ctx_new(const char *search_dir, uint16_t options, struct ly_ctx **new_ctx);
226 
249 LIBYANG_API_DECL LY_ERR ly_ctx_new_ylpath(const char *search_dir, const char *path, LYD_FORMAT format, int options,
250  struct ly_ctx **ctx);
251 
266 LIBYANG_API_DECL LY_ERR ly_ctx_new_ylmem(const char *search_dir, const char *data, LYD_FORMAT format, int options,
267  struct ly_ctx **ctx);
268 
282 LIBYANG_API_DECL LY_ERR ly_ctx_new_yldata(const char *search_dir, const struct lyd_node *tree, int options,
283  struct ly_ctx **ctx);
284 
292 LIBYANG_API_DECL LY_ERR ly_ctx_compile(struct ly_ctx *ctx);
293 
304 LIBYANG_API_DECL LY_ERR ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir);
305 
315 LIBYANG_API_DECL LY_ERR ly_ctx_unset_searchdir(struct ly_ctx *ctx, const char *value);
316 
328 LIBYANG_API_DECL LY_ERR ly_ctx_unset_searchdir_last(struct ly_ctx *ctx, uint32_t count);
329 
337 LIBYANG_API_DECL const char * const *ly_ctx_get_searchdirs(const struct ly_ctx *ctx);
338 
345 LIBYANG_API_DECL uint16_t ly_ctx_get_options(const struct ly_ctx *ctx);
346 
355 LIBYANG_API_DECL LY_ERR ly_ctx_set_options(struct ly_ctx *ctx, uint16_t option);
356 
363 LIBYANG_API_DECL LY_ERR ly_ctx_unset_options(struct ly_ctx *ctx, uint16_t option);
364 
371 LIBYANG_API_DECL uint16_t ly_ctx_get_change_count(const struct ly_ctx *ctx);
372 
383 LIBYANG_API_DECL uint32_t ly_ctx_get_modules_hash(const struct ly_ctx *ctx);
384 
391 typedef void (*ly_module_imp_data_free_clb)(void *module_data, void *user_data);
392 
415 typedef LY_ERR (*ly_module_imp_clb)(const char *mod_name, const char *mod_rev, const char *submod_name, const char *submod_rev,
416  void *user_data, LYS_INFORMAT *format, const char **module_data, ly_module_imp_data_free_clb *free_module_data);
417 
425 LIBYANG_API_DECL ly_module_imp_clb ly_ctx_get_module_imp_clb(const struct ly_ctx *ctx, void **user_data);
426 
436 LIBYANG_API_DECL void ly_ctx_set_module_imp_clb(struct ly_ctx *ctx, ly_module_imp_clb clb, void *user_data);
437 
447 typedef LY_ERR (*ly_ext_data_clb)(const struct lysc_ext_instance *ext, void *user_data, void **ext_data,
448  ly_bool *ext_data_free);
449 
463 LIBYANG_API_DECL ly_ext_data_clb ly_ctx_set_ext_data_clb(struct ly_ctx *ctx, ly_ext_data_clb clb, void *user_data);
464 
474 LIBYANG_API_DECL struct lys_module *ly_ctx_get_module(const struct ly_ctx *ctx, const char *name, const char *revision);
475 
486 LIBYANG_API_DECL struct lys_module *ly_ctx_get_module_latest(const struct ly_ctx *ctx, const char *name);
487 
496 LIBYANG_API_DECL struct lys_module *ly_ctx_get_module_implemented(const struct ly_ctx *ctx, const char *name);
497 
507 LIBYANG_API_DECL struct lys_module *ly_ctx_get_module_iter(const struct ly_ctx *ctx, uint32_t *index);
508 
518 LIBYANG_API_DECL struct lys_module *ly_ctx_get_module_ns(const struct ly_ctx *ctx, const char *ns, const char *revision);
519 
530 LIBYANG_API_DECL struct lys_module *ly_ctx_get_module_latest_ns(const struct ly_ctx *ctx, const char *ns);
531 
540 LIBYANG_API_DECL struct lys_module *ly_ctx_get_module_implemented_ns(const struct ly_ctx *ctx, const char *ns);
541 
550 LIBYANG_API_DECL const struct lysp_submodule *ly_ctx_get_submodule(const struct ly_ctx *ctx, const char *submodule,
551  const char *revision);
552 
561 LIBYANG_API_DECL const struct lysp_submodule *ly_ctx_get_submodule_latest(const struct ly_ctx *ctx, const char *submodule);
562 
571 LIBYANG_API_DECL const struct lysp_submodule *ly_ctx_get_submodule2(const struct lys_module *module, const char *submodule,
572  const char *revision);
573 
582 LIBYANG_API_DECL const struct lysp_submodule *ly_ctx_get_submodule2_latest(const struct lys_module *module,
583  const char *submodule);
584 
602 LIBYANG_API_DECL void ly_ctx_reset_latests(struct ly_ctx *ctx);
603 
611 LIBYANG_API_DECL uint32_t ly_ctx_internal_modules_count(const struct ly_ctx *ctx);
612 
632 LIBYANG_API_DECL struct lys_module *ly_ctx_load_module(struct ly_ctx *ctx, const char *name, const char *revision,
633  const char **features);
634 
656 LIBYANG_API_DECL LY_ERR ly_ctx_get_yanglib_data(const struct ly_ctx *ctx, struct lyd_node **root,
657  const char *content_id_format, ...);
658 
674 LIBYANG_API_DECL void ly_ctx_destroy(struct ly_ctx *ctx);
675 
678 #ifdef __cplusplus
679 }
680 #endif
681 
682 #endif /* LY_CONTEXT_H_ */
LIBYANG_API_DECL LY_ERR ly_ctx_unset_options(struct ly_ctx *ctx, uint16_t option)
Unset some of the context&#39;s options, see Context options.
LIBYANG_API_DECL const struct lysp_submodule * ly_ctx_get_submodule_latest(const struct ly_ctx *ctx, const char *submodule)
Get the latests revision of a submodule from context. If its belongs-to module is known...
struct ly_ctx * ctx
Definition: tree_schema.h:2101
LIBYANG_API_DECL uint32_t ly_ctx_internal_modules_count(const struct ly_ctx *ctx)
Learn the number of internal modules of a context. Internal modules is considered one that was loaded...
Generic structure for a data node.
Definition: tree_data.h:781
YANG extension compiled instance.
Definition: plugins_exts.h:436
LIBYANG_API_DECL struct lys_module * ly_ctx_get_module_iter(const struct ly_ctx *ctx, uint32_t *index)
Iterate over all modules in the given context.
Schema parsers for libyang.
uint8_t ly_bool
Type to indicate boolean value.
Definition: log.h:28
LIBYANG_API_DECL void ly_ctx_reset_latests(struct ly_ctx *ctx)
Reset cached latest revision information of the schemas in the context.
LIBYANG_API_DECL uint32_t ly_ctx_get_modules_hash(const struct ly_ctx *ctx)
Get the hash of all the modules in the context. Since order of the modules is significant, even when 2 contexts have the same modules but loaded in a different order, the hash will differ.
LIBYANG_API_DECL LY_ERR ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir)
Add the search path into libyang context.
LIBYANG_API_DECL struct lys_module * ly_ctx_get_module_implemented_ns(const struct ly_ctx *ctx, const char *ns)
Get the (only) implemented YANG module specified by its namespace.
const char * ns
Definition: tree_schema.h:2104
LIBYANG_API_DECL LY_ERR ly_ctx_unset_searchdir(struct ly_ctx *ctx, const char *value)
Clean the search path(s) from the libyang context.
LIBYANG_API_DECL ly_ext_data_clb ly_ctx_set_ext_data_clb(struct ly_ctx *ctx, ly_ext_data_clb clb, void *user_data)
Set callback providing run-time extension instance data. The expected data depend on the extension...
LIBYANG_API_DECL 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...
LIBYANG_API_DECL struct lys_module * ly_ctx_get_module_implemented(const struct ly_ctx *ctx, const char *name)
Get the (only) implemented YANG module specified by its name.
libyang representation of YANG data trees.
LYD_FORMAT
Data input/output formats supported by libyang parser and printer functions.
Definition: tree_data.h:533
LIBYANG_API_DECL LY_ERR ly_ctx_new_ylpath(const char *search_dir, const char *path, LYD_FORMAT format, int options, struct ly_ctx **ctx)
Create libyang context according to the provided yang-library data in a file.
LIBYANG_API_DECL LY_ERR ly_ctx_set_options(struct ly_ctx *ctx, uint16_t option)
Set some of the context&#39;s options, see Context options.
LYS_INFORMAT
Schema input formats accepted by libyang parser functions.
Definition: parser_schema.h:91
LY_ERR(* ly_ext_data_clb)(const struct lysc_ext_instance *ext, void *user_data, void **ext_data, ly_bool *ext_data_free)
Callback for getting arbitrary run-time data required by an extension instance.
Definition: context.h:476
LY_ERR(* ly_module_imp_clb)(const char *mod_name, const char *mod_rev, const char *submod_name, const char *submod_rev, void *user_data, LYS_INFORMAT *format, const char **module_data, ly_module_imp_data_free_clb *free_module_data)
Callback for retrieving missing included or imported models in a custom way.
Definition: context.h:444
LIBYANG_API_DECL LY_ERR ly_ctx_new_ylmem(const char *search_dir, const char *data, LYD_FORMAT format, int options, struct ly_ctx **ctx)
Create libyang context according to the provided yang-library data in a string.
void(* ly_module_imp_data_free_clb)(void *module_data, void *user_data)
Callback for freeing returned module data in ly_module_imp_clb.
Definition: context.h:420
Available YANG schema tree structures representing YANG module.
Definition: tree_schema.h:2100
LIBYANG_API_DECL struct lys_module * ly_ctx_get_module_ns(const struct ly_ctx *ctx, const char *ns, const char *revision)
Get YANG module of the given namespace and revision.
LIBYANG_API_DECL const char *const * ly_ctx_get_searchdirs(const struct ly_ctx *ctx)
Get the NULL-terminated list of the search paths in libyang context. Do not modify the result! ...
LIBYANG_API_DECL const struct lysp_submodule * ly_ctx_get_submodule2(const struct lys_module *module, const char *submodule, const char *revision)
Get a specific submodule from a module. If the belongs-to module is not known, use ly_ctx_get_submodu...
LIBYANG_API_DECL 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.
LIBYANG_API_DECL const struct lysp_submodule * ly_ctx_get_submodule(const struct ly_ctx *ctx, const char *submodule, const char *revision)
Get a specific submodule from context. If its belongs-to module is known, use ly_ctx_get_submodule2()...
LIBYANG_API_DECL uint16_t ly_ctx_get_options(const struct ly_ctx *ctx)
Get the currently set context&#39;s options.
LIBYANG_API_DECL struct lys_module * ly_ctx_get_module_latest_ns(const struct ly_ctx *ctx, const char *ns)
Get the latest revision of the YANG module specified by its namespace.
LIBYANG_API_DECL LY_ERR ly_ctx_compile(struct ly_ctx *ctx)
Compile (recompile) the context applying all the performed changes after the last context compilation...
LIBYANG_API_DECL struct lys_module * ly_ctx_get_module(const struct ly_ctx *ctx, const char *name, const char *revision)
Get YANG module of the given name and revision.
LIBYANG_API_DECL LY_ERR ly_ctx_get_yanglib_data(const struct ly_ctx *ctx, struct lyd_node **root, const char *content_id_format,...)
Get data of the internal ietf-yang-library module with information about all the loaded modules...
LY_ERR
libyang&#39;s error codes returned by the libyang functions.
Definition: log.h:254
LIBYANG_API_DECL LY_ERR ly_ctx_new_yldata(const char *search_dir, const struct lyd_node *tree, int options, struct ly_ctx **ctx)
Create libyang context according to the provided yang-library data in a data tree.
LIBYANG_API_DECL struct lys_module * ly_ctx_load_module(struct ly_ctx *ctx, const char *name, const char *revision, const char **features)
Try to find the model in the searchpaths of ctx and load it into it. If custom missing module callbac...
Logger manipulation routines and error definitions.
LIBYANG_API_DECL uint16_t ly_ctx_get_change_count(const struct ly_ctx *ctx)
Get the change count of the context (module set) during its life-time.
const char * revision
Definition: tree_schema.h:2103
libyang context handler.
const char * name
Definition: tree_schema.h:2102
LIBYANG_API_DECL void ly_ctx_destroy(struct ly_ctx *ctx)
Free all internal structures of the specified context.
LIBYANG_API_DECL struct lys_module * ly_ctx_get_module_latest(const struct ly_ctx *ctx, const char *name)
Get the latest revision of the YANG module specified by its name.
LIBYANG_API_DECL LY_ERR ly_ctx_unset_searchdir_last(struct ly_ctx *ctx, uint32_t count)
Remove the least recently added search path(s) from the libyang context.
LIBYANG_API_DECL const struct lysp_submodule * ly_ctx_get_submodule2_latest(const struct lys_module *module, const char *submodule)
Get the latest revision of a submodule from a module. If the belongs-to module is not known...