libyang  1.0.101
YANG data modeling language library
libyang.h File Reference

The main libyang public header. More...

#include <stdio.h>
#include "tree_schema.h"
#include "tree_data.h"
#include "xml.h"
#include "dict.h"
Include dependency graph for libyang.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

union  ly_set_set
 set array of ly_set It is kept in union to keep ly_set generic for data as well as schema trees More...
 
struct  ly_set
 Structure to hold a set of (not necessary somehow connected) lyd_node or lys_node objects. Caller is supposed to not mix the type of objects added to the set and according to its knowledge about the set content, it is supposed to access the set via the sset, dset or set members of the structure. More...
 
struct  ly_err_item
 Libyang full error structure. More...
 

Macros

#define LY_ENABLED_CACHE
 Whether to enable schema and data cache. More...
 
#define LY_ENABLED_LATEST_REVISIONS
 Whether to allow reusing latest revisions of schemas. More...
 
#define LY_ENABLED_LYD_PRIV
 Whether to add priv pointer to struct lyd_node. More...
 
#define _PACKED   __attribute__((__packed__))
 Compiler flag for packed data types. More...
 
#define LY_VERSION_MAJOR   1
 
#define LY_VERSION_MINOR   4
 
#define LY_VERSION_MICRO   1
 
#define LY_VERSION   "1.4.1"
 
#define LY_CTX_ALLIMPLEMENTED   0x01
 
#define LY_CTX_TRUSTED   0x02
 
#define LY_CTX_NOYANGLIBRARY   0x04
 
#define LY_CTX_DISABLE_SEARCHDIRS   0x08
 
#define LY_CTX_DISABLE_SEARCHDIR_CWD   0x10
 
#define LY_CTX_PREFER_SEARCHDIRS   0x20
 
#define LY_MODCLB_NOT_IMPLEMENTED   0x01
 
#define LY_SET_OPT_USEASLIST   0x01
 Option for ly_set_add() to allow duplicities in the ly_set structure so the set is not used as a set, but as a list of (container for) items. More...
 
#define LYP_WITHSIBLINGS   0x01
 
#define LYP_FORMAT   0x02
 
#define LYP_KEEPEMPTYCONT   0x04
 
#define LYP_WD_MASK   0xF0
 
#define LYP_WD_EXPLICIT   0x00
 
#define LYP_WD_TRIM   0x10
 
#define LYP_WD_ALL   0x20
 
#define LYP_WD_ALL_TAG   0x40
 
#define LYP_WD_IMPL_TAG   0x80
 
#define LYP_NETCONF   0x100
 
#define LY_LOLOG   0x01
 
#define LY_LOSTORE   0x02
 
#define LY_LOSTORE_LAST   0x06
 
#define LY_LDGDICT   0x01
 
#define LY_LDGYANG   0x02
 
#define LY_LDGYIN   0x04
 
#define LY_LDGXPATH   0x08
 
#define LY_LDGDIFF   0x10
 
#define LY_LDGAPI   0x20
 
#define LY_LDGHASH   0x40
 
#define ly_errno   (*ly_errno_glob_address())
 libyang specific (thread-safe) errno (see LY_ERR for the list of possible values and their meaning). More...
 

Typedefs

typedef const 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...
 
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...
 

Enumerations

enum  LY_LOG_LEVEL { LY_LLERR = 0, LY_LLWRN = 1, LY_LLVRB = 2, LY_LLDBG = 3 }
 Verbosity levels of the libyang logger. More...
 
enum  LY_ERR {
  LY_SUCCESS = 0, LY_EMEM, LY_ESYS, LY_EINVAL,
  LY_EINT, LY_EVALID, LY_EPLUGIN
}
 libyang's error codes available via ly_errno extern variable. More...
 
enum  LY_VECODE {
  LYVE_SUCCESS = 0, LYVE_XML_MISS, LYVE_XML_INVAL, LYVE_XML_INCHAR,
  LYVE_EOF, LYVE_INSTMT, LYVE_INPAR, LYVE_INID,
  LYVE_INDATE, LYVE_INARG, LYVE_MISSSTMT, LYVE_MISSARG,
  LYVE_TOOMANY, LYVE_DUPID, LYVE_DUPLEAFLIST, LYVE_DUPLIST,
  LYVE_NOUNIQ, LYVE_ENUM_INVAL, LYVE_ENUM_INNAME, LYVE_ENUM_WS,
  LYVE_BITS_INVAL, LYVE_BITS_INNAME, LYVE_INMOD, LYVE_KEY_NLEAF,
  LYVE_KEY_TYPE, LYVE_KEY_CONFIG, LYVE_KEY_MISS, LYVE_KEY_DUP,
  LYVE_INREGEX, LYVE_INRESOLV, LYVE_INSTATUS, LYVE_CIRC_LEAFREFS,
  LYVE_CIRC_FEATURES, LYVE_CIRC_IMPORTS, LYVE_CIRC_INCLUDES, LYVE_INVER,
  LYVE_SUBMODULE, LYVE_OBSDATA, LYVE_NORESOLV, LYVE_INELEM,
  LYVE_MISSELEM, LYVE_INVAL, LYVE_INMETA, LYVE_INATTR,
  LYVE_MISSATTR, LYVE_NOCONSTR, LYVE_INCHAR, LYVE_INPRED,
  LYVE_MCASEDATA, LYVE_NOMUST, LYVE_NOWHEN, LYVE_INORDER,
  LYVE_INWHEN, LYVE_NOMIN, LYVE_NOMAX, LYVE_NOREQINS,
  LYVE_NOLEAFREF, LYVE_NOMANDCHOICE, LYVE_XPATH_INTOK, LYVE_XPATH_EOF,
  LYVE_XPATH_INOP, LYVE_XPATH_INCTX, LYVE_XPATH_INMOD, LYVE_XPATH_INFUNC,
  LYVE_XPATH_INARGCOUNT, LYVE_XPATH_INARGTYPE, LYVE_XPATH_DUMMY, LYVE_XPATH_NOEND,
  LYVE_PATH_INCHAR, LYVE_PATH_INMOD, LYVE_PATH_MISSMOD, LYVE_PATH_INNODE,
  LYVE_PATH_INKEY, LYVE_PATH_MISSKEY, LYVE_PATH_INIDENTREF, LYVE_PATH_EXISTS,
  LYVE_PATH_MISSPAR, LYVE_PATH_PREDTOOMANY
}
 libyang's codes of validation error. Whenever ly_errno is set to LY_EVALID, the ly_vecode is also set to the appropriate LY_VECODE value. 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...
 
struct ly_setly_set_new (void)
 Create and initiate new ly_set structure. More...
 
struct ly_setly_set_dup (const struct ly_set *set)
 Duplicate the existing set. More...
 
int ly_set_add (struct ly_set *set, void *node, int options)
 Add a lyd_node or lys_node object into the set. More...
 
int ly_set_merge (struct ly_set *trg, struct ly_set *src, int options)
 Add all objects from src to trg. More...
 
int ly_set_contains (const struct ly_set *set, void *node)
 Get know if the set contains the specified object. More...
 
int ly_set_clean (struct ly_set *set)
 Remove all objects from the set, but keep the set container for further use. More...
 
int ly_set_rm (struct ly_set *set, void *node)
 Remove a lyd_node or lys_node object from the set. More...
 
int ly_set_rm_index (struct ly_set *set, unsigned int index)
 Remove a lyd_node or lys_node object from the set index. More...
 
void ly_set_free (struct ly_set *set)
 Free the ly_set data. Frees only the set structure content, not the referred data. More...
 
LY_LOG_LEVEL ly_verb (LY_LOG_LEVEL level)
 Set logger verbosity level. More...
 
int ly_log_options (int opts)
 Set additional logger options. Default is LY_LOLOG | LY_LOSTORE_LAST. More...
 
void ly_verb_dbg (int dbg_groups)
 Enable specific debugging messages (independent of log level). More...
 
void ly_set_log_clb (void(*clb)(LY_LOG_LEVEL level, const char *msg, const char *path), int path)
 Set logger callback. More...
 
LY_VECODE ly_vecode (const struct ly_ctx *ctx)
 Get the last (thread, context-specific) validation error code. More...
 
const char * ly_errmsg (const struct ly_ctx *ctx)
 Get the last (thread, context-specific) error message. If the corresponding module defined a specific error message, it will be used instead the default one. More...
 
const char * ly_errpath (const struct ly_ctx *ctx)
 Get the last (thread, context-specific) path of the element where was an error. More...
 
const char * ly_errapptag (const struct ly_ctx *ctx)
 Get the last (thread, context-specific) error-app-tag if there was a specific one defined in the module for the last error. More...
 
struct ly_err_itemly_err_first (const struct ly_ctx *ctx)
 Get the first (thread, context-specific) generated error structure. More...
 
void ly_err_print (struct ly_err_item *eitem)
 Print the error structure as if just generated. More...
 
void ly_err_clean (struct ly_ctx *ctx, struct ly_err_item *eitem)
 Free error structures from a context. More...
 

Variables

void(*)(LY_LOG_LEVEL, const char *, const char *) ly_get_log_clb (void)
 Get logger callback. More...
 

Detailed Description

The main libyang public header.

Author
Radek Krejci rkrej.nosp@m.ci@c.nosp@m.esnet.nosp@m..cz Copyright (c) 2015 - 2018 CESNET, z.s.p.o.

This source code is licensed under BSD 3-Clause License (the "License"). You may not use this file except in compliance with the License. You may obtain a copy of the License at

https://opensource.org/licenses/BSD-3-Clause

Definition in file libyang.h.

Macro Definition Documentation

◆ LY_ENABLED_CACHE

#define LY_ENABLED_CACHE

Whether to enable schema and data cache.

Definition at line 23 of file libyang.h.

◆ LY_ENABLED_LATEST_REVISIONS

#define LY_ENABLED_LATEST_REVISIONS

Whether to allow reusing latest revisions of schemas.

Definition at line 28 of file libyang.h.

◆ LY_ENABLED_LYD_PRIV

#define LY_ENABLED_LYD_PRIV

Whether to add priv pointer to struct lyd_node.

Definition at line 33 of file libyang.h.

◆ _PACKED

#define _PACKED   __attribute__((__packed__))

Compiler flag for packed data types.

Definition at line 38 of file libyang.h.

◆ LY_VERSION_MAJOR

#define LY_VERSION_MAJOR   1

libyang major version number

Definition at line 49 of file libyang.h.

◆ LY_VERSION_MINOR

#define LY_VERSION_MINOR   4

libyang minor version number

Definition at line 50 of file libyang.h.

◆ LY_VERSION_MICRO

#define LY_VERSION_MICRO   1

libyang micro version number

Definition at line 51 of file libyang.h.

◆ LY_VERSION

#define LY_VERSION   "1.4.1"

libyang version string

Definition at line 52 of file libyang.h.