libyang 5.4.9
libyang is YANG data modelling language parser and toolkit written (and providing API) in C.
Loading...
Searching...
No Matches
context.h
Go to the documentation of this file.
1
15
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
26extern "C" {
27#endif
28
29struct lys_module;
30
155
165
170struct ly_ctx;
171
180
181#define LY_CTX_ALL_IMPLEMENTED 0x01
182#define LY_CTX_REF_IMPLEMENTED 0x02
188#define LY_CTX_NO_YANGLIBRARY 0x04
194#define LY_CTX_DISABLE_SEARCHDIRS 0x08
198#define LY_CTX_DISABLE_SEARCHDIR_CWD 0x10
201#define LY_CTX_PREFER_SEARCHDIRS 0x20
202#define LY_CTX_SET_PRIV_PARSED 0x40
210#define LY_CTX_EXPLICIT_COMPILE 0x80
216#define LY_CTX_ENABLE_IMP_FEATURES 0x0100
219#define LY_CTX_COMPILE_OBSOLETE 0x0200
222#define LY_CTX_LYB_HASHES 0x0400
224#define LY_CTX_LEAFREF_EXTENDED 0x0800
226#define LY_CTX_LEAFREF_LINKING 0x1000
230#define LY_CTX_BUILTIN_PLUGINS_ONLY 0x2000
236#define LY_CTX_STATIC_PLUGINS_ONLY 0x4000
241
242/* 0x80000000 reserved for internal use */
243
245
268LIBYANG_API_DECL LY_ERR ly_ctx_new(const char *search_dir, uint32_t options, struct ly_ctx **new_ctx);
269
292LIBYANG_API_DECL LY_ERR ly_ctx_new_ylpath(const char *search_dir, const char *path, LYD_FORMAT format, int options,
293 struct ly_ctx **ctx);
294
309LIBYANG_API_DECL LY_ERR ly_ctx_new_ylmem(const char *search_dir, const char *data, LYD_FORMAT format, int options,
310 struct ly_ctx **ctx);
311
325LIBYANG_API_DECL LY_ERR ly_ctx_new_yldata(const char *search_dir, const struct lyd_node *tree, int options,
326 struct ly_ctx **ctx);
327
335LIBYANG_API_DECL LY_ERR ly_ctx_compile(struct ly_ctx *ctx);
336
347LIBYANG_API_DECL LY_ERR ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir);
348
358LIBYANG_API_DECL LY_ERR ly_ctx_unset_searchdir(struct ly_ctx *ctx, const char *value);
359
371LIBYANG_API_DECL LY_ERR ly_ctx_unset_searchdir_last(struct ly_ctx *ctx, uint32_t count);
372
380LIBYANG_API_DECL const char * const *ly_ctx_get_searchdirs(const struct ly_ctx *ctx);
381
388LIBYANG_API_DECL uint32_t ly_ctx_get_options(const struct ly_ctx *ctx);
389
398LIBYANG_API_DECL LY_ERR ly_ctx_set_options(struct ly_ctx *ctx, uint32_t option);
399
406LIBYANG_API_DECL LY_ERR ly_ctx_unset_options(struct ly_ctx *ctx, uint32_t option);
407
414LIBYANG_API_DECL uint16_t ly_ctx_get_change_count(const struct ly_ctx *ctx);
415
429LIBYANG_API_DECL uint32_t ly_ctx_get_modules_hash(const struct ly_ctx *ctx);
430
437typedef void (*ly_module_imp_data_free_clb)(void *module_data, void *user_data);
438
461typedef LY_ERR (*ly_module_imp_clb)(const char *mod_name, const char *mod_rev, const char *submod_name, const char *submod_rev,
462 void *user_data, LYS_INFORMAT *format, const char **module_data, ly_module_imp_data_free_clb *free_module_data);
463
471LIBYANG_API_DECL ly_module_imp_clb ly_ctx_get_module_imp_clb(const struct ly_ctx *ctx, void **user_data);
472
482LIBYANG_API_DECL void ly_ctx_set_module_imp_clb(struct ly_ctx *ctx, ly_module_imp_clb clb, void *user_data);
483
495typedef LY_ERR (*ly_ext_data_clb)(const struct lysc_ext_instance *ext, const struct lyd_node *parent, void *user_data,
496 void **ext_data, ly_bool *ext_data_free);
497
511LIBYANG_API_DECL ly_ext_data_clb ly_ctx_set_ext_data_clb(const struct ly_ctx *ctx, ly_ext_data_clb clb, void *user_data);
512
522LIBYANG_API_DECL struct lys_module *ly_ctx_get_module(const struct ly_ctx *ctx, const char *name, const char *revision);
523
534LIBYANG_API_DECL struct lys_module *ly_ctx_get_module_latest(const struct ly_ctx *ctx, const char *name);
535
544LIBYANG_API_DECL struct lys_module *ly_ctx_get_module_implemented(const struct ly_ctx *ctx, const char *name);
545
555LIBYANG_API_DECL struct lys_module *ly_ctx_get_module_iter(const struct ly_ctx *ctx, uint32_t *index);
556
566LIBYANG_API_DECL struct lys_module *ly_ctx_get_module_ns(const struct ly_ctx *ctx, const char *ns, const char *revision);
567
578LIBYANG_API_DECL struct lys_module *ly_ctx_get_module_latest_ns(const struct ly_ctx *ctx, const char *ns);
579
588LIBYANG_API_DECL struct lys_module *ly_ctx_get_module_implemented_ns(const struct ly_ctx *ctx, const char *ns);
589
598LIBYANG_API_DECL const struct lysp_submodule *ly_ctx_get_submodule(const struct ly_ctx *ctx, const char *submodule,
599 const char *revision);
600
609LIBYANG_API_DECL const struct lysp_submodule *ly_ctx_get_submodule_latest(const struct ly_ctx *ctx, const char *submodule);
610
619LIBYANG_API_DECL const struct lysp_submodule *ly_ctx_get_submodule2(const struct lys_module *module, const char *submodule,
620 const char *revision);
621
630LIBYANG_API_DECL const struct lysp_submodule *ly_ctx_get_submodule2_latest(const struct lys_module *module,
631 const char *submodule);
632
640LIBYANG_API_DECL uint32_t ly_ctx_internal_modules_count(const struct ly_ctx *ctx);
641
661LIBYANG_API_DECL struct lys_module *ly_ctx_load_module(struct ly_ctx *ctx, const char *name, const char *revision,
662 const char **features);
663
685LIBYANG_API_DECL LY_ERR ly_ctx_get_yanglib_data(const struct ly_ctx *ctx, struct lyd_node **root,
686 const char *content_id_format, ...);
687
694LIBYANG_API_DECL void ly_ctx_free_parsed(struct ly_ctx *ctx);
695
703LIBYANG_API_DECL int ly_ctx_compiled_size(const struct ly_ctx *ctx);
704
713LIBYANG_API_DECL LY_ERR ly_ctx_compiled_print(const struct ly_ctx *ctx, void *mem, void **mem_end);
714
725LIBYANG_API_DECL LY_ERR ly_ctx_new_printed(const void *mem, struct ly_ctx **ctx);
726
733LIBYANG_API_DECL ly_bool ly_ctx_is_printed(const struct ly_ctx *ctx);
734
750LIBYANG_API_DECL void ly_ctx_destroy(struct ly_ctx *ctx);
751
753
754#ifdef __cplusplus
755}
756#endif
757
758#endif /* LY_CONTEXT_H_ */
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 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_ERR ly_ctx_compiled_print(const struct ly_ctx *ctx, void *mem, void **mem_end)
Print (serialize) a compiled context (without any parsed modules) into a pre-allocated memory chunk.
LIBYANG_API_DECL int ly_ctx_compiled_size(const struct ly_ctx *ctx)
Get the total size a compiled context requires for serialization.
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 modules in a custom way.
Definition context.h:461
LIBYANG_API_DECL LY_ERR ly_ctx_set_options(struct ly_ctx *ctx, uint32_t option)
Set some of the context's options, see Context options.
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_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....
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,...
LIBYANG_API_DECL LY_ERR ly_ctx_new_printed(const void *mem, struct ly_ctx **ctx)
Create a (immutable) context that was printed into a memory chunk.
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 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...
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 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 modules are not locall...
LIBYANG_API_DECL void ly_ctx_destroy(struct ly_ctx *ctx)
Free all internal structures of the specified context.
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 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,...
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!
LY_ERR(* ly_ext_data_clb)(const struct lysc_ext_instance *ext, const struct lyd_node *parent, 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:495
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.
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,...
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 ly_bool ly_ctx_is_printed(const struct ly_ctx *ctx)
Check if the context was created from a printed (immutable) context.
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 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 struct lys_module * ly_ctx_load_module(struct ly_ctx *ctx, const char *name, const char *revision, const char **features)
Try to find the module in the searchpaths of ctx and load it into it. If custom missing module callba...
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:437
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_iter(const struct ly_ctx *ctx, uint32_t *index)
Iterate over all modules in the given 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.
LIBYANG_API_DECL void ly_ctx_free_parsed(struct ly_ctx *ctx)
Free all the parsed modules in a context. Any data manipulation will be possible but some schema func...
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 uint32_t ly_ctx_get_options(const struct ly_ctx *ctx)
Get the currently set context's options.
LIBYANG_API_DECL ly_ext_data_clb ly_ctx_set_ext_data_clb(const 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 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.
LIBYANG_API_DECL LY_ERR ly_ctx_unset_options(struct ly_ctx *ctx, uint32_t option)
Unset some of the context's options, see Context options.
LIBYANG_API_DECL LY_ERR ly_ctx_new(const char *search_dir, uint32_t options, struct ly_ctx **new_ctx)
Create libyang 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_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 context handler.
LYD_FORMAT
Data input/output formats supported by libyang parser and printer functions.
Definition tree_data.h:511
LY_ERR
libyang's error codes returned by the libyang functions.
Definition log.h:252
YANG extension compiled instance.
const char * name
const char * revision
const char * ns
struct ly_ctx * ctx
LYS_INFORMAT
Schema input formats accepted by libyang parser functions.
Available YANG schema tree structures representing YANG module.
Logger manipulation routines and error definitions.
uint8_t ly_bool
Type to indicate boolean value.
Definition log.h:36
Schema parsers for libyang.
libyang representation of YANG data trees.
struct lyd_node * parent
Definition tree_data.h:790
Generic structure for a data node.
Definition tree_data.h:783