libyang  0.16.105
YANG data modeling language library
libyang.h
Go to the documentation of this file.
1 
15 #ifndef LY_LIBYANG_H_
16 #define LY_LIBYANG_H_
17 
18 #include <stdio.h>
19 
23 #define LY_ENABLED_CACHE
24 
28 #define LY_ENABLED_LATEST_REVISIONS
29 
33 #define LY_ENABLED_LYD_PRIV
34 
38 #define _PACKED __attribute__((__packed__))
39 
40 #include "tree_schema.h"
41 #include "tree_data.h"
42 #include "xml.h"
43 #include "dict.h"
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 #define LY_VERSION_MAJOR 0
50 #define LY_VERSION_MINOR 16
51 #define LY_VERSION_MICRO 105
1114 struct ly_ctx;
1115 
1124 #define LY_CTX_ALLIMPLEMENTED 0x01
1125 #define LY_CTX_TRUSTED 0x02
1128 #define LY_CTX_NOYANGLIBRARY 0x04
1134 #define LY_CTX_DISABLE_SEARCHDIRS 0x08
1138 #define LY_CTX_DISABLE_SEARCHDIR_CWD 0x10
1141 #define LY_CTX_PREFER_SEARCHDIRS 0x20
1165 struct ly_ctx *ly_ctx_new(const char *search_dir, int options);
1166 
1193 struct ly_ctx *ly_ctx_new_ylpath(const char *search_dir, const char *path, LYD_FORMAT format, int options);
1194 
1221 struct ly_ctx *ly_ctx_new_ylmem(const char *search_dir, const char *data, LYD_FORMAT format, int options);
1222 
1228 unsigned int ly_ctx_internal_modules_count(struct ly_ctx *ctx);
1229 
1240 int ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir);
1241 
1249 void ly_ctx_unset_searchdirs(struct ly_ctx *ctx, int index);
1250 
1257 const char * const *ly_ctx_get_searchdirs(const struct ly_ctx *ctx);
1258 
1265 int ly_ctx_get_options(struct ly_ctx *ctx);
1266 
1277 void ly_ctx_set_disable_searchdirs(struct ly_ctx *ctx);
1278 
1284 void ly_ctx_unset_disable_searchdirs(struct ly_ctx *ctx);
1285 
1295 void ly_ctx_set_disable_searchdir_cwd(struct ly_ctx *ctx);
1296 
1302 void ly_ctx_unset_disable_searchdir_cwd(struct ly_ctx *ctx);
1303 
1312 void ly_ctx_set_prefer_searchdirs(struct ly_ctx *ctx);
1313 
1319 void ly_ctx_unset_prefer_searchdirs(struct ly_ctx *ctx);
1320 
1334 void ly_ctx_set_allimplemented(struct ly_ctx *ctx);
1335 
1341 void ly_ctx_unset_allimplemented(struct ly_ctx *ctx);
1342 
1355 void ly_ctx_set_trusted(struct ly_ctx *ctx);
1356 
1362 void ly_ctx_unset_trusted(struct ly_ctx *ctx);
1363 
1371 uint16_t ly_ctx_get_module_set_id(const struct ly_ctx *ctx);
1372 
1380 struct lyd_node *ly_ctx_info(struct ly_ctx *ctx);
1381 
1389 const struct lys_module *ly_ctx_get_module_iter(const struct ly_ctx *ctx, uint32_t *idx);
1390 
1398 const struct lys_module *ly_ctx_get_disabled_module_iter(const struct ly_ctx *ctx, uint32_t *idx);
1399 
1412 const struct lys_module *ly_ctx_get_module(const struct ly_ctx *ctx, const char *name, const char *revision, int implemented);
1413 
1431 const struct lys_module *ly_ctx_get_module_older(const struct ly_ctx *ctx, const struct lys_module *module);
1432 
1447 const struct lys_module *ly_ctx_load_module(struct ly_ctx *ctx, const char *name, const char *revision);
1448 
1465 typedef const char *(*ly_module_imp_clb)(const char *mod_name, const char *mod_rev, const char *submod_name, const char *sub_rev,
1466  void *user_data, LYS_INFORMAT *format, void (**free_module_data)(void *model_data, void *user_data));
1467 
1477 void ly_ctx_set_module_imp_clb(struct ly_ctx *ctx, ly_module_imp_clb clb, void *user_data);
1478 
1486 ly_module_imp_clb ly_ctx_get_module_imp_clb(const struct ly_ctx *ctx, void **user_data);
1487 
1500 typedef const struct lys_module *(*ly_module_data_clb)(struct ly_ctx *ctx, const char *name, const char *ns,
1501  int options, void *user_data);
1502 
1503 /* Module is in the context, but is not implemented, so to continue with the data operation, it must be implemented. */
1504 #define LY_MODCLB_NOT_IMPLEMENTED 0x01
1505 
1514 void ly_ctx_set_module_data_clb(struct ly_ctx *ctx, ly_module_data_clb clb, void *user_data);
1515 
1523 ly_module_data_clb ly_ctx_get_module_data_clb(const struct ly_ctx *ctx, void **user_data);
1524 
1525 #ifdef LY_ENABLED_LYD_PRIV
1526 
1527 void ly_ctx_set_priv_dup_clb(struct ly_ctx *ctx, void *(*priv_dup_clb)(const void *priv));
1528 
1529 #endif
1530 
1543 const struct lys_module *ly_ctx_get_module_by_ns(const struct ly_ctx *ctx, const char *ns, const char *revision, int implemented);
1544 
1559 const struct lys_submodule *ly_ctx_get_submodule(const struct ly_ctx *ctx, const char *module, const char *revision,
1560  const char *submodule, const char *sub_revision);
1561 
1572 const struct lys_submodule *ly_ctx_get_submodule2(const struct lys_module *main_module, const char *submodule);
1573 
1589 const struct lys_node *ly_ctx_get_node(struct ly_ctx *ctx, const struct lys_node *start, const char *data_path, int output);
1590 
1602 struct ly_set *ly_ctx_find_path(struct ly_ctx *ctx, const char *path);
1603 
1617 int ly_ctx_remove_module(const struct lys_module *module,
1618  void (*private_destructor)(const struct lys_node *node, void *priv));
1619 
1628 void ly_ctx_clean(struct ly_ctx *ctx, void (*private_destructor)(const struct lys_node *node, void *priv));
1629 
1646 void ly_ctx_destroy(struct ly_ctx *ctx, void (*private_destructor)(const struct lys_node *node, void *priv));
1647 
1657 char *ly_path_xml2json(struct ly_ctx *ctx, const char *xml_path, struct lyxml_elem *xml);
1658 
1670 char *ly_path_data2schema(struct ly_ctx *ctx, const char *data_path);
1671 
1687 union ly_set_set {
1688  struct lys_node **s;
1689  struct lyd_node **d;
1690  void **g;
1691 };
1692 
1704 struct ly_set {
1705  unsigned int size;
1706  unsigned int number;
1707  union ly_set_set set;
1708 };
1709 
1714 #define LY_SET_OPT_USEASLIST 0x01
1715 
1721 struct ly_set *ly_set_new(void);
1722 
1729 struct ly_set *ly_set_dup(const struct ly_set *set);
1730 
1744 int ly_set_add(struct ly_set *set, void *node, int options);
1745 
1758 int ly_set_merge(struct ly_set *trg, struct ly_set *src, int options);
1759 
1766 int ly_set_contains(const struct ly_set *set, void *node);
1767 
1774 int ly_set_clean(struct ly_set *set);
1775 
1786 int ly_set_rm(struct ly_set *set, void *node);
1787 
1798 int ly_set_rm_index(struct ly_set *set, unsigned int index);
1799 
1805 void ly_set_free(struct ly_set *set);
1806 
1817 #define LYP_WITHSIBLINGS 0x01
1818 #define LYP_FORMAT 0x02
1819 #define LYP_KEEPEMPTYCONT 0x04
1820 #define LYP_WD_MASK 0xF0
1821 #define LYP_WD_EXPLICIT 0x00
1823 #define LYP_WD_TRIM 0x10
1824 #define LYP_WD_ALL 0x20
1825 #define LYP_WD_ALL_TAG 0x40
1830 #define LYP_WD_IMPL_TAG 0x80
1834 #define LYP_NETCONF 0x100
1856 typedef enum {
1857  LY_LLERR = 0,
1858  LY_LLWRN = 1,
1859  LY_LLVRB = 2,
1860  LY_LLDBG = 3
1862 } LY_LOG_LEVEL;
1863 
1870 
1879 #define LY_LOLOG 0x01
1881 #define LY_LOSTORE 0x02
1883 #define LY_LOSTORE_LAST 0x06
1896 int ly_log_options(int opts);
1897 
1898 #ifndef NDEBUG
1899 
1909 #define LY_LDGDICT 0x01
1910 #define LY_LDGYANG 0x02
1911 #define LY_LDGYIN 0x04
1912 #define LY_LDGXPATH 0x08
1913 #define LY_LDGDIFF 0x10
1923 void ly_verb_dbg(int dbg_groups);
1924 
1925 #endif
1926 
1941 void ly_set_log_clb(void (*clb)(LY_LOG_LEVEL level, const char *msg, const char *path), int path);
1942 
1947 void (*ly_get_log_clb(void))(LY_LOG_LEVEL, const char *, const char *);
1948 
1954 typedef enum {
1955  LY_SUCCESS = 0,
1956  LY_EMEM,
1957  LY_ESYS,
1958  LY_EINVAL,
1959  LY_EINT,
1960  LY_EVALID,
1961  LY_EPLUGIN
1962 } LY_ERR;
1963 
1970 typedef enum {
1971  LYVE_SUCCESS = 0,
1973  LYVE_XML_MISS,
1975  LYVE_XML_INCHAR,
1977  LYVE_EOF,
1978  LYVE_INSTMT,
1979  /* */
1980  LYVE_INPAR,
1985  /* */
1990  LYVE_DUPLIST,
1991  LYVE_NOUNIQ,
1992  LYVE_ENUM_INVAL,
1994  /* */
1995  /* */
1996  LYVE_ENUM_WS,
1999  /* */
2000  /* */
2002  /* */
2003  LYVE_KEY_NLEAF,
2006  LYVE_KEY_MISS,
2019  /* */
2021  LYVE_INELEM,
2022  /* */
2026  LYVE_INATTR,
2027  LYVE_MISSATTR,
2029  LYVE_INCHAR,
2044  LYVE_XPATH_INOP,
2045  /* */
2070 LY_ERR *ly_errno_glob_address(void);
2076 #define ly_errno (*ly_errno_glob_address())
2086 LY_VECODE ly_vecode(const struct ly_ctx *ctx);
2098 const char *ly_errmsg(const struct ly_ctx *ctx);
2099 
2113 const char *ly_errpath(const struct ly_ctx *ctx);
2114 
2125 const char *ly_errapptag(const struct ly_ctx *ctx);
2126 
2130 struct ly_err_item {
2132  LY_ERR no;
2133  LY_VECODE vecode;
2134  char *msg;
2135  char *path;
2136  char *apptag;
2137  struct ly_err_item *next;
2138  struct ly_err_item *prev; /* first item's prev points to the last item */
2139 };
2140 
2147 struct ly_err_item *ly_err_first(const struct ly_ctx *ctx);
2148 
2154 void ly_err_print(struct ly_err_item *eitem);
2155 
2164 void ly_err_clean(struct ly_ctx *ctx, struct ly_err_item *eitem);
2170 #ifdef __cplusplus
2171 }
2172 #endif
2173 
2174 #endif /* LY_LIBYANG_H_ */
Common structure representing single YANG data statement describing.
Definition: tree_schema.h:1229
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.
int ly_set_merge(struct ly_set *trg, struct ly_set *src, int options)
Add all objects from src to trg.
uint8_t implemented
Definition: tree_schema.h:693
void ly_ctx_unset_trusted(struct ly_ctx *ctx)
Reverse function to ly_ctx_set_trusted().
const char *const * ly_ctx_get_searchdirs(const struct ly_ctx *ctx)
Get the NULL-terminated list of the search paths in libyang context.
Submodule schema node structure that can be included into a YANG module.
Definition: tree_schema.h:737
LY_VECODE
libyang's codes of validation error. Whenever ly_errno is set to LY_EVALID, the ly_vecode is also set...
Definition: libyang.h:1997
LY_ERR
libyang's error codes available via ly_errno extern variable.
Definition: libyang.h:1981
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.
struct lys_node ** s
Definition: libyang.h:1700
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 ...
int ly_set_rm_index(struct ly_set *set, unsigned int index)
Remove a lyd_node or lys_node object from the set index.
union ly_set_set set
Definition: libyang.h:1719
libyang dictionary
void ly_set_free(struct ly_set *set)
Free the ly_set data. Frees only the set structure content, not the referred data.
libyang representation of data model trees.
LY_LOG_LEVEL ly_verb(LY_LOG_LEVEL level)
Set logger verbosity level.
LY_VECODE vecode
Definition: libyang.h:2160
int ly_ctx_set_searchdir(struct ly_ctx *ctx, const char *search_dir)
Add the search path into libyang 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.
const char * ly_errpath(const struct ly_ctx *ctx)
Get the last (thread, context-specific) path of the element where was an error.
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.
void(*)(LY_LOG_LEVEL, const char *, const char *) ly_get_log_clb(void)
Get logger callback.
Definition: libyang.h:1974
struct ly_err_item * prev
Definition: libyang.h:2165
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.
void ** g
Definition: libyang.h:1702
void ly_ctx_unset_prefer_searchdirs(struct ly_ctx *ctx)
Reverse function to ly_ctx_set_prefer_searchdirs().
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_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.
libyang representation of data trees.
LY_LOG_LEVEL level
Definition: libyang.h:2158
unsigned int number
Definition: libyang.h:1718
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.
Definition: libyang.h:1512
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.
int ly_ctx_get_options(struct ly_ctx *ctx)
Get the currently set context's options.
LYD_FORMAT
Data input/output formats supported by libyang parser and printer functions.
Definition: tree_data.h:40
char * apptag
Definition: libyang.h:2163
char * path
Definition: libyang.h:2162
struct ly_set * ly_set_dup(const struct ly_set *set)
Duplicate the existing set.
Structure to hold a set of (not necessary somehow connected) lyd_node or lys_node objects....
Definition: libyang.h:1716
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.
int ly_set_rm(struct ly_set *set, void *node)
Remove a lyd_node or lys_node object from the set.
Libyang full error structure.
Definition: libyang.h:2157
void ly_ctx_unset_allimplemented(struct ly_ctx *ctx)
Reverse function to ly_ctx_set_allimplemented().
struct ly_err_item * ly_err_first(const struct ly_ctx *ctx)
Get the first (thread, context-specific) generated error structure.
LY_ERR no
Definition: libyang.h:2159
Public API of libyang XML parser.
void ly_ctx_unset_disable_searchdir_cwd(struct ly_ctx *ctx)
Reverse function to ly_ctx_set_disable_searchdir_cwd().
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 modu...
Structure describing an element in an XML tree.
Definition: xml.h:91
void ly_err_print(struct ly_err_item *eitem)
Print the error structure as if just generated.
LYS_INFORMAT
Schema input formats accepted by libyang parser functions.
Definition: tree_schema.h:195
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...
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_loa...
int ly_set_clean(struct ly_set *set)
Remove all objects from the set, but keep the set container for further use.
const char * ns
Definition: tree_schema.h:727
void ly_set_log_clb(void(*clb)(LY_LOG_LEVEL level, const char *msg, const char *path), int path)
Set logger callback.
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.
struct ly_err_item * next
Definition: libyang.h:2164
Main schema node structure representing YANG module.
Definition: tree_schema.h:674
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 vali...
int ly_set_contains(const struct ly_set *set, void *node)
Get know if the set contains the specified object.
void ly_ctx_set_priv_dup_clb(struct ly_ctx *ctx, void *(*priv_dup_clb)(const void *priv))
LY_LOG_LEVEL
Verbosity levels of the libyang logger.
Definition: libyang.h:1880
const struct lys_node * ly_ctx_get_node(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).
char * msg
Definition: libyang.h:2161
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.
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.
void ly_ctx_unset_searchdirs(struct ly_ctx *ctx, int index)
Clean the search path(s) from the libyang context.
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) t...
void ly_err_clean(struct ly_ctx *ctx, struct ly_err_item *eitem)
Free error structures from a context.
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.
Definition: libyang.h:1477
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.
Generic structure for a data node, directly applicable to the data nodes defined as LYS_CONTAINER,...
Definition: tree_data.h:186
struct lyd_node ** d
Definition: libyang.h:1701
int ly_set_add(struct ly_set *set, void *node, int options)
Add a lyd_node or lys_node object into the set.
const char * name
Definition: tree_schema.h:676
ly_module_data_clb ly_ctx_get_module_data_clb(const struct ly_ctx *ctx, void **user_data)
Get the missing data module calback.
LY_VECODE ly_vecode(const struct ly_ctx *ctx)
Get the last (thread, context-specific) validation error code.
struct ly_set * ly_set_new(void)
Create and initiate new ly_set structure.
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...
const char * ly_errmsg(const struct ly_ctx *ctx)
Get the last (thread, context-specific) error message. If the corresponding module defined a specific...
char * ly_path_data2schema(struct ly_ctx *ctx, const char *data_path)
Transform a data path into schema path (see XPath Addressing).
struct ly_ctx * ctx
Definition: tree_schema.h:675
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...
unsigned int size
Definition: libyang.h:1717
const struct lys_submodule * ly_ctx_get_submodule2(const struct lys_module *main_module, const char *submodule)
Get submodule of a main module.
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())...
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_modu...
set array of ly_set It is kept in union to keep ly_set generic for data as well as schema trees
Definition: libyang.h:1699
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...
libyang context handler.
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() resu...
struct lyd_node * ly_ctx_info(struct ly_ctx *ctx)
Get data of an internal ietf-yang-library module.
void ly_ctx_unset_disable_searchdirs(struct ly_ctx *ctx)
Reverse function to ly_ctx_set_disable_searchdirs().