 |
libyang
1.0.130
YANG data modeling language library
|
Go to the documentation of this file.
21 #include "Internal.hpp"
42 check_libyang_error(
nullptr);
44 deleter = std::make_shared<Deleter>(ctx);
49 check_libyang_error(
nullptr);
51 deleter = std::make_shared<Deleter>(ctx);
56 check_libyang_error(
nullptr);
58 deleter = std::make_shared<Deleter>(ctx);
64 check_libyang_error(ctx);
71 check_libyang_error(ctx);
75 S_Deleter new_deleter = std::make_shared<Deleter>(new_node, deleter);
76 return std::make_shared<Data_Node>(new_node, new_deleter);
80 return module ? std::make_shared<Module>((
lys_module *) module, deleter) :
nullptr;
84 return new_module ? std::make_shared<Module>((
lys_module *) new_module, deleter) :
nullptr;
89 check_libyang_error(
ctx);
91 return module ? std::make_shared<Module>((
lys_module *) module, deleter) :
nullptr;
95 return module ? std::make_shared<Module>((
lys_module *) module, deleter) :
nullptr;
101 std::vector<S_Module> s_vector;
104 if (mod ==
nullptr) {
107 s_vector.push_back(std::make_shared<Module>((
lys_module *) mod, deleter));
116 std::vector<S_Module> s_vector;
119 if (mod ==
nullptr) {
122 s_vector.push_back(std::make_shared<Module>((
lys_module *) mod, deleter));
131 std::vector<std::string> s_vector;
139 if (
data[size] ==
nullptr) {
142 s_vector.push_back(std::string(
data[size]));
148 S_Submodule
Context::get_submodule(
const char *module,
const char *revision,
const char *submodule,
const char *sub_revision) {
153 return tmp_submodule ? std::make_shared<Submodule>((
struct lys_submodule *) tmp_submodule, deleter) :
nullptr;
160 return tmp_submodule ? std::make_shared<Submodule>((
struct lys_submodule *) tmp_submodule, deleter) :
nullptr;
163 const struct lys_node *node =
nullptr;
165 node =
ly_ctx_get_node(ctx, start ? start->node : NULL, data_path, output);
167 return node ? std::make_shared<Schema_Node>((
struct lys_node *) node, deleter) :
nullptr;
175 S_Deleter new_deleter = std::make_shared<Deleter>(
set, deleter);
176 return std::make_shared<Set>(
set, new_deleter);
179 std::vector<S_Schema_Node> s_vector;
183 for (i = 0; i < ctx->models.used; i++) {
184 while ((iter = (
struct lys_node *)
lys_getnext(iter, NULL, ctx->models.list[i], options))) {
185 s_vector.push_back(std::make_shared<Schema_Node>(iter, deleter));
192 struct lyd_node *new_node =
nullptr;
196 check_libyang_error(ctx);
200 S_Deleter new_deleter = std::make_shared<Deleter>(new_node, deleter);
201 return std::make_shared<Data_Node>(new_node, new_deleter);
204 struct lyd_node *new_node =
nullptr;
206 new_node =
lyd_parse_fd(ctx, fd, format, options, NULL);
208 check_libyang_error(ctx);
212 S_Deleter new_deleter = std::make_shared<Deleter>(new_node, deleter);
213 return std::make_shared<Data_Node>(new_node, new_deleter);
221 check_libyang_error(
ctx);
225 S_Deleter new_deleter = std::make_shared<Deleter>(module, deleter);
226 return std::make_shared<Module>(module, new_deleter);
233 check_libyang_error(
ctx);
237 S_Deleter new_deleter = std::make_shared<Deleter>(module, deleter);
238 return std::make_shared<Module>(module, new_deleter);
245 check_libyang_error(
ctx);
249 S_Deleter new_deleter = std::make_shared<Deleter>(module, deleter);
250 return std::make_shared<Module>(module, new_deleter);
253 struct lyd_node *new_node =
nullptr;
257 check_libyang_error(ctx);
261 S_Deleter new_deleter = std::make_shared<Deleter>(new_node, deleter);
262 return std::make_shared<Data_Node>(new_node, new_deleter);
265 struct lyd_node *new_node =
nullptr;
268 throw std::invalid_argument(
"Elem can not be empty");
273 check_libyang_error(ctx);
277 S_Deleter new_deleter = std::make_shared<Deleter>(new_node, deleter);
278 return std::make_shared<Data_Node>(new_node, new_deleter);
286 mod_missing_cb.emplace_back(std::move(callback), std::move(deleter));
289 const char*
Context::cpp_mod_missing_cb(
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*,
void*))
293 const auto &cb = x.first;
294 auto ret = cb(mod_name, mod_rev, submod_name, sub_rev);
296 *format = ret.format;
325 std::vector<S_Error> s_vector;
337 s_vector.push_back(std::make_shared<Error>(eitem));
357 check_libyang_error(
nullptr);
361 deleter = std::make_shared<Deleter>(set_new);
369 std::vector<S_Data_Node> s_vector;
372 for (i = 0; i <
set->number; i++){
373 s_vector.push_back(std::make_shared<Data_Node>(
set->set.
d[i], deleter));
379 std::vector<S_Schema_Node> s_vector;
382 for (i = 0; i <
set->number; i++){
383 s_vector.push_back(std::make_shared<Schema_Node>(
set->set.
s[i], deleter));
394 auto deleter = std::make_shared<Deleter>(new_set);
395 return std::make_shared<Set>(new_set, deleter);
399 throw std::invalid_argument(
"Node can not be empty");
405 throw std::invalid_argument(
"Node can not be empty");
426 throw std::invalid_argument(
"Node can not be empty");
432 throw std::invalid_argument(
"Node can not be empty");
442 return new_ctx ? std::make_shared<Context>(new_ctx,
nullptr) :
nullptr;
Error(struct ly_err_item *eitem)
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.
std::vector< S_Schema_Node > data_instantiables(int options)
LYS_INFORMAT
Schema input formats accepted by libyang parser functions.
const char *const * ly_ctx_get_searchdirs(const struct ly_ctx *ctx)
Get the NULL-terminated list of the search paths in libyang context.
std::vector< std::string > get_searchdirs()
void add_missing_module_callback(const mod_missing_cb_t &callback, const mod_missing_deleter_t &deleter=mod_missing_deleter_t())
Add a missing include or import module callback.
struct lyd_node * lyd_parse_fd(struct ly_ctx *ctx, int fd, LYD_FORMAT format, int options,...)
Read (and validate) data from the given file descriptor.
int ly_set_add(struct ly_set *set, void *node, int options)
Add a lyd_node or lys_node object into the set.
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...
static void cpp_mod_missing_deleter(void *data, void *user_data)
std::vector< S_Schema_Node > schema()
S_Context create_new_Context(struct ly_ctx *ctx)
S_Module get_module(const char *name, const char *revision=nullptr, int implemented=0)
struct ly_set * ly_set_dup(const struct ly_set *set)
Duplicate the existing set.
Main schema node structure representing YANG module.
int ly_set_rm(struct ly_set *set, void *node)
Remove a lyd_node or lys_node object from the set.
static const char * cpp_mod_missing_cb(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))
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.
Class implementation for libyang C header libyang.h.
int ly_set_clean(struct ly_set *set)
Remove all objects from the set, but keep the set container for further use.
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.
S_Data_Node parse_data_xml(S_Xml_Elem elem, int options=0)
S_Module get_module_older(S_Module module)
S_Module parse_module_mem(const char *data, LYS_INFORMAT format)
S_Module parse_module_path(const char *path, LYS_INFORMAT format)
S_Module get_module_by_ns(const char *ns, const char *revision=nullptr, int implemented=0)
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...
int ly_set_contains(const struct ly_set *set, void *node)
Get know if the set contains the specified object.
S_Data_Node parse_data_fd(int fd, LYD_FORMAT format, int options=0)
struct lyd_node * lyd_parse_xml(struct ly_ctx *ctx, struct lyxml_elem **root, int options,...)
Parse (and validate) XML tree.
int contains(S_Data_Node node)
const struct lys_submodule * ly_ctx_get_submodule2(const struct lys_module *main_module, const char *submodule)
Get submodule of a main module.
int set_searchdir(const char *search_dir)
const struct lys_module * lys_parse_mem(struct ly_ctx *ctx, const char *data, LYS_INFORMAT format)
Load a schema into the specified context.
std::vector< S_Module > get_module_iter()
struct lyd_node * lyd_parse_path(struct ly_ctx *ctx, const char *path, LYD_FORMAT format, int options,...)
Read (and validate) data from the given file path.
Class implementation for libyang C header xml.h.
LY_LOG_LEVEL set_log_verbosity(LY_LOG_LEVEL level)
The main libyang public header.
Generic structure for a data node, directly applicable to the data nodes defined as LYS_CONTAINER,...
libyang representation of data trees.
struct ly_err_item * next
S_Submodule get_submodule2(S_Module main_module, const char *submodule=nullptr)
LYD_FORMAT
Data input/output formats supported by libyang parser and printer functions.
struct ly_ctx * ly_ctx_new(const char *search_dir, int options)
Create libyang context.
LY_LOG_LEVEL
Verbosity levels of the libyang logger.
Structure to hold a set of (not necessary somehow connected) lyd_node or lys_node objects....
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 dictio...
std::vector< S_Module > get_disabled_module_iter()
S_Module parse_module_fd(int fd, LYS_INFORMAT format)
struct lyd_node * ly_ctx_info(struct ly_ctx *ctx)
Get data of an internal ietf-yang-library module.
struct ly_set * ly_set_new(void)
Create and initiate new ly_set structure.
Class implementation for libyang C header tree_schema.h.
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).
int add(S_Data_Node node, int options=0)
Context(struct ly_ctx *ctx, S_Deleter deleter)
S_Data_Node parse_data_path(const char *path, LYD_FORMAT format, int options=0)
Submodule schema node structure that can be included into a YANG module.
Common structure representing single YANG data statement describing.
std::function< mod_missing_cb_return(const char *mod_name, const char *mod_rev, const char *submod_name, const char *sub_rev)> mod_missing_cb_t
S_Module load_module(const char *name, const char *revision=nullptr)
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.
S_Data_Node parse_data_mem(const char *data, LYD_FORMAT format, int options=0)
libyang representation of data model trees.
#define ly_errno
libyang specific (thread-safe) errno (see LY_ERR for the list of possible values and their meaning).
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.
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.
class for wrapping ly_ctx.
Libyang full error structure.
std::vector< std::pair< mod_missing_cb_t, mod_missing_deleter_t > > mod_missing_cb
std::function< void(void *)> mod_missing_deleter_t
S_Submodule get_submodule(const char *module, const char *revision=nullptr, const char *submodule=nullptr, const char *sub_revision=nullptr)
struct ly_err_item * ly_err_first(const struct ly_ctx *ctx)
Get the first (thread, context-specific) generated error structure.
std::vector< const mod_missing_deleter_t * > mod_missing_deleter
struct lyd_node * lyd_parse_mem(struct ly_ctx *ctx, const char *data, LYD_FORMAT format, int options,...)
Parse (and validate) data from memory.
int rm_index(unsigned int index)
LY_LOG_LEVEL ly_verb(LY_LOG_LEVEL level)
Set logger verbosity level.
int ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir)
Add the search path into libyang context.
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).
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.
int set_log_options(int options)
std::vector< S_Error > get_ly_errors(S_Context context)
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.
int ly_log_options(int opts)
Set additional logger options. Default is LY_LOLOG | LY_LOSTORE_LAST.
Class implementation for libyang C header tree_data.h.
S_Schema_Node get_node(S_Schema_Node start, const char *data_path, int output=0)
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.
std::vector< S_Data_Node > data()
int ly_set_rm_index(struct ly_set *set, unsigned int index)
Remove a lyd_node or lys_node object from the set index.
S_Set find_path(const char *schema_path)
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....
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.